Caml
Power

Opam Installation

You do not need to follow these instructions if you are using the VM. We have already done them for you.

For Linux users, It’s best to use your distribution’s package manager to install OPAM. The OPAM installation page has detailed instructions for many popular package managers. Continue with the instructions under below.

  • Check your OPAM version by running opam --version. That ought to report that you have OPAM version 2, e.g., 2.0.5. If you instead have version 1, e.g., 1.2.2, you have to fix that before proceeding. Follow the instructions under “Need help?” below.
  • If you have ever had OPAM installed before this semester, we highly recommend that you start fresh instead of trying to upgrade an earlier install. To start fresh, all you have to do is delete the directory ~/.opam, or, move it to a different location—e.g., mv ~/.opam ~/.opam.bak.
  • This step varies depending on whether you are running on Windows, or on OS X or Linux.
  • On Windows (WSL), run the following command to initialize OPAM:

    # Note: do NOT prefix this command with sudo

    opam init --bare -a -y --disable-sandboxing
    
  • (We have to disable sandboxing because of an open OPAM issue related to WSL. Hopefully that will be fixed in the future.)
  • On OS X or Linux, run this command:

    # Note: do NOT prefix this command with sudo

    opam init --bare -a -y
    
  • Enter the following commands to switch OPAM to the OCaml 4.09.0 compiler:

    # Note: do NOT prefix these commands with sudo

    opam switch create 4.09.0 ocaml-base-compiler.4.09.0
    eval $(opam env)
    

    If you get an error about 4.09.0 not being a known compiler version, try running opam update.

  • Now check your compiler version by running opam switch show. If that reports anything other than 4.09.0, then something has gone wrong; follow the instructions under “Need help?” below. Be aware that OCaml version 4.09 is the only supported version of the OCaml compiler in CS 326 this semester. All your code must compile under that version.
  • Enter the following commands to install some OPAM packages that will be needed for CS 326. Make sure to grab the entirety of the first line, which is quite long.

    # Note: do NOT prefix these commands with sudo

    opam install -y utop ocamlbuild ounit qtest merlin tuareg ocp-indent menhir ansiterminal
    
  • Close the terminal you were in. Open a new terminal. Check that you can run OCaml:
    • Type utop to launch the OCaml toplevel.
    • Type 326;; followed by the Enter key to evaluate the integer 326.
    • Stop to appreciate how good an integer 326 is.
    • Type #quit;; or Control-D to exit the toplevel.

Continue by installing a text editor for OCaml programs using these instructions.