Recently, I discovered that the GHC developers classify the platforms that they support into different tiers. Tier 1, somewhat surprisingly, includes four distinct operating systems: Windows, OS X, Linux, …and FreeBSD. That last one surprised me, since they don’t even advertise their FreeBSD support that much on the Haskell Platform website. (You have to go to the Linux section to find the FreeBSD information.)
This got me curious as to how easy to use GHC is on FreeBSD, since some other OSes have some kinks that need ironed (*cough*Windows*cough*). Since I found the process of installing GHC and
cabal on FreeBSD to be somewhat nontrivial, I’ll post the exact steps I took here.
- A FreeBSD distribution. You can get the real deal here, or you can get a noob-friendlier derivative such as PC-BSD. I used the latter.
- Internet access
There are two paths you can go by
There are two common ways of installing GHC and its associated bells and whistles. One can install the Haskell Platform, which is a collection of GHC, the
cabal build system, several prebuilt packages, and other utilities. Installing the Haskell Platform is quicker and less painful, but it is updated less frequently. If you prefer this, go to the Haskell Platform section.
Alternatively, you can install a binary distribution of GHC and then build all of the needed tools yourself. This requires more heavy lifting, but you gain the ability to use whatever packages you want (instead of whatever the Haskell Platform is bundled with). If you prefer this, go to the Binary distribution section.
Luckily, the Haskell Platform exists as a FreeBSD port. At the time of this post, the latest version includes GHC 7.6.3. You can install the Platform by doing one of the following:
- Opening a terminal and running
pkg install hs-haskell-platformas root
- (On PC-BSD) Go to App Cafe. Click Browser View > Raw Packages. Then search for “Haskell Platform” and install it.
If you don’t want the full Haskell Platform, you can also individually install the
Either way, once everything you want is installed, you should edit
~/.cshrc and add
~/.cabal/bin to your
PATH so that you can run Haskell executables. Make sure that you put it before
/usr/local/bin so that more recently installed versions of
cabal take precedence over the Haskell Platform’s version.
Next, we need to install some GNU software, since BSD distributions tend to spurn it. According to the FreeBSD Haskell devs, you need at least this much installed:
compat8x(if using FreeBSD 9 or later)
gcc(4.7 or later)
On PC-BSD, I already had
libiconv installed, so I only needed to install the following:
You might be tempted to use
clang, which is now FreeBSD’s default compiler, instead of
gcc, but I had nothing but problems using it. The FreeBSD Haskell devs also advise not using
clanguntil it is further tested.
Now we can install GHC:
Note that this won’t configure GHC’s manpages correctly. If you want them, make sure to run
cp /usr/local/share/man/man1/ghc.1 /usr/local/man/man1/as root after installing GHC.
cabal-install archive and open
bootstrap.sh in your favorite editor. As of version 126.96.36.199, line 208 of this file, namely:
won’t work correctly on FreeBSD. To fix it, change this line to:
bootstrap.sh will try to look for
gcc, but it is probably named
gcc47 or something similar instead. To help ease
boostrap.sh’s burden, make a symbolic link with
ln -s /usr/local/bin/gcc47 /usr/local/bin/gcc as root. Then install
cabal-install by running
Finally, you should edit
~/.cshrc and add
~/.cabal/bin to your
PATH so that you can run
cabal and other Haskell executables.
Regardless of how you installed GHC, you’ll notice some problems if you try to install packages that require nontrivial build tools such as
hsc2hs. The problems might manifest themselves as errors such as
runProcess: runInteractiveProcess: exec: permission denied (Permission denied). This hints at the problem: a build tool is trying to execute a file in
/tmp has the
noexec filesystem option.
In PC-BSD, this can be fixed by going to the PC-BSD Control Panel > Hardware > Disk Manager. Under the ZFS Filesystems tab, right-click
tank/tmp and click “Edit properties”. Change
exec to “on” and click “Apply.”
That should clear the way for
cabal to do its thing. Now you can get the very latest stuff: