Spork Code

Code. Randomness. Sporks.

Haskell Cabal in Ubuntu

with 8 comments

EDIT: You may prefer to install the entire haskell platform in one go, which includes cabal. Detailed instructions can be found here.

Recently I’ve begun to learn Haskell, the lazy functional language. Haskell is backed by a large library of packages, called Hackage. On Hackage, libraries and programs in a wide variety of genres are available for download. In order to simplify the download and install process for these packages a tool was born to allow command line grab/install maneuver. Think apt-get for Haskell.

The tool in question is called cabal, and it’s quite useful during Haskell development. Unfortunately, I’ve run into some issues while using it, mainly to do with resolving dependencies. I’ll get to that later.

Installing Cabal
Installing cabal was not as straight-forward as I had hoped. I first went to the offical cabal download page, to see what my options were. The only option on that page was to download a tarball and install it by hand. Of course, having been pampered by the power of apt-get, I figured there had to be a better way. Unfortunately, it seems as there is not. No cabal package exists in the Ubuntu repositories. I downloaded the tarball and prepared to install. The install from the tarball was painless as manual installs go, but unfortunately I had to resolve multiple dependencies to get the build to succeed. Here were the steps I took:

#get our dependant libraries (this assumes we already have ghc6 installed)
sudo apt-get install libghc6-network-dev libghc6-parsec-dev libghc6-mtl-dev libghc6-zlib-dev

#grab the source
wget http://haskell.org/cabal/release/cabal-install-0.6.2/cabal-install-0.6.2.tar.gz

#untar it
tar -xvvf cabal-install-0.6.2.tar.gz

#install it
sh cabal-install-0.6.2/bootstrap.sh

#link the executable into our path
sudo ln -s $HOME/.cabal/bin/cabal /usr/local/bin/cabal

Using Cabal

Cabal is not limited to simply downloading libraries. It can also allow you to easily create libraries of your own and upload them to Hackage, and also build projects (similar to make).

cabal --help will bring up your main options, which is always a good starting place. Let’s look at installing a package using cabal.

cabal install [package-name] installs the given package name. This should be very familiar to anyone who has used a package manager such as apt-get.

cabal list [string] is like apt-cache; it searches Hackage for packages pertaining to the string you entered.

Explore! Have fun! there’s plenty more features of cabal that I won’t be covering now, yet are plenty awesome.

I’ve had some strange dependency issues; for example, installing bloxorz –
cabal install bloxorz
gives me an error while trying to build a dependency that in turn depends on a C library which is not auto-resolved. Fun. Fortunately, such errors seem to be few and far between.


Written by John Gunderman

July 5, 2009 at 9:18 pm

Posted in Uncategorized

Tagged with , ,

8 Responses

Subscribe to comments with RSS.

  1. From Wikipedia:

    A cabal is a number of people united in some close design, usually to promote their private views and interests in a church, state, or other community, often by intrigue.

    HA HA, I thought this article would be about a bunch of crazed fanatics trying to make Ubuntu dependent on Haskell.

    Unlike Mono.


    BTW, sometimes package and library loaders (like CPAN) can conflict with apt and dkpg. That’s why I usually try to find what I need in the repositories first. For example, if apt doesn’t know about your latest and greatest library, it may revert you to an earlier one.

    Haskell probably won’t have that problem until language extensions and additions enter the repositories.

    Eddie Haskell

    July 6, 2009 at 1:21 pm

  2. Yeah, the cabal bootstrap script assumes that you will have the libraries which are normally packaged along with GHC, but the Debian/Ubuntu guys have split GHC up further, so you have to install those basic libraries.

    However, Ubuntu’s package of GHC is perpetually 5 to 7 months out of date, since the release schedules misalign perfectly, which is enough to mean that it’s a major version back a lot of the time. So it’s unfortunate, but I usually just install the generic Linux binary available from the GHC website. Ubuntu *still* has 6.8.2 as the latest version, and 6.8.3 came out (in fact, in time that it could have been included, so I don’t know why it wasn’t) and we’re now at 6.10.3 with 6.10.4 coming up shortly, and 6.12.1 will be released sometime in September, probably after it’s too late to make it in again. 😉

    But, at least, there is the Haskell Platform now… hopefully if the Debian and Ubuntu guys pick that up in the future, you’ll be able to install it and get cabal automatically, anyway.

    Cale Gibbard

    July 6, 2009 at 2:57 pm

  3. I want apt-get install cabal.


    July 9, 2009 at 2:26 pm

  4. […] Haskell Cabal in Ubuntu […]

  5. […] Haskell Cabal in Ubuntu […]

  6. I was actually looking for something else when I found this post but it was a good read! I’ll be bookmarking to return later.

    cheats for bloxorz

    May 1, 2010 at 5:17 pm

  7. was a great help! thx. But because ubuntu is often behind I had to install the newest version of the ghc first… however, this post was a first good hint how to install cabal! 🙂


    November 11, 2010 at 10:20 am

  8. Good post, even though I was looking information on different kind of dependency issues.

    Tip: when you want something to your path, instead of

    13 #link the executable into our path
    14 sudo ln -s $HOME/.cabal/bin/cabal /usr/local/bin/cabal

    you can just append
    export PATH=$HOME/.cabal/bin/cabal:$PATH
    to your ~/.bashrc.

    Heikki Salo

    February 22, 2011 at 4:35 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: