OCaml Software
Setup

Installing OCaml and Related Tools

We will use opam, OCaml's package manager, to install OCaml as well as various libraries and tools. We recommend (but do not require) the Visual Studio Code editor (referred to as VS Code).

These guides from ocaml.org provide tutorial walk throughs for installing OCaml:

But before working through the general information above, read on for specific instructions we believe will work and suffice for CSE 341 based on our own experience. Please speak up on the discussion board if you run into problems after following these steps carefully, so we can improve these notes.

Here is what we have found to work:

  1. Install opam

Windows (best method)

  • Follow the instructions here to install Windows Subsystem for Linux (WSL). WSL allows Windows developers to run a GNU/Linux environment directly on Windows without the overhead of a traditional virtual machine or dual-booting setup. Install WSL 2 if possible.

  • To install make and cc, run this command:

    • sudo apt install build-essential

  • Follow the Linux instructions for installing opam below.

Windows (old method)

  • Follow the instructions from the OCaml for Windows project's page on installing opam on Windows.

    • The 64-bit graphical installer is probably what you want.

    • If you get a virus-scan failure on the graphical-installer download, try "save link as" from an incognito browser window.

  • After installation completes (it takes a while), open the cygwin shell created in the previous step, called something like cygwin64 Terminal, and proceed to step 2.

    • If you already had cygwin installed, you now have a second one installed. This is no problem, but you will need to keep track of "which is which" and open a terminal for the cygwin you just created here for the instructions that follow and whenever opening vscode.

Linux, MacOS, and Windows Subsystem for Linux (WSL) [WSL install instructions]

  • Follow the instructions on opam's official installation page. Note: For MacOS, you need to have Xcode command line developer tools installed. You can install them using: $ xcode-select --install

  • Note: For WSL, you need to disable sandboxing:

  • $ opam init --disable-sandboxing --reinit

  • You may want to use your OS's package manager to install opam, but you can also directly install the binary distribution.


  • Use opam to install dune, utop, etc.

  • Once opam is installed, install dune and utop by running this command :

  • $ opam install dune utop

  • If you use VS Code (see more below), you will also want ocaml-lsp-server:

$ opam install ocaml-lsp-server

You can learn more about managing your opam installation from the opam usage guide, but you don't need to.

Alternatively, instead of installing everything on your system, you can choose to use attu (remote CSE Linux cluster, available to CSE students only), which has an OCaml installation. From a terminal, run ssh <CSENetID>@attu.cs.washington.edu and use your CSE login as the password. VS Code also has SSH support (instructions below). However, the OCaml version installed by default on attu is outdated, which will be an issue on some assignments. Follow these instructions to install an up-to-date version of OCaml in your attu home directory.

Installing Visual Studio Code (VS Code) and Extension(s)

Install VS Code

The VS Code website provides installers for Windows, Linux, and MacOS.

Note: if you installed OCaml via WSL on Windows, follow the instructions here to develop in WSL using VS Code. This will let you edit files in WSL using VS Code and use the terminal in WSL to use your OCaml installation.

Install the OCaml Extension

VS Code provides many extensions to better support developing programs in various languages.

If you want, you can read the general instructions on how to install an extension, but if you just want to install the extension for OCaml support, you should be able to skip that.

The key thing is to install the OCaml Platform extension by OCaml Labs. You can probably just click the big green Install button.

Opening VS Code -- Crucial Information for Windows Users (Cygwin)

On Mac, Linux, and WSL, you should be able to open VS Code however you want and have the OCaml Extension work correctly with the utop REPL, etc. But on Windows, the bottom of the OCaml "up and running" instructions contain this key information: On Windows, we must launch Visual Studio Code from within the Cygwin window, rather than by clicking on its icon (otherwise, the language server will not be found):

$ /cygdrive/c/Users/Frank\ Smith/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe

In other words, do not launch VS Code like a normal application. Instead, every time you want to launch VS Code open the cygwin terminal and type something like the above, replacing "Frank\ Smith" with your Windows account name on the computer you are using.

However, that can be annoying, so here is a slightly less annoying approach. One time, take these steps:

  • Open a new cygwin terminal window.

  • Type pwd to find the location of your home directory. If it says /home/YourName, then your home directory is probably something like C:\OCaml64\home\YourName. In that directory is a file named .bash_profile (notice the file name starts with a period).

  • Open this .bash_profile file in the text editor of your choice. (You can even use VS Code if you like.) At the bottom of the file, add this, of course replacing YourName with your Windows account name:

alias vscode="/cygdrive/c/Users/Dan\ Grossman/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe"

Now every time you want to open VS Code and use utop within it, you still need to open a cygwin terminal, but now you can just type vscode and hit return.

If using attu

If you chose to use attu, install the Remote-SSH extension to develop on attu within VS Code.


UW CSE VM

The UW CSE Virtual Machine is a CentOS Linux set up to approximate the set up on Allen School lab computers.

Roughly speaking, it will let you run a fresh, full-fledged Linux machine as if it was just another application.

If you are struggling to set up software on your personal computer, you may have better luck by: