Skip to content

Setting up OCaml

Here is a quick overview of how to set up OCaml. In general, the best course of action is to follow the official installation instructions, here. You can also find alternative instructions, here.

In brief, perform the following steps:

For Mac and Linux

  1. Run bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)" in a terminal. Press enter when it asks you where to install it, and enter your password when it asks you to.
  2. Run opam init; when it asks you how to modify zsh, just press enter.
  3. Run opam install ocaml-lsp-server odoc ocamlformat utop. If it says that no switch exists, first run opam switch create cs2800 ocaml-base-compiler.5.3.0.
  4. Try running utop. If that doesn't work, try first running eval $(opam env). If it works after running eval $(opam env), run this command so that you don't have to again: echo 'eval $(opam env)' >> ~/.zshrc.
  5. (Recommended) Install VSCode, search for "OCaml", and install the official OCaml Platform extension.

For Windows

  1. Install Windows Subsystem for Linux. Open Powershell in administrator mode (right-click on PowerShell and select "Run and administrator"). Then, enter the following command: wsl --install
  2. Once WSL finishes installing, you can open an Ubuntu terminal via the Start menu.
  3. Then, follow the instructions for Mac/Linux above.