Tero Karvinen - Articles - Downloads - Courses - Contact

Table of Contents

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.

Last modified: 2008-05-08. Permanent url: http://www.iki.fi/karvinen/programming_languages_on_linux.html

Tero Karvinen www.iki.fi/karvinen - Top - Validate HTML - Validate CSS