Chapter 2. Installing GHC
Prev |  | Next

## Chapter 2. Installing GHC

Installing from binary distributions is easiest, and recommended! (Why binaries? Because GHC is a Haskell compiler written in Haskell, so you've got to bootstrap it somehow. We provide machine-generated C-files-from-Haskell for this purpose, but it's really quite a pain to use them. If you must build GHC from its sources, using a binary-distributed GHC to do so is a sensible way to proceed.)

This guide is in several parts:

- Installing on Unix-a-likes (Section 2.1, “Installing on Unix-a-likes”).

- Installing on Windows (Section 2.2, “Installing on Windows”).

- The layout of installed files (Section 2.3, “The layout of installed files”). You don't need to know this to install GHC, but it's useful if you are changing the implementation.

## 2.1. Installing on Unix-a-likes

### 2.1.1. When a platform-specific package is available

Most common OSes provide GHC binaries packaged using the native package format for the platform. This is likely to be by far the best way to install GHC for your platform if one of these packages is available, since dependencies will automatically be handled and the package system normally provides a way to uninstall the package at a later date.

Check the distribution packages page to see if there is a package available for your platform.

### 2.1.2. GHC binary distributions

Binary distributions come in “bundles,” called `ghc-`version`-`platform`.tar.bz2`. (See the building guide for the definition of a platform.) Suppose that you untar a binary-distribution bundle, thus:

    % cd /your/scratch/space
    % bunzip2 < ghc-version-platform.tar.bz2 | tar xvf -

Then you should find the bundle contents inside a single directory, `ghc-`version``.

#### 2.1.2.1. Installing

OK, so let's assume that you have unpacked your chosen bundles. What next? Well, you will first need to `configure` the bundle by changing to the bundle's top-level directory and typing `./configure`. That should convert `Makefile-vars.in` to `Makefile-vars`.

The `configure` script takes a number of flags. The most commonly used is the `--prefix=`/path/to/install/in`` flag, which tells the bundle that you want it to be installed in `/path/to/install/in` rather than the default location (/usr/local). To see all the flags that configure accepts, run `configure --help`.

Then do the following:

1. Run `make install`. This should work with ordinary Unix `make`—no need for fancy stuff like GNU `make`.

2. If appropriate, add the bin directory to your PATH, as instructed.

3. You may need to run `rehash` (t?csh or zsh users), in order for your shell to see the new stuff in your bin directory.

4. Once done, test your “installation” as suggested in Section 2.1.2.2, “Testing that GHC seems to be working ”. Be sure to use a `-v` option, so you can see exactly what pathnames it's using. If things don't work as expected, check the list of known pitfalls in the building guide.

When installing the user-invokable binaries, this installation procedure will install GHC as `ghc-x.xx` where `x.xx` is the version number of GHC. It will also make a link (in the binary installation directory) from `ghc` to `ghc-x.xx`. If you install multiple versions of GHC then the last one “wins”, and “`ghc`” will invoke the last one installed. You can change this manually if you want. But regardless, `ghc-x.xx` should always invoke GHC version `x.xx`.

#### 2.1.2.2. Testing that GHC seems to be working

The way to do this is, of course, to compile and run this program (in a file `Main.hs`):

    main = putStr "Hello, world!\n"

Compile the program, using the `-v` (verbose) flag to verify that libraries, etc., are being found properly:

    % ghc -v -o hello Main.hs

Now run it:

    % ./hello
    Hello, world!

For more information on how to “drive” GHC, read on...

Prev |  | Next
1.6. Release notes for version 6.8.1 | Home | 2.2. Installing on Windows