Installing GHC

The Glasgow Haskell Compiler User's Guide, Version 6.2
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. For the other `fptools` programs, many are written in Haskell, so binary distributions allow you to install them without having a Haskell compiler.)

This guide is in several parts:

- Installing on Unix-a-likes (Section 2.1).

- Installing on Windows (Section 2.2).

- The layout of installed files (Section 2.3). 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

For certain platforms, we 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.

We generally provide the following packages:

RedHat or SuSE Linux/x86

  RPM source & binary packages for RedHat and SuSE Linux (x86 only) are available for most major releases.

Debian Linux/x86

  Debian packages for Linux (x86 only), also for most major releases.

FreeBSD/x86

  On FreeBSD/x86, GHC can be installed using either the ports tree (`cd /usr/ports/lang/ghc && make install`) or from a pre-compiled package available from your local FreeBSD mirror.

Other platform-specific packages may be available, check the GHC download page for details.

## 2.1.2. GHC binary distributions

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

    % cd /your/scratch/space
    % gunzip < ghc-x.xx-sun-sparc-solaris2.tar.gz | tar xvf -

Then you should find a single directory, `ghc-`version``, with the following structure:

`Makefile.in`

  the raw material from which the `Makefile` will be made (Section 2.1.2.1).

`configure`

  the configuration script (Section 2.1.2.1).

`README`

  Contains this file summary.

`INSTALL`

  Contains this description of how to install the bundle.

`ANNOUNCE`

  The announcement message for the bundle.

`NEWS`

  release notes for the bundle—a longer version of `ANNOUNCE`. For GHC, the release notes are contained in the User Guide and this file isn't present.

`bin/`platform``

  contains platform-specific executable files to be invoked directly by the user. These are the files that must end up in your path.

`lib/`platform`/`

  contains platform-specific support files for the installation. Typically there is a subdirectory for each `fptools` project, whose name is the name of the project with its version number. For example, for GHC there would be a sub-directory `ghc-x.xx`/ where `x.xx` is the version number of GHC in the bundle.

  These sub-directories have the following general structure:

  `libHSstd.a` etc:

    supporting library archives.

  `ghc-iface.prl` etc:

    support scripts.

  `import/`

    (`.hi`) for the prelude.

  `include/`

    A few C `#include` files.

`share/`

  contains platform-independent support files for the installation. Again, there is a sub-directory for each `fptools` project.

`html/`

  contains HTML documentation files (one sub-directory per project).

### 2.1.2.1. Installing

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

You can now either start using the tools in-situ without going through any installation process, just type `make in-place` to set the tools up for this. You'll also want to add the path which `make` will now echo to your `PATH` environment variable. This option is useful if you simply want to try out the package and/or you don't have the necessary privileges (or inclination) to properly install the tools locally. Note that if you do decide to install the package `properly' at a later date, you have to go through the installation steps that follow.

To install a package, you'll have to do the following:

1. Edit the `Makefile` and check the settings of the following variables:

   `platform`

     the platform you are going to install for.

   `bindir`

     the directory in which to install user-invokable binaries.

   `libdir`

     the directory in which to install platform-dependent support files.

   `datadir`

     the directory in which to install platform-independent support files.

   `infodir`

     the directory in which to install Emacs info files.

   `htmldir`

     the directory in which to install HTML documentation.

   `dvidir`

     the directory in which to install DVI documentation.

   The values for these variables can be set through invocation of the configure script that comes with the distribution, but doing an optical diff to see if the values match your expectations is always a Good Idea.

   Instead of running configure, it is perfectly OK to copy `Makefile.in` to `Makefile` and set all these variables directly yourself. But do it right!

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

3. `rehash` (t?csh or zsh users), so your shell will see the new stuff in your bin directory.

4. Once done, test your “installation” as suggested in Section 2.1.2.3. 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. What bundles there are

There are plenty of “non-basic” GHC bundles. The files for them are called `ghc-x.xx-`bundle`-`platform`.tar.gz`, where the `platform` is as above, and `bundle` is one of these:

`prof`:

  Profiling with cost-centres. You probably want this.

`par`:

  Parallel Haskell features (sits on top of PVM). You'll want this if you're into that kind of thing.

`gran`:

  The “GranSim” parallel-Haskell simulator (hmm… mainly for implementors).

`ticky`:

  “Ticky-ticky” profiling; very detailed information about “what happened when I ran this program”—really for implementors.

One likely scenario is that you will grab two binary bundles—basic, and profiling. We don't usually make the rest, although you can build them yourself from a source distribution.

The various GHC bundles are designed to be unpacked into the same directory; then installing as per the directions above will install the whole lot in one go. Note: you must at least have the basic GHC binary distribution bundle, these extra bundles won't install on their own.

### 2.1.2.3. 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!

Some simple-but-profitable tests are to compile and run the notorious `nfib` program, using different numeric types. Start with `nfib :: Int -> Int`, and then try `Integer`, `Float`, `Double`, `Rational` and perhaps the overloaded version. Code for this is distributed in `ghc/misc/examples/nfib/` in a source distribution.

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

Prev | Home | Next
Release notes for version 6.2 |  | Installing on Windows