Pages

Wednesday, 21 September 2011

We can install Haskell Compiler like GHC and Haskell Platform using synaptic package manager in Ubuntu. But to get the latest version, we might have to install it manually.

1. Download the Glasgow Haskell Compiler binary.
2. Decompress the downloaded file and go into the ghc directory.
3. Now you need to configure the ghc binary. You can give the path of installation using the prefix flag.

./configure --prefix=/usr/local/ghc/7.0.3

Here I have downloaded v7.0.3. Since I wanted to keep different version of the compiler, I keep folders with version number under the ghc folder. Accordingly, you give the path to the configure script.
4. Install. It is already compiled, because you downloaded the binary.

sudo make install

5. Now you need to add the ghc directory to your path so that your bash shell can find it. There are numerous ways to do it. Create a file say "ghc-7.0.3.sh" in "/etc/profile.d"

Log out and log in. Open your terminal (Ctrl + Alt + T) and type "ghc --version" to ensure ghc is available.
6. Now you have a working Haskell Compiler. It is highly recommended to install Haskell-Platform which are a set of libraries for Haskell. For that you go to Haskell-Platform page and download the tar.gz file under the "Build from source" section. Decompress the downloaded file.
7. There are dependency files that you need to have installed before proceeding to compile the Haskell-Platform. So, let us install aptitude, which is a ncurses front-end to APT. Then we shall install 'happy', 'alex' and 'darcs' using 'aptitude' which are haskell libraries.

sudo apt-get install aptitude
sudo aptitude install happy alex darcs

Now we need to install C dependencies. To find that we will use a script. In general, the C dependencies are 'libedit-dev', 'libbsd-dev', 'libgmp3-dev', 'zlib1g-dev', 'freeglut3-dev'. You will need to run the below script to find out.
Let us call the below script 'depcheck'. Put it in 'bin' folder under your home directory. The 'bin' folder is added to you bash path. So bash can find all the scripts inside that folder.

Now go to the haskell-platform directory which you decompressed in step 6 and run depcheck. (Just type depcheck and press enter).
It will print out a lot of library names. You need to install all the ones which ends with a '-dev'. So the libraries shown to me are 'libedit-dev', 'libbsd-dev', 'libgmp3-dev', 'zlib1g-dev', 'freeglut3-dev' and 'libglu1-mesa-dev'. (Just in case, if your installation aborted saying that it is missing some library, then you can install them and continue the installation).

8. Now that you have got all your dependencies installed, you can proceed with the Haskell-Platform. (You are now in the haskell-platform directory).

./configure --prefix=/usr/local/haskell-platform/2011.2.0.1
make
sudo make install

It will take a while to complete.
9. After the successful installation of Haskell-Platform, you need to add the directory to your path. Like in step 5, you create a file say 'haskell-platform-2011.2.0.1.sh' in '/etc/profile.d/' folder.