Let’s get up and running with OCaml and VS Code on a Mac.
If you do not have Brew installed yet, then here is the one-liner you need.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
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 brew.sh.
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
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
eval $(opam env)
If you open a new
Terminal window, you should be able to run
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 https://go.microsoft.com/fwlink/?LinkID=620882 -O VSCode-darwin-stable.zip && \ unzip VSCode-darwin-stable.zip && \ mv "Visual Studio Code.app" /Applications/ # if this fails, run as `sudo ...`
To be able to run
code from Terminal, open up Visual Code.
And then install the command line tools
We are going to use the OCaml and Reason IDE extension which can be installed directly from VS Code.
And search for
OCaml and Reason IDE.
If everything ran as expected (which is always does), then you should now have a nice IDE for OCaml within VS Code.