This script allows you to easily switch between different versions of GHC (the Glasgow Haskell Compiler) that are installed on your system. It's a simple Bash script that manipulates a symlink pointing to a subdirectory with the current preferred version of the GHC binaries.
Install the Haskell Platform (HP) for Mac OS X.
The HP creates a directory
/Library/Frameworks/GHC.frameworkwith all the tools needed to use Haskell. In particular, the
Versionssubdirectory contains the GHC installation. Each future installation of HP adds a new version in a subdirectory of
Versions, there is a symlink
Currentthat points to the subdirectory with the "current" GHC. We use that to determine which GHC we want to use at any one point in time.
Update the HP symlinks in
To make the HP tools part of the standard path, the HP installer creates symlinks in
/usr/binthat point to the binaries in the current version. By default, they may link to the specific subdirectory in
Versions. You should relink them, replacing the specific version with
You can find the current symlinks with
ls -l /usr/bin/ | grep GHC\.framework. For example, I see
runhaskell, among others. There may also be version-specific ones like
ghc-7.4.1which you may want to delete, since they will not be applicable if you change your current version.
For each symlink
$Ffrom above, recreate it with
sudo ln -sf /Library/Frameworks/GHC.framework/Versions/Current/usr/bin/$F /usr/bin/$F
And you're done!
ghc-ver listto see the versions available.
It simply looks at the subdirectories in
/Library/Frameworks/GHC.framework/Versionsand gives you the list of names. Thus, it helps to name the versions appropriately and concisely.
ghc-ver 7.4.1to select version
7.4.1if it is available. You will get a notice if it is not, and you will also get a confirmation of the current GHC version, which should be unchanged in the case of failure.
Install any future versions of the HP as normal. Unless the installer changes, you should just be able to switch to the new version using
ghc-ver. (You may need to update the
/usr/binsymlinks as described above.)
Install any non-HP versions of GHC in
In the case where you are compiling GHC from source, say the version is called
HEAD, you can create the directory
/Library/Frameworks/GHC.framework/Versions/HEADand configure GHC as follows:
./configure \ --prefix=/Library/Frameworks/GHC.framework/Versions/HEAD/usr \ --with-gmp-libraries=/Library/Frameworks/GMP.framework \ --with-gmp-includes=/Library/Frameworks/GMP.framework/Headers
sudo make installwill do the right thing.
You may or may not need the extra
GMP.frameworkflags. There have be times in the past where GMP did not work properly when compiling GHC from source.