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 we need to configure the ghc
binary. We 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, we can give the path to the configure script.
4. Install. It is already compiled, because we downloaded the binary.
sudo make install
5. Now we need to add the ghc
directory to the path so that the 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`.
sudo vim /etc/profile.d/ghc-7.0.3.sh
# Add the below contents to the file, save and quit.
# ghc-7.0.3 path
PATH=${PATH}:/usr/local/ghc/7.0.3/bin
Log out and log in. Open your terminal (Ctrl
+ Alt
+ T
) and type ghc --version
to ensure ghc
is available.
6. Now we have a working Haskell Compiler. It is highly recommended to install Haskell-Platform
which are a set of libraries for Haskell. For that we can 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 we 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
. We 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 should be added to the path so that bash can find all the scripts inside that folder.
#!/bin/bash
# check dependency of a package. The libs with -dev need to be installed
# before building
strace -f -o /tmp/log ./configure
# or make instead of ./configure, if the package doesn't use autoconf
for x in `dpkg -S $(grep open /tmp/log|\
perl -pe 's!.* open\(\"([^\"]*).*!$1!' |\
grep "^/"| sort | uniq|\
grep -v "^\(/tmp\|/dev\|/proc\)" ) 2>/dev/null|\
cut -f1 -d":"| sort | uniq`; \
do \
echo -n "$x (>=" `dpkg -s $x|grep ^Version|cut -f2 -d":"` "), "; \
done
Set executable permission for the depcheck
script.
chmod +x depcheck
Now go to the haskell-platform
directory which we decompressed in step 6 and run depcheck
.
It will print out a lot of library names. We 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 the installation aborted saying that it is missing some library, then we can install them and continue the installation).
sudo apt-get install libedit-dev libbsd-dev libgmp3-dev zlib1g-dev freeglut3-dev libglu1-mesa-dev
8. Now that we have got all your dependencies installed, you can proceed with the Haskell-Platform
. From this folder run:
./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
, we need to add the directory to your path. Like in step 5, we will create a file say haskell-platform-2011.2.0.1.sh
in '/etc/profile.d/' folder.
sudo vim /etc/profile.d/haskell-platform-2011.2.0.1.sh
# Add the following contents to the file, save and quit.
# Haskell-Platform 2011.2.0.1
PATH=${PATH}:/usr/local/haskell-platform/2011.2.0.1/bin
Log out and log in.
10. All done! Now do a cabal update
to get the latest list of all the packages in hackage
, which will take a while. Now we can install libraries (eg: hscurses
) using cabal
.
cabal update
cabal install hscurses # ncurses binding for haskell