Configure VS Code to run OCAML a Mac OSX

August 30, 2020

Let’s get up and running with OCaml and VS Code on a Mac.

Install Brew

If you do not have Brew installed yet, then here is the one-liner you need.

/bin/bash -c "$(curl -fsSL"

Please note that running random code is find on the internet is dangerous, so learn more about installing brew on a mac directly from the

Install OCAML

Using brew, we can now install OCaml

brew install ocaml

Or, if it’s already installed, we can upgrade ot the latest

brew upgrade ocaml

As of this time of writing, we are running The OCaml toplevel, version 4.10.0

ocaml --version

Install OPAM Tools

Now we can install OPAM, the package manager for OCaml

brew install opam
opam init

Merlin provides services such as autocompletion to IDEs such as VSCode.

opam install merlin

Ocp-indent is a tool for auto-formatting OCaml code.

opam install ocp-indent

utop provides a much improved interface to the OCaml REPL

opam install utop

To ensure opam is working as expected, you will want to add the following to you bash profile (many names such as ~/.bash_profile, ~/.bashrc, ~/.bash_aliases)

eval $(opam env)

If you open a new Terminal window, you should be able to run utop

Running utop

Install VS Code

There are many editors out there. I enjoy using Sublime Text with Terminus, but VS Code is a great altnerative as you will see below.

Follow the installation instructions or you can run the script below.

If you don’t have wget, then install it using brew

brew install wget

Now we can install VSCode.

cd /tmp
  wget -O && \
  unzip && \
  mv "Visual Studio" /Applications/ # if this fails, run as `sudo ...`

To be able to run code from Terminal, open up Visual Code.

Open the command palette

And then install the command line tools

Install code on the command line

Integrate OCAML with VS Code

We are going to use the OCaml and Reason IDE extension which can be installed directly from VS Code.

install an extension

And search for OCaml and Reason IDE.

OCaml and Reason IDE extension

If everything ran as expected (which is always does), then you should now have a nice IDE for OCaml within VS Code.

VS Code up and running with OCaml

Happy Coding!