1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <chapter id="installing-bin-distrib">
3 <title>Installing GHC</title>
4 <indexterm><primary>binary installations</primary></indexterm>
5 <indexterm><primary>installation, of binaries</primary></indexterm>
8 Installing from binary distributions is easiest, and recommended!
9 (Why binaries? Because GHC is a Haskell compiler written in Haskell,
10 so you've got to bootstrap it somehow. We provide machine-generated
11 C-files-from-Haskell for this purpose, but it's really quite a pain to
12 use them. If you must build GHC from its sources, using a
13 binary-distributed GHC to do so is a sensible way to proceed.)
16 <para>This guide is in several parts:</para>
20 <para> Installing on Unix-a-likes (<xref
21 linkend="unix-a-likes"/>). </para>
24 <para> Installing on Windows (<xref
25 linkend="install-windows"/>). </para>
28 <para> The layout of installed files (<xref
29 linkend="install-files"/>). You don't need to know this to
30 install GHC, but it's useful if you are changing the
31 implementation.</para>
35 <sect1 id="unix-a-likes"><title>Installing on Unix-a-likes</title>
38 <title>When a platform-specific package is available</title>
40 <para>Most common OSes provide GHC binaries packaged
41 using the native package format for the platform. This is
42 likely to be by far the best way to install GHC for your
43 platform if one of these packages is available, since
44 dependencies will automatically be handled and the package
45 system normally provides a way to uninstall the package at a
48 <para>Check the <ulink url="http://www.haskell.org/ghc/distribution_packages.html">distribution packages</ulink> page to see if there is a package available for your platform.</para>
52 <title>GHC binary distributions</title>
55 <indexterm><primary>bundles of binary stuff</primary></indexterm>
59 Binary distributions come in “bundles,” called
60 <literal>ghc-<replaceable>version</replaceable>-<replaceable>platform</replaceable>.tar.bz2</literal>. (See the <ulink url="http://hackage.haskell.org/trac/ghc/wiki/Building">building guide</ulink> for the definition of a platform.) Suppose that you untar a binary-distribution bundle, thus:
65 % cd /your/scratch/space
66 % bunnzip2 < ghc-<replaceable>version</replaceable>-<replaceable>platform</replaceable>.tar.bz2 | tar xvf -</screen>
70 Then you should find the bundle contents inside a single directory,
71 <literal>ghc-<replaceable>version</replaceable></literal>.
75 <title>Installing</title>
78 OK, so let's assume that you have unpacked your chosen bundles. What
79 next? Well, you will first need to
80 <literal>configure</literal><indexterm><primary>configure</primary></indexterm>
82 changing to the bundle's top-level directory
83 and typing <literal>./configure</literal>. That should convert
84 <literal>Makefile-vars.in</literal> to <literal>Makefile-vars</literal>.
88 The <literal>configure</literal> script takes a number of flags. The most
90 <literal>--prefix=<replaceable>/path/to/install/in</replaceable></literal>
91 flag, which tells the bundle that you want it to be installed in
92 <replaceable>/path/to/install/in</replaceable> rather than the default
93 location (/usr/local).
94 To see all the flags that configure accepts, run
95 <literal>configure --help</literal>.
99 Then do the following:
108 Run <literal>make install</literal>. This <emphasis>
109 should</emphasis> work with ordinary Unix
110 <literal>make</literal>—no need for fancy stuff like GNU
111 <literal>make</literal>.
117 If appropriate, add the bin directory to your PATH, as instructed.
123 You may need to run <literal>rehash</literal> (t?csh or zsh users), in
124 order for your shell to see the new stuff in your bin directory.
130 Once done, test your “installation” as suggested in
131 <xref linkend="GHC-test"/>. Be sure to use a <literal>-v</literal>
132 option, so you can see exactly what pathnames it's using.
133 If things don't work as expected, check the list of known pitfalls in
134 the <ulink url="http://hackage.haskell.org/trac/ghc/wiki/Building">building guide</ulink>.
144 <indexterm><primary>link, installed as ghc</primary></indexterm>
145 When installing the user-invokable binaries, this installation
146 procedure will install GHC as <literal>ghc-x.xx</literal> where <literal>x.xx</literal> is the version
147 number of GHC. It will also make a link (in the binary installation
148 directory) from <literal>ghc</literal> to <literal>ghc-x.xx</literal>. If you install multiple versions
149 of GHC then the last one “wins”, and “<literal>ghc</literal>” will invoke the last
150 one installed. You can change this manually if you want. But
151 regardless, <literal>ghc-x.xx</literal> should always invoke GHC version <literal>x.xx</literal>.
157 <sect3 id="GHC-test">
158 <title>Testing that GHC seems to be working
162 <indexterm><primary>testing a new GHC</primary></indexterm>
166 The way to do this is, of course, to compile and run <emphasis>this</emphasis> program
167 (in a file <literal>Main.hs</literal>):
173 main = putStr "Hello, world!\n"
179 Compile the program, using the <literal>-v</literal> (verbose) flag to verify that
180 libraries, etc., are being found properly:
183 % ghc -v -o hello Main.hs</screen>
192 Hello, world!</screen>
196 <para>For more information on how to “drive” GHC, read
206 <sect1 id="install-windows"><title>Installing on Windows</title>
209 Getting the Glasgow Haskell Compiler (post 5.02) to run on Windows platforms is
210 a snap: the installer does everything you need.
213 <sect2><title>Installing GHC on Windows</title>
216 To install GHC, use the following steps:
219 <listitem><para>Download the installer
222 url="http://www.haskell.org/ghc/download.html">GHC download page</ulink>.
225 <listitem><para>Run the installer.
226 On Windows, all of GHC's files are installed in a single directory.
227 You can override it, but by default this directory is
228 <filename>c:/ghc/ghc-<replaceable>version</replaceable></filename>.
229 The executable binary for GHC will be installed in the
230 <filename>bin/</filename> sub-directory of the installation directory.
231 If you want to invoke GHC from a command line, add this
232 to your <literal>$PATH</literal> environment variable.
235 When installation is complete, you should find GHCi and the GHC
236 documentation are available in your Start menu under
237 "Start/All Programs/GHC/ghc-<replaceable>version</replaceable>".
242 GHC needs a directory in which to create, and later delete, temporary files.
243 It uses the standard Windows procedure <literal>GetTempPath()</literal> to
244 find a suitable directory. This procedure returns:
246 <listitem><para>The path in the environment variable TMP,
247 if TMP is set.</para></listitem>
248 <listitem><para>Otherwise, the path in the environment variable TEMP,
249 if TEMP is set.</para></listitem>
250 <listitem><para>Otherwise, there is a per-user default which varies
251 between versions of Windows. On NT and XP-ish versions, it might
253 <filename>c:\Documents and Settings\<username>\Local Settings\Temp</filename>.
256 The main point is that if you don't do anything GHC will work fine,
257 but if you want to control where the directory is, you can do so by
263 To test the fruits of your labour, try now to compile a simple
269 module Main(main) where
271 main = putStrLn "Hello, world!"
272 bash$ ghc -o main main.hs
281 You do <emphasis>not</emphasis> need the Cygwin toolchain, or anything
282 else, to install and run GHC.
285 An installation of GHC requires about 365M of disk space.
286 To run GHC comfortably, your machine should have at least
291 <sect2><title>Moving GHC around</title>
293 Once GHC is installed, you can freely move the entire GHC tree just by copying
294 the <filename>c:/ghc/ghc-<replaceable>version</replaceable></filename>
295 directory. (You will need to fix up
296 the links in "Start/All Programs/GHC/ghc-<replaceable>version</replaceable>"
300 It is OK to put GHC tree in a directory whose path involves spaces. However,
301 don't do this if you use want to use GHC with the Cygwin tools,
302 because Cygwin can get confused when this happens.
303 We haven't quite got to the bottom of this, but so far as we know it's not
304 a problem with GHC itself. Nevertheless, just to keep life simple we usually
305 put GHC in a place with a space-free path.
310 <title>Installing ghc-win32 FAQ</title>
314 <term>I'm having trouble with symlinks.</term>
316 <para>Symlinks only work under Cygwin (<xref linkend="install" />),
317 so binaries not linked to the Cygwin
318 DLL, in particular those built for Mingwin, will not work with
324 <term>I'm getting “permission denied” messages from the
325 <command>rm</command> or <command>mv</command>.</term>
327 <para>This can have various causes: trying to rename a directory
328 when an Explorer window is open on it tends to fail. Closing the
329 window generally cures the problem, but sometimes its cause is
330 more mysterious, and logging off and back on or rebooting may be
331 the quickest cure.</para>
340 <sect1 id="install-files"><title>The layout of installed files</title>
343 This section describes what files get installed where. You don't need to know it
344 if you are simply installing GHC, but it is vital information if you are changing
347 <para> GHC is installed in two directory trees:</para>
350 <term>Library directory,</term>
351 <listitem> <para> known as <filename>$(libdir)</filename>, holds all the
352 support files needed to run GHC. On Unix, this
353 directory is usually something like <filename>/usr/lib/ghc/ghc-5.02</filename>. </para>
357 <term>Binary directory</term>
358 <listitem> <para> known as <filename>$(bindir)</filename>, holds executables that
359 the user is expected to invoke.
361 <filename>ghc</filename> and <filename>ghci</filename>. On Unix, this directory
362 can be anywhere, but is typically something like <filename>/usr/local/bin</filename>. On Windows,
363 however, this directory <emphasis>must be</emphasis> <filename>$(libdir)/bin</filename>.
370 When GHC runs, it must know where its library directory is.
371 It finds this out in one of two ways:
376 <filename>$(libdir)</filename> is passed to GHC using the <option>-B</option> flag.
377 On Unix (but not Windows), the installed <filename>ghc</filename> is just a one-line
378 shell script that invokes the real GHC, passing a suitable <option>-B</option> flag.
379 [All the user-supplied flags
380 follow, and a later <option>-B</option> flag overrides an earlier one, so a user-supplied
385 <para> On Windows (but not Unix), if no <option>-B</option> flag is given, GHC uses a system
386 call to find the directory in which the running GHC executable lives, and derives
387 <filename>$(libdir)</filename> from that. [Unix lacks such a system call.]
388 That is why <filename>$(bindir)</filename> must be <filename>$(libdir)/bin</filename>.
393 <sect2> <title>The binary directory</title>
395 <para>The binary directory, <filename>$(bindir)</filename>, contains user-visible
396 executables, notably <filename>ghc</filename> and <filename>ghci</filename>.
397 You should add it to your <literal>$PATH</literal>.
400 <para>On Unix, the user-invokable <filename>ghc</filename> invokes <filename>$(libdir)/ghc-<replaceable>version</replaceable></filename>,
401 passing a suitable <option>-B</option> flag to tell <filename>ghc-<replaceable>version</replaceable></filename> where
402 <filename>$(libdir)</filename> is.
403 Similarly <filename>ghci</filename>, except the extra flag <literal>--interactive</literal> is passed.
406 <para>On Win32, the user-invokable <filename>ghc</filename> binary
407 is the Real Thing (no intervening
408 shell scripts or <filename>.bat</filename> files).
409 Reason: we sometimes invoke GHC with very long command lines,
410 and <filename>cmd.exe</filename> (which executes <filename>.bat</filename> files)
411 truncates them. Similarly <filename>ghci</filename> is a C wrapper program that invokes <filename>ghc --interactive</filename>
412 (passing on all other arguments), not a <filename>.bat</filename> file.
418 <sect2> <title>The library directory</title>
420 <para>The layout of the library directory, <filename>$(libdir)</filename>,
421 is almost identical on
422 Windows and Unix, as follows. Differences between Windows and Unix
423 are annotated <literal>[Win32 only]</literal> and are commented below.</para>
427 package.conf GHC package configuration
428 ghc-usage.txt Message displayed by ghc ––help
429 ghci-usage.txt Message displayed by ghci ––help
431 bin/ [Win32 only] User-visible binaries
435 unlit Remove literate markup
437 touchy.exe [Win32 only]
438 perl.exe [Win32 only]
441 ghc-x.xx GHC executable [Unix only]
443 ghc-split Asm code splitter
444 ghc-asm Asm code mangler
446 gcc-lib/ [Win32 only] Support files for gcc
447 specs gcc configuration
449 cpp0.exe gcc support binaries
456 libmingw32.a Standard
461 hslibs-imports/ GHC interface files for the...
462 ghc/*.hi ...'ghc' library
464 include/ C header files
465 StgMacros.h GHC-specific
468 mingw/*.h [Win32 only] Mingwin header files
474 libHSrts*.a GHC RTS archive
475 libHSghc.a GHC package archive
477 HSrts.o GHC RTS linkable, used by ghci
478 HSghc.o GHC package linkable, used by ghci
485 <para><filename>$(libdir)</filename> also contains support
486 binaries. These are <emphasis>not</emphasis> expected to be
487 on the user's <filename>PATH</filename>, but are invoked
488 directly by GHC. In the Makefile system, this directory is
489 also called <filename>$(libexecdir)</filename>, but
490 <emphasis>you are not free to change it</emphasis>. It must
491 be the same as <filename>$(libdir)</filename>.</para>
495 <para>We distribute <filename>gcc</filename> with the Win32 distribution of GHC, so that users
496 don't need to install <filename>gcc</filename>, nor need to care about which version it is.
497 All <filename>gcc</filename>'s support files are kept in <filename>$(libdir)/gcc-lib/</filename>.
502 <para>Similarly, we distribute <filename>perl</filename> and a <filename>touch</filename>
503 replacement (<filename>touchy.exe</filename>)
504 with the Win32 distribution of GHC. </para>
508 <para>The support programs <filename>ghc-split</filename>
509 and <filename>ghc-asm</filename> are Perl scripts. The
510 first line says <literal>#!/usr/bin/perl</literal>; on Unix, the
511 script is indeed invoked as a shell script, which invokes
512 Perl; on Windows, GHC invokes
513 <filename>$(libdir)/perl.exe</filename> directly, which
514 treats the <literal>#!/usr/bin/perl</literal> as a comment.
515 Reason: on Windows we want to invoke the Perl distributed
516 with GHC, rather than assume some installed one. </para>
528 ;;; Local Variables: ***
530 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***