UbuntuにOCamlをインストールする

Ubuntu15.04にOCamlをインストールする

**1.OPAMのインストール**

```
$ apt-cache search opam
opam - package manager for OCaml
opam-docs - package manager for OCaml (documentation)
$ sudo apt-get install opam
以下の追加パッケージがインストールされます:
  aspcud camlp4 clasp gringo ledit ocaml ocaml-base ocaml-base-nox
  ocaml-compiler-libs ocaml-interp ocaml-nox opam-docs
提案パッケージ:
  tcl-dev tk-dev ocaml-doc tuareg-mode ocaml-mode
以下のパッケージが新たにインストールされます:
  aspcud camlp4 clasp gringo ledit ocaml ocaml-base ocaml-base-nox
  ocaml-compiler-libs ocaml-interp ocaml-nox opam opam-docs
アップグレード: 0 個、新規インストール: 13 個、削除: 0 個、保留: 0 個。
19.9 MB のアーカイブを取得する必要があります。
この操作後に追加で 140 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
```

**2.初期設定**

```
$ opam init
Checking for available remotes: rsync and local, git.
[NOTE] hg not found, you won't be able to use mercurial repositories unless you install it.
[NOTE] darcs not found, you won't be able to use darcs repositories unless you install it.
[default] Downloading https://opam.ocaml.org/urls.txt
[default] Downloading https://opam.ocaml.org/index.tar.gz
Updating ~/.opam/repo/compiler-index ...
Updating ~/.opam/compilers/ ...
Updating ~/.opam/repo/package-index ...
Updating ~/.opam/packages/ ...
The following actions will be performed:
 - install   base-unix.base
 - install   base-bigarray.base
 - install   base-threads.base
=== 3 to install ===

=-=- Synchronizing package archives -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

=-=- Installing packages =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Installing base-bigarray.base.
Installing base-threads.base.
Installing base-unix.base.

In normal operation, OPAM only alters files within ~/.opam.

During this initialisation, you can allow OPAM to add information to two
other files for best results. You can also make these additions manually
if you wish.

If you agree, OPAM will modify:

  - ~/.bashrc (or a file you specify) to set the right environment
    variables and to load the auto-completion scripts for your shell (bash)
    on startup. Specifically, it checks for and appends the following line:

    . /home/kenji/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true


  - ~/.ocamlinit to ensure that non-system installations of `ocamlfind`
    (i.e. those installed by OPAM) will work correctly when running the
    OCaml toplevel. It does this by adding $OCAML_TOPLEVEL_PATH to the list
    of include directories.

If you choose to not configure your system now, you can either configure
OPAM manually (instructions will be displayed) or launch the automatic setup
later by running:

   opam config setup -a


Do you want OPAM to modify ~/.bashrc and ~/.ocamlinit?
(default is 'no', use 'f' to name a file other than ~/.bashrc)
    [N/y/f] y

User configuration:
  Generating ~/.ocamlinit.
  Updating ~/.bashrc.
Global configuration:
  Updating ~/.opam/opam-init/init.sh
    auto-completion : [true]
    opam-switch-eval: [true]
  Updating ~/.opam/opam-init/init.zsh
    auto-completion : [true]
    opam-switch-eval: [true]
  Updating ~/.opam/opam-init/init.csh
    auto-completion : [true]
    opam-switch-eval: [true]
  Updating ~/.opam/opam-init/init.fish
    auto-completion : [true]
    opam-switch-eval: [true]
\# To setup the new switch in the current shell, you need to run:
eval \`opam config env\`
$ eval \`opam config env\`
```

**3.違うバージョンをインストール**

```
$ opam switch list
system  C system  System compiler (4.01.0)
--     -- 3.11.2  Official 3.11.2 release
--     -- 3.12.1  Official 3.12.1 release
--     -- 4.00.0  Official 4.00.0 release
--     -- 4.00.1  Official 4.00.1 release
--     -- 4.01.0  Official 4.01.0 release
--     -- 4.02.0  Official 4.02.0 release
--     -- 4.02.1  Official 4.02.1 release
# 100 more patched or experimental compilers, use '--all' to show
```




```
$ opam switch 4.02.1
[compiler.get] Downloading http://caml.inria.fr/pub/distrib/ocaml-4.02/ocaml-4.02.1.tar.gz
Now compiling OCaml. This may take a while, please bear with us...
Done.
# To setup the new switch in the current shell, you need to run:
eval `opam config env`
The following actions will be performed:
 - install   base-unix.base
 - install   base-bigarray.base
 - install   base-threads.base
=== 3 to install ===

=-=- Synchronizing package archives -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

=-=- Installing packages =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Installing base-bigarray.base.
Installing base-threads.base.
Installing base-unix.base.
$ eval `opam config env`
```

```
$ ocaml -version
The OCaml toplevel, version 4.02.1
```

**4.日本語の設定**
~/.ocamlinitに以下を記述

```~/.ocamlinit
let printer ppf = Format.fprintf ppf "\"%s\"";;
#install_printer printer
```

```
$ ocaml
        OCaml version 4.02.1

# "あ";;
- : string = "あ"
```

とりあえず今日はここまで。

**5.OCamlのバージョンをあげる**

```
$ opam update; opam upgrade
$ opam switch list
system  I system  System compiler (4.01.0)
4.02.1  C 4.02.1  Official 4.02.1 release
--     -- 3.11.2  Official 3.11.2 release
--     -- 3.12.1  Official 3.12.1 release
--     -- 4.00.0  Official 4.00.0 release
--     -- 4.00.1  Official 4.00.1 release
--     -- 4.01.0  Official 4.01.0 release
--     -- 4.02.0  Official 4.02.0 release
--     -- 4.02.2  Official 4.02.2 release
--     -- 4.02.3  Official 4.02.3 release
$ opam switch 4.02.3
$ eval `opam config env`
$ ocaml -version 
The OCaml toplevel, version 4.02.3