# Installing OCaml with GODI

In this section, we will see how to install OCaml using GODI, a package manager designed specifically to help OCaml programmers install, upgrade or uninstall applications, libraries and tools. While starting with GODI is not the easiest of tasks, using GODI is generally the best way of having a robust installation of OCaml and all the important tools.

This tutorial is meant for users of Linux, MacOS X, BSD and other variants of Unix. It could also be completed to work for Windows, but that's a new story altogether.

## Necessary tools

### Under Linux/BSD

1. Open a terminal. A terminal is a small utility used to communicate instructions to the computer in a minimal programming language called the shell or the command interpreter.
   - Under Linux and BSD, to open a terminal, you typically need to open menu Applications, submenu Accessories and choose Terminal.
   - Under recent versions MacOS X, to open a terminal, you may push keys <Command>+<Spacebar> and write "Terminal".
   - Under all versions MacOS X, to open a terminal, you may open directory Applications and choose Terminal.app .
2. Once the terminal is opened, you should see a black box and a blinking text cursor, somethine along the lines of `yoric@Blefuscu:~$ _` . Here, `yoric` is my name and `Blefuscu` is the name of the computer I'm using. Depending on your name, the name of the computer you're using and the configuration of your computer, you may see something different. However, you will probably see the `$`.
3. Install GCC, m4, wget, make, gzip, bzip2 and patch. The method to do this depends on your version of Linux/BSD.
   - Under Ubuntu or Debian, write `sudo apt-get install gcc m4 wget make gzip bzip2` and press <Enter>. Accept the various suggestions.
   - Under Fedora or Red Hat, write `sudo yum install gcc m4 wget make gzip bzip2` and press <Enter>. Accept the various suggestions.
4. Once installation is complete, you may close the terminal.

### Under MacOS X

1. Find your Apple Developer Tools, which are provided by Apple with your copy of MacOS X. If your version of MacOS X came as a DVD, they are on the DVD, otherwise they are on a different CD.
2. Install XCode from that CD/DVD. XCode is a set of tools for developers, including a text editor for programmers, several programming languages, etc. Unfortunately, no OCaml (yet).
3. Go to http://ftp.gnu.org/pub/gnu/wget/wget-1.11.tar.gz.
4. Your browser may offer you to open the file with some decompressor -- depending on what software is installed on your computer, this decompressor may be called file-roller, Ark, ShrinkWrap... Choose rather to save the file. You will need to choose a directory. In case of doubt, directory `/tmp` is a good choice.
5. Open a terminal. A terminal is a small utility used to communicate instructions to the computer in a minimal programming language called the shell or the command interpreter.
   - Under recent versions MacOS X, to open a terminal, you may push keys <Command>+<Spacebar> and write "Terminal".
   - Under all versions MacOS X, to open a terminal, you may open directory Applications and choose Terminal.app .
6. Once the terminal is opened, you should see a black box and a blinking text cursor, somethine along the lines of `yoric@Blefuscu:~$ _` . Here, `yoric` is my name and `Blefuscu` is the name of the computer I'm using. Depending on your name, the name of the computer you're using and the configuration of your computer, you may see something different. However, you will probably see the `$`.
7. In the terminal, type `cd /tmp` -- if you have saved your files to another directory than `/tmp`, replace appropriately.
8. Still in the terminal, type the following commands (press <Enter> at the end of each of the following lines) `tar -zxf wget-1.11.tar.gz cd wget-1.11/ ./configure`
9. You should see something along the lines of `yoric@Blefuscu:/tmp/wget-1.11$ ./configure configure: configuring for GNU Wget 1.11 checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking whether make sets $(MAKE)... yes checking for a BSD-compatible install... /usr/bin/install -c checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed [ ...] config.status: creating src/config.h config.status: executing default commands generating po/POTFILES from ./po/POTFILES.in creating po/Makefile yoric@Blefuscu:/tmp/wget-1.11$` Once you have reached that stage, write `make` This will instruct your computer to turn wget from a source code (i.e. a description of what the computer should do) into an application. By the way, wget is a downloading program, which is used by GODI.
10. You should see something along the lines of `yoric@Blefuscu:/tmp/wget-1.11$ make cd src && make CC='gcc' CPPFLAGS='' DEFS='-DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\" -DLOCALEDIR=\"/usr/local/share/locale\"' CFLAGS='-O2 -Wall' LDFLAGS='' LIBS='-ldl -lrt -lssl -lcrypto ' DESTDIR='' prefix='/usr/local' exec_prefix='/usr/local' bindir='/usr/local/bin' infodir='/usr/local/share/info' mandir='/usr/local/share/man' manext='1' make[1]: Entering directory `/tmp/wget-1.11/src' gcc -I. -I. -DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\" -DLOCALEDIR=\"/usr/local/share/locale\" -O2 -Wall -c cmpt.c gcc -I. -I. -DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\" -DLOCALEDIR=\"/usr/local/share/locale\" -O2 -Wall -c connect.c [...] cd windows && make CC='gcc' CPPFLAGS='' DEFS='-DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\" -DLOCALEDIR=\"/usr/local/share/locale\"' CFLAGS='-O2 -Wall' LDFLAGS='' LIBS='-ldl -lrt -lssl -lcrypto ' DESTDIR='' prefix='/usr/local' exec_prefix='/usr/local' bindir='/usr/local/bin' infodir='/usr/local/share/info' mandir='/usr/local/share/man' manext='1' make[1]: Entering directory `/tmp/wget-1.11/windows' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/tmp/wget-1.11/windows'` Once you have reached that stage, write `sudo make install` and enter your password when prompted. This will actually install `wget`.
11. Once installation is complete, you can close your terminal.

## Downloading and unpacking GODI

1. Go to http://godi.camlcity.org/godi/index.html and choose "Download GODI"
2. Your browser may offer you to open the file with some decompressor -- depending on what software is installed on your computer, this decompressor may be called file-roller, Ark, ShrinkWrap... Choose rather to save the file. You will need to choose a directory. In case of doubt, directory `/tmp` is a good choice.
3. In your decompressor, choose to extract the contents of the file. You may choose whichever directory suits you -- once this tutorial is complete, you will not need the files anymore. In case of doubt, directory `/tmp` is a good choice.
4. Once extraction is complete, you may close the decompressor. Remember in which directory you have extracted the file. For the rest of this tutorial, we will assume that you have chosen directory `/tmp`.

1. Open a terminal. A terminal is a small utility used to communicate instructions to the computer in a minimal programming language called the shell or the command interpreter.
   - Under Linux and BSD, to open a terminal, you typically need to open menu Applications, submenu Accessories and choose Terminal.
   - Under recent versions MacOS X, to open a terminal, you may push keys <Command>+<Spacebar> and write "Terminal".
   - Under all versions MacOS X, to open a terminal, you may open directory Applications and choose Terminal.app .
2. Once the terminal is opened, you should see a black box and a blinking text cursor, somethine along the lines of `yoric@Blefuscu:~$ _` . Here, `yoric` is my name and `Blefuscu` is the name of the computer I'm using. Depending on your name, the name of the computer you're using and the configuration of your computer, you may see something different. However, you will probably see the `$`.
3. In the terminal, write `cd /tmp` and press <Enter>. If you have unpacked GODI in a directory other than `/tmp`, you should replace with the name of the directory you have chosen.
4. Still in the terminal, write `ls` This should display a list of everything in the directory in which you have unpacked GODI. This may look like `yoric@Blefuscu:/tmp$ ls acroread_1000_1000 gconfd-yoric keyring-2MSlZc orbit-yoric totem.yoric.3483895353 file8eok1j godi-rocketboost-20080630 mapping-yoric plugtmp virtual-yoric.AcfbLs filemjfCnI godi-rocketboost-20080630.tar.gz ocaml797c01pipe ssh-MKJzlx5913`
5. Most files are unimportant for the installation of GODI. The important one is the one whose name starts with `godi` and doesn not end with `.tar.gz`. The exact name will depend on when you read this tutorial, as the numbers at the end represent the day the last version of GODI was published. For the next few steps, we will assume that the name is `godi-rocketboost-20080630`. This is the name of the directory in which you may find the contents of the file you downloaded earlier, by the way.
6. Enter that directory in the terminal, by writing `cd godi-rocketboost-20080630/` and by the way, write `ls` to check that you're in the correct directory. You should see something along the lines of `yoric@Blefuscu:/tmp/godi-rocketboost-20080630$ ls bootstrap bootstrap_stage2 cleanup godi-tools godi-tools-boot README run` The files we're interested in are `bootstrap` and `bootstrap_stage2`, which are both used to pursue the installation of GODI and OCaml.
7. At this point, you'll need to decide which version of OCaml you're interested in and where you want to install GODI. In case of doubt, OCaml 3.11 is a safe bet and directory `~/usr/local` is a nice directory. For the rest of this tutorial, we'll assume that you have chosen these options. Otherwise, write down the name of the directory you have elected, we'll need it later.
8. Start the GODI installer by writing `./bootstrap --section 3.11 --prefix ~/usr/local` You should see something along the lines of `*** Welcome to GODI, the O'Caml source distribution *** RocketBoost bootstrap GODI has been created by Gerd Stolpmann (mailto: gerd@gerd-stolpmann.de), and is derived from the NetBSD pkgsrc system. A number of packaging tools are now compiled and/or installed. Messages are written to bootstrap.log. Configuring make framework: Looking up system commands... /usr/bin/patch works fine /usr/bin/patch can make backups with -V simple -b -z /usr/bin/patch can remove empty files with -E /usr/bin/patch can reject reverse patches with -N /usr/bin/patch can be silent with -s Selected release: 3.11 Installing into: /home/yoric/usr/local Press [Return] to begin with the installation; press [CTRL-C] to abort.`
9. Press <Enter> and wait until this stage of installation is complete. You should see things such as `===> Creating sample godi.conf ===> Building ocamlrun ===> Installing preliminary version of godi_console ===> Installing preliminary version of the make framework (godi-tools) Bootstrap was successful! Please remember to add ~/usr/local/bin and ~/usr/local/sbin to your PATH environment variable. If necessary, please remember to add ~/usr/local/man to your MANPATH environment variable. An example godi.conf file has been created for you in the current directory, and it has been installed in ~/usr/local/etc. Selected GODI section: 3.11 (to change this, edit ~/usr/local/etc/godi.conf) It is now recommended to start bootstrap_stage2 to download and install a minimum set of packages. For more information, see the file README. yoric@Blefuscu:/tmp/godi-rocketboost-20080630$`
10. We will need to follow the above instructions. To do so, we will need to edit the contents of a file and add two lines.
    - Under Linux or BSD, that file is usually called `~/.bashrc`. To edit it, write `gedit ~/.bashrc` or `kwrite ~/.bashrc` (gedit and kwrite are just two text editors, you may use another editor if you prefer). If the file you see in your editor is empty, you have a problem: your configuration has a different name, which I can't guess. You may wish to try `gedit ~/.tcshrc` or `gedit ~/.zshrc` instead. Assuming that the file isn't empty, add the following two lines at the end: `export PATH=~/usr/local/bin:~/usr/local/sbin:$PATH export MANPATH=~/usr/local/man:$MANPATH` You may save the file and quit your text editor. These two lines instructs your computer to look for additional programs in directories `~/usr/local/bin:~/usr/local/sbin` and for additional manual pages inside directory `~/usr/local/man`.
    - Under recent versions of MacOS X, that file is usually called `~/.bashrc`. Under older versions of MacOS X, it was called `~/.tcshrc`. To open this file, write `open -a TextEdit .bashrc` if the file is empty, close TextEdit and try instead `open -a TextEdit .tcshrc` Once you have found the correct file, add the following two lines at the end: `export PATH=~/usr/local/bin:~/usr/local/sbin:$PATH export MANPATH=~/usr/local/man:$MANPATH` You may save the file and quit your text editor. These two lines instructs your computer to look for additional programs in directories `~/usr/local/bin:~/usr/local/sbin` and for additional manual pages inside directory `~/usr/local/man`.
