Jonathan
Jonathan

Reputation: 11321

How can I install a recent version of the Haskell GHC compiler on Ubuntu?

I noticed that I'm running an old version of GHC on Ubuntu 15.04. Can I get a newer one without having to compile it from source?

Upvotes: 10

Views: 4737

Answers (2)

Michael Steele
Michael Steele

Reputation: 15772

There is a PPA with prepackaged binaries for many recent versions of GHC.

  1. Add the following to your /etc/apt/sources.list.d/extra-ppas.list file:

    deb http://ppa.launchpad.net/hvr/ghc/ubuntu vivid main deb-src http://ppa.launchpad.net/hvr/ghc/ubuntu vivid main

  2. Install one of the PPA's versions of GHC. They are named tool-version while the ones that come with Ubuntu are simply named tool. The most recent at the time of this writing is ghc-7.10.2, for example.

  3. GHC will be installed under /opt/ghc/<version>/bin. Add this folder to your path to use that version of GHC.

Upvotes: 4

user2913694
user2913694

Reputation:

I highly recommend using Stack. It has made my life 110% easier and solves your problem.

You can get GHC 7.8 with 1106 packages that won't break (no cabal hell, no cabal sandbox install marathons) or you can get GHC 7.10 with 1028 packages - source.

You can even run different versions of GHC in different projects! Check the FAQ for details. To install if you are on an Ubuntu system, follow the installation docs.

Edit: Just tried to create a new stack project with GHC 7.10 and there was a bit more to it than first expected. After installing stack you will run:

stack new

Then, you'll need to edit your stack.yaml, and change the default resolver from

resolver: lts-2.19

to:

resolver: ghc-7.10

Then you can run:

stack setup

Or

stack build --install-ghc  # to build as well!

and you will have a new stack project with GHC 7.10. Reference for stack.yaml is here.

Upvotes: 11

Related Questions