We all have our own constraints when it comes to development tooling, so we compromise.
In my case, I like Linux and Mac OS, but I often have to work on Windows.
It’s no secret that Windows sucks for development, specially for modern web development.
Windows Subsystem for Linux (WSL) helps a lot, but it has its limits.
OCaml is no exception on Windows sucking for development, the installation build breaks even on WSL, that’s what we’ll fix today.
Down to it!
OCaml in WSL
Get the Ubuntu WSL from the Microsoft Store
Excuse my French!
Launch it, it should ask you for some stuff like a username and password
Now in the Linux shell, let’s install some dependencies
$ sudo apt-get install curl build-essential m4 zlib1g-dev libssl-dev bubblewrap
- Let’s install opam, the OCaml version and package manager. It exists in the default Ubuntu package repositories, but it’s an old version, so we’ll get it from the installation script better.
$ sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)
- Initialize opam
$opam init --disable-sandboxing
- Find the Latest Release Version Try
opam switch list-available
The latest stable version is the latest release without a
- Install the Latest OCaml
$ opam switch create 4.10.0 --jobs=1
We’re purposedly not using concurrent jobs because it breaks on WSL.
- This is it!
$ opam switch # switch compiler description → 4.10.0 ocaml-base-compiler.4.10.0 4.10.0
Visual Studio Code … Not much way around this… Thankfully it’s a pretty good editor, in this case, there’s a WSL plugin that uses a VSCode server in WSL so you can edit your files from Windows.
You can download the editor from here.
Install the Remote - WSL Plugin
Open Your Project Directory Now, from any directory in the WSL shell, you should be able to run the
codecommand, and it will open VSCode in Windows on this directory/file.