11. We now need to instruct the computer to use these new preferences. To do so, write `~/.bashrc` (if the file isn't called `~/.bashrc`, replace with `~/.tcshrc` or the name of the file).
12. We're now ready to install our first programs using GODI. Actually, our first programs will be the tools required to complete the installation of GODI. To do so, write `./bootstrap_stage2` This will download and install a few OCaml-related programs on your computer. The installation may last 10 minutes or more and present plenty of weird messages, so don't worry -- and take a break.
13. Once this is done, we're finished with GODI. Only a few more steps and we'll be able to use OCaml Batteries Included.

## Ledit and OCaml Batteries Included

1. In a terminal, write `godi_console`
2. This should open the GODI console, i.e. the menu-based installer for OCaml packages. The first menu looks like `+--------------------------------------------+ | GODI Console | +--------------------------------------------+ >>> Main Menu <<< [1] Update the list of available packages [2] Select source packages [3] Exit program`
3. Press <1> to have GODI download the list of available packages. A package is either a complete application, a small tool or a library which may be useful for OCaml programmers. You will need a few such tools and libraries in your career as a OCaml programmer and GODI is the right place to look for them.
4. Once the download is complete, press <x> to exit the download menu and return to the first menu. Now press <2> to enter the package selection menu.
5. The package selection menu looks like `+------------------------------------------------------ GODI Console ------------------------------------------------------+ >>> Select Source Packages <<< FL NAME INSTALLED AVAILABLE COMMENT ==========Packages available as source code:================================================================================ [ 1] apps-aifad 1.0.27 A machine learning tool for structured data. [ 2] apps-alt-ergo 0.8#1 Automated first-order theorem prover [ 3] apps-batteries 0 Batteries Included: standard OCaml development platform. [ 4] apps-bigbro 2.0.4#4 An http link checker. [ 5] apps-camlmix 1.3.0 OCaml-stuffed templates [ 6] apps-cduce 0.5.0#1 XML-oriented functional language [ 7] apps-ceve 1.0.1 Parser for many package formats [ 8] apps-cmigrep 1.2 1.2 module exploration utility [ 9] apps-coq 8.1pl3#1 8.1pl4#2 Interactive proof assistant [ 10] apps-ergo 0.7.3 DEPRECATED: ergo is now called alt-ergo. This package is only here to ease [ 11] apps-felix 1.1.1#1 Felix Compiler [ 12] apps-frama-c 20080701 Modular C static analyser [ 13] apps-godiva 0.9.7 0.9.7 High-level tool for simplifying the creation of GODI packages. [ 14] apps-headache 1.03 Tool for managing headers in source code files [ 15] apps-hevea 1.10 1.10 Latex-to-HTML converter [ 16] apps-ledit 1.16 1.16 Line editor wrapper [ 17] apps-nurpawiki 1.2.2 Wiki + To-Do list [ 18] apps-ocamldsort 0.14.3 Sort OCaml source files according to their dependencies [ 19] apps-ocamlweb 1.36 literate programming tool for Objective Caml [ 20] apps-ocsigen 1.1.0#1 Framework for web programming [ 21] apps-pkglab 1.1 Distribution navigator [ 22] apps-planets 0.1.12 Planet simulation [ 23] apps-tart 1.0.1 Package distributor [ 24] apps-tdir 1.1.1#4 Translation Directory [ 25] apps-umlmon 1.0.5 A system monitor for User Mode Linux [ 26] apps-umlmon-web 1.0.5 A system monitor for User Mode Linux [ 27] apps-unison 2.27.57 File synchronizer [ 28] apps-why 2.14 Verification condition generator for various systems [ 29] apps-wyrd 1.4.1 Curses calendar app [ 30] apps-zenon 0.5.0 "first-order automated theorem prover generating coq output" [ 31] base-curl 7.14.0 The version of CURL for GODI [ 32] base-expat 1.95.7#3 The version of expat for GODI [ 33] base-gdbm 1.8.3#6 The GNU database manager [ 34] base-pcre 7.7#1 The version of PCRE for GODI [ 35] base-plan9-mk 1.6 The make utility from Plan9 [ 36] base-subversion-c$ 1.0.6 The subversion client allows direct access to GODI repositories [ 37] conf-bdb 1 Configures which bdb library to use [ 38] conf-curl 3 Configures which curl library to use ------------------------------------------------------------------------------------------------------------(more)---------- [p]rev [n]ext [u]pgrade all [s]tart/continue installation [h]elp e[x]it menu` As a start, we'll install Ledit, a small tool which is quite useful to program in OCaml. To install Ledit, you need to write the number corresponding to `apps-ledit` and press <Enter> -- on my example, it's 16, but the exact number may depend on which programs are available in GODI when you read this tutorial.
6. New menu: `------------------ GODI Console -------------- >>> Single Package <<< Package: apps-ledit Status: Keep Installed version: 1.16 Available version: 1.16 (from source) Comment: Line editor wrapper Description: Ledit is a line editor, allowing to use control commands like in emacs or in shells (bash, tcsh). To be used with interactive commands. This package is dependent on: - godi-ocaml>=3.10 - godi-camlp5>=5.07 GODI maintainer: Gerd Stolpmann <gerd@gerd-stolpmann.de> ----------------------------------------------- [p]rev [n]ext [b]uild&install [r]emove [t]est configuration [h]elp e[x]it menu` To mark Ledit for installation, press <b>.
7. You may return to the previous menu by pressing <x>
8. You should now start looking for the package containing Batteries Included. It's called `godi-batteries` and it's a few pages further into the list of packages. On my computer, it's numbered 72 but, once again, this may change. To navigate between pages, press <n> (to go to the next page) or <p> (to go to the next page).
9. As with Ledit, enter the description by writing the number of the package, press <b> to mark Batteries for installation and press <x> to return to the previous menu.
10. Press <s> twice to start installation.
11. One last menu before installation actually proceeds: `------------------ GODI Console -------------- >>> Installation <<< GODI is going to - remove 0 package(s) - upgrade 0 package(s) from source - build 10 package(s) from source Press [ok] to execute this plan. Important note: There are packages with configuration options or build messages you might not yet have seen: Package conf-zlib: Options: GODI_ZLIB_INCDIR, GODI_ZLIB_LIBDIR Build message: The Zlib C library (version 1.1.3 or up) needs to be installed. Available options for godi.conf: - GODI_ZLIB_INCDIR: Where zlib.h can be found. Set this option if the installed zlib library is not found. - GODI_ZLIB_LIBDIR: Where libz can be found. Set this option if the installed zlib library is not found. To set options, exit this menu, select the packages in question, and invoke their [c]onfigure menu. ----------------------------------------------- [p]rev [n]ext [o]k [h]elp e[x]it menu` This menu informs you that there are configuration options, which you could customize. Normally, you don't need to.
    Press <o> to really start installation.
12. Go take a coffee. This installation may last half an hour, if not more.
13. Once installation is complete, you have OCaml Batteries Included on your computer. At last.