Don’t panic! It’s only an upgrade

Time for another upgrade of my GHC installation. OK, I know I already posted about this twice but yet again the process was different from the previous ones.

My first attempts of installing GHC and the Haskell Platform a year ago relied on using packages from my distribution’s repository. This quickly turned out to be problematic so I decided for a direct installation of the Haskell Platform. This worked perfectly fine except for the fact that Haskell packages were installed in different subdirectories of /usr/local, which lead to a bit of a mess and problems with controlling what is installed where (this is useful if you want to remove a package). So the second time I was installing Haskell Platform I was smarter and refined the whole process. This time I confined the installation to a single directory so that both GHC and all the packages are located in a single, easy to find place.

Yesterday I figured out it would be great to get a new version of GHC. GHC 7.6.1 was released on 6th September 2012 and the updated 7.6.2 version is only two weeks old. While GHC 7.6.1 has been out for over 5 months it is still not part of the Haskell Platform and it won’t be for the next three months. That’s too long a wait for me so I decided to send the Platform to /dev/null and just install GHC and its environment from scratch.

My plan to install GHC from precompiled binaries went up the spout:

This build requires libgmp.so.3.

Watwatwat? Now what is that supposed to mean? Previously released binaries didn’t depend on one particular version of libgmp library. Of course my system has libgmp.so.10 and any attempt to install an older version results in breaking package dependencies. I downloaded binaries anyway and tried to run them:

[killy@xerxes : ~/ghc-7.6.2/ghc/stage2/build/tmp] ./ghc-stage2 --interactive
 ./ghc-stage2: error while loading shared libraries: libgmp.so.3: cannot open shared object file: No such file or directory

OK, so that requirement is true – you need the exact version of libgmp. So what now? I know! Compilation from sources! I’ve been hacking on GHC recently so I already have sources on my drive. Unfortunately it turned out that after switching GHC repo and all its subrepos to ghc-7.6 branch I get some compilation errors. I wasn’t in the mood for debugging this so I switched everything back to master and downloaded the source snapshot. From now on things are easy, assuming that you already have an older version of GHC on your system. After extracting the sources I copied $(TOP)/mk/build.mk.sample to $(TOP)/mk/build.mk ($(TOP) refers to directory containing GHC sources) and uncommented the line BuildFlavour = perf-llvm. This gives me fully optimized build using LLVM. Now the compilation:

perl boot
./configure --prefix=/usr/local/ghc-7.6.2
make

This will build GHC and prepare it for installation in /usr/local/ghc-7.6.2. Fully optimized build takes much over an hour on all 4 cores. After the build is done all one needs to do is run make install as root. At this stage old GHC can be removed. You of course need to add /usr/local/ghc-7.6.2/bin to PATH environmental variable. As I already have mentioned I have the habit of installing all the packages system-wide in a single directory. For that I need to edit /root/.cabal/config file by adding the following entry:

install-dirs global
    prefix:/usr/local/ghc-7.6.2

All that is left now is installing cabal-install. Grab the sources from hackage, extract them and run (as root) sh bootstrap.sh --global in the source directory. This installs cabal-install with its dependencies. Now you can start installing other packages that you need (a.k.a. compile the World).

This completes Yet Another Installation of GHC.

