Bona:Fide:Cynic

Installation of Haskell Platform on linux.

It is not difficult to install haskell platform using packaging system i.e on ubuntu ‘apt-get’ or ‘rpm’ on fedora but those are so hopelessly out of date. That is why I decided to install them from source, the other reason is that until it breaks you’ll never learn how to fix it. I am running ubuntu 10.10 and latest haskell on it, is platform 2010.1.0.0.1 with ghc 6.12

So if compiling this from source kills your dog or burns your house I am not responsible.

Let’s go to haskell website, right in the middle of the page there is a button “download haskell” let’s go there, it opens another page were I chose linux install. Clicked on ubuntu link that takes me to the ubuntu page, I don’t need that so it’s “build from source download” haskell-platform-2011.2.0.1.tar.gz It says on this page that ghc 7.0.3 needs to be installed before installation of the platform let’s go to that page. Right, one for me is Linux(x86_64) [download link] if you have 32bit os chose the other one. Quite a big download 104 Mb so it’ll take some time. You can download them using curl or wget:

$ wget -c http://lambda.galois.com/hp-tmp/2011.2.0.1/haskell-platform-2011.2.0.1.tar.gz
$ wget -c http://haskell.org/ghc/dist/7.0.3/ghc-7.0.3-x86_64-unknown-linux.tar.bz2

Now just extract them:

$ tar xjfv ghc-7.0.3-x86_64-unknown-linux.tar.bz2
$ tar xzvf 2011.2.0.1/haskell-platform-2011.2.0.1.tar.gz

You can choose to go with default install path is /usr/local but I will just install it in /opt/haskell/2011.2.0.1 so that when there will be a new release it’s install will not interfere with the old one. And also I don’t need to switch to sudo to install or remove something.

$ sudo mkdir -p /opt/haskell/2011.2.0.1
$ sudo chown -R 1000:1000 /opt/haskell

Change group and user to your one, to check just type ‘id’ in the terminal though first user on ubuntu gid 1000 uid 1000. Changing permissions will allow you to install without using sudo. Install dependencies, I found these are needed on my system.

$ sudo apt-get install libedit2 libedit-dev freeglut3-dev libglu1-mesa-dev libgmp3-dev 
$ cd ghc-7.0.3/
$ ./configure --prefix=/opt/haskell/2011.2.0.1
$ make install

This took a long time on my system. Edit your .bashrc and append to the end of it new path:

$ echo 'PATH=/opt/haskell/2011.2.0.1/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc

If you installing in default location you wouldn’t need this. Don’t forget sudo for ‘make install’ though. Now installation of ghc finished succesfully I hope and we continue to install platform:

$ cd ../haskell-platform-2011.2.0.1/
$ ./configure --prefix=/opt/haskell/2011.2.0.1
$ make
$ make install
$ cabal update

That’s it, platform installed and you can start using your new haskell. About that last command, it updates index of packages in ‘hackageDB’ (repository of pakages for haskell) for something called cabal.

Ok, let’s do “Hello, World!”.

$ vi hello.hs

Type this:

main = putStrLn "Hello, World"

Now let’s compile:

$ ghc --make  hello.hs
$ Linking hello ...
$ ls -lh
$ -rwxr-xr-x 1 anatoli anatoli 951K 2011-04-19 11:48 hello
$ -rw-r--r-- 1 anatoli anatoli  488 2011-04-18 09:51 hello.hi
$ -rw-r--r-- 1 anatoli anatoli   32 2011-04-17 13:13 hello.hs
$ -rw-r--r-- 1 anatoli anatoli 3.7K 2011-04-18 09:51 hello.o
$ strip --strip-unneded hello
$ ls -lh hello
$ -rwxr-xr-x 1 anatoli anatoli 637K 2011-04-19 11:51 hello

What about “Hello, World!” in C.
Let’s see:

$ vi hello.c
#include <stdio.h>

main()
{
    printf("Hello, World!\n");
}
$ gcc -o hello hello.c
$ ls -lh
$ -rwxr-xr-x 1 anatoli anatoli 8.2K 2011-04-19 12:02 hello

It compiles executables which is good they are bigger obviously then C executables but who cares any more about disk space.
You can also use ‘ghci’ which is very good REPL for trying your code interactively, to run it without compiling it first, you can use ‘runghc’ scriptname.hs to run your scripts.

This is my first encounter with haskell.

blog comments powered by Disqus