Programming Languages on Linux – Installing and Using on Ubuntu


Programming Languages on Linux – Installing and Using on Ubuntu

Your favourite programming language is probably available on Linux. This article explains how to compile and run “Hello world” in some languages.

All of these commands have been tested on Ubuntu 7.10 Gutsy.



Python

$ python
>>> print "Hello Tero"
Hello Tero
>>> print 2+2
4
>>> exit()

Python Hello World



Bash

$ nano hello.sh
$ chmod a+x hello.sh
$ ./hello.sh
Hello world

hello.sh:

#!/bin/bash
echo "Hello world"

See also shell scripting.



Perl

$ echo "foobar" |perl -pe 's/foo/bar/g'



C++

$ sudo apt-get install g++
$ g++ hello.cc -o hello
$ ./hello
Hello Tero!

C++ Hello World



Java

Most of Java (Iced Tea) is now Free! However, this installs some non-free stuff too.

$ sudo apt-get install sun-java6-jdk   # on Ubuntu 7.10
$ javac HelloWorld.java   # filename must match class name
$ java HelloWorld    # must not write .class here

Java Hello World



Basic

$ sudo apt-get install yabasic
$ yabasic
PRINT "HELLO TERO"
ctrl-D
HELLO TERO

For learning programming languages, I suggest you use Python instead.



Pascal

$ fpc hello.pas
... 5 Lines compiled, 0.1 sec
$ ./hello
Hello Tero!

Pascal Hello World

For learning programming languages, I suggest you use Python instead.



C#

$ sudo apt-get install mono-mcs
$ mcs Hello.cs
$ mono Hello.exe
I would not put all my eggs to M$ basket.

Isn’t the ‘#’ character called “hash“? I don’t recommend C# or mono, because those languages are actually controlled by Microsoft.

C# Hello World



Ruby

If it walks like a duck…

$ sudo apt-get install ruby-full
$ ruby
print ("Hello Ruby World!n")
ctrl-D
Hello Ruby World! 



Troubleshooting



gpc: crt1.o: No such file

$ sudo apt-get install gpc
$ gpc hello.pas  # does not work yet, some lib missing
/usr/bin/ld: crt1.o: No such file: No such file or directory
collect2: ld returned 1 exit status

Solution: Install fpc instead.



“gcc” is not a C++ Compiler

$ gcc hello.cc   # Wrong, use g++ instead
/tmp/ccuCc0ga.o: In function `__static_initialization_and_destruction_0(int, int)':
hello.cc:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccuCc0ga.o: In function `__tcf_0':
[..]
hello.cc:(.text+0x88): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccuCc0ga.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Solution: Use ‘g++’ to compile C++ source files.


Posted in Old Site | Tagged | 17 Comments

17 Responses to Programming Languages on Linux – Installing and Using on Ubuntu

  1. Pingback: Programming in linux xubuntu | Saroj Pradhan blog

  2. Pingback: Creating and executing shell scripts (C#, Java, Python & Ruby) | markus elfving exploring the world of linux

  3. Pingback: Summary | Matias Ranta

  4. Pingback: h7. Hello World neljällä eri ohjelmointikielellä | Ilkka Siiskonen

  5. Pingback: “Hello world!” neljällä kielellä | Leo Roos

  6. Pingback: TYÖASEMAT JA TIETOVERKOT ICT1TN002-43: KOTILÄKSY 7, Hello World! | HH Annika Viitanen

  7. Pingback: Hello World! | Arttu Tahvanainen

  8. Pingback: “Hello World!” neljällä eri ohjelmointikielellä | Kristina Wiik

  9. Pingback: Hello world! neljällä kielellä | Sari Nuolivirta

  10. Pingback: Translating “Hello world” in four different coding languages | Matias Ranta

  11. Pingback: H7: Hello World | anttistenman

  12. Pingback: Hello world! x4 | arytkonen

  13. Pingback: Tehtävä 7 – Hello world! | Teemu Salminen

  14. Pingback: Hello world! neljällä kielellä | Teemu Toivanen

  15. Java is now $ sudo apt-get -y install openjdk-7-jdk

  16. Pingback: Hello World! | Kim Stenberg

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Picks

  • Boxing Clock for AndroidOcton8 Diving T-ShirtsShaking Tower Panda Android GameLearn Chinese with Android
  • Student projects