9 Responses to “Don’t panic! It’s only an upgrade”

  1. I just upgraded to ghc 7.6.2 today, because I didn’t want to wait for the Haskell Platform. My procedure was a bit simpler. I had a working cabal-install (compiled under GHC 7.4.2), and I was able to use it to install (and replace) itself. I didn’t have to build it from source.

    1. Install GHC.
    2. Change my path to point to the new GHC directory.
    3. Nuke my ~/.cabal folder.
    4. cabal update
    5. cabal install cabal-install

  2. In the past, I’ve always installed the Haskell Platform along with GHC, but this time I got tired of waiting for the new HP. I was worried that I’d be missing out on a lot of stuff in the platform, but really, cabal is the only thing that I had to give special consideration to. If I didn’t have a working version of cabal-install, I would have had to install it from source. But as I said in my previous comment, using a version of cabal-install built under one version of GHC to build and install itself with a new version of GHC worked just fine.

    For anyone who googles your blog post, and wants to try installing GHC (and the Haskell Platform) without using their distro’s package manager, here’s my recipe. Your mileage may vary, of course.

    GHC version: x.y.z
    Haskell platform version: a.b.c.d

    Installing GHC manually
    ———————–
    Unpack into a *temporary* directory
    sudo mkdir /usr/local/ghc-x.y.z
    ./configure –prefix=/usr/local/ghc-x.y.z
    sudo make install
    Add to PATH!

    Installing Haskell platform manually
    ————————————
    Unpack into a *temporary* directory
    sudo mkdir /usr/local/haskell-platform-a.b.c.d
    ./configure –prefix=/usr/local/haskell-platform-a.b.c.d –enable-profiling=yes –with-ghc=/usr/local/ghc-x.y.z/bin/ghc –with-ghc-pkg=/usr/local/ghc-x.y.z/bin/ghc-pkg
    make
    sudo make install
    Add to PATH!
    Don’t upgrade any libraries that come with GHC itself (except cabal)

  3. Jan Stolarek says:

    What about dependency on libgmp? If you have exactly the required version then of course your procedure will work. But otherwise I think there is no alternative to compilation from source. Or am I wrong?

  4. Al says:

    Has anyone ever figured out how popular Haskell would be if it wasn’t so nearly impossible to install? Most of the functional languages are problematic, but Haskell is about the worst. Even so, it is also about the most popular of all of them. Imagine how many would use it if the instructions on the haskell web site were simple, direct, and actually worked, and if you didn’t have to have it installed to get it installed. It would be near universal if you could actually download and install one package, no matter how large, and actually start programming it.

  5. Jan Stolarek says:

    Has anyone ever figured out how popular Haskell would be if it wasn’t so nearly impossible to install?

    Of course. Haskell users and developers are well aware of the issues you’re mentioning. The problem is that these things just don’t seem that easy to solve, but I think there is a constant (although slow) progress towards making things better.

  6. Al says:

    >> I think there is a constant (although slow) progress towards making things better <<

    I keep trying to get started with it, and I don't see the progress. A year or so back, I was able to install ghc and the haskell platform, get through a few chapters of one of the introductory books. A few weeks ago I got just about nowhere trying. The rewards are so attractive that I doubt that I'll be able to stop trying. And it's easy to imagine that there would be at least a 10x increase in use of haskell if it were easy to actually get it going and keep it going while experimenting with all the powerful haskell code that is freely available.

  7. > What about dependency on libgmp? If you have exactly the required
    > version then of course your procedure will work. But otherwise I
    > think there is no alternative to compilation from source. Or am I
    > wrong?

    I didn’t encounter that problem when I installed ghc-7.6.2, either because I already had a copy libgmp.so.3, or because I had already applied the workaround described below.

    Today I installed ghc-7.6.3 on a machine with no previous Haskell installation, and I encountered the same problem you described, but this time I was able to work around it with the following command:

    sudo ln -s /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.5 /usr/lib/libgmp.so.3

    After that, I was able to install ghc and the Github version of cabal in the normal way.

  8. Jan Stolarek says:

    I was able to work around it with the following command:

    sudo ln -s /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.5 /usr/lib/libgmp.so.3

    After that, I was able to install ghc and the Github version of cabal in the normal way.

    And the compiler works without a problem? That would be surprising. I tried using newer version of libgmp in the same way that you described only to get errors.

  9. Yes, and it’s been working just fine for me. I found that workaround somewhere, and it sounded familiar, so I tried it. But I don’t really know how this library versioning stuff works, so I can’t say if what I did was a “good” workaround or not.

Leave a Reply

(required)

Staypressed theme by Themocracy