OCAML Course

Installing OCaml on Windows

Go back

This page is quite long, as I had a hard time, and as they were a lot of tutorials that finally worked for me, yet none of them were enough so that I could fully enjoy OCaml in my editor (so I'm making my own plugin for IntelliJ πŸš€).

You can use a WSL
πŸ‘: easy, you got a graphical version for emacs, sublime text, IntelliJ, etc.
πŸ‘Ž: not beautiful, a bit blurry

This is Linux on Windows. Here is the tutorial to install a WSL. Then you can install OCaml like you would on Linux.

sudo apt-get update && sudo apt-get install ocaml
# editor: sublime text
sudo apt-get install sublime-text
subl -c
# editor: emacs
sudo apt-get install emacs
emacs -c
# editor: IntelliJ
# ... get the tar.gz on their Website, tar xvf idea.tar.gz
# inside the bin folder, run the .sh
./idea.sh -c

But this won't work. You need to install XMing, and XMing fonts first (links in "public domain"). Then, every time you need to use -c (graphical version), start XMing.

OCaml from "sources"
πŸ‘: easy, VSCode+tuareg
πŸ‘Ž: you need someone to zip their working OCaml for you

The original tutorial is made by my teacher is here, but just in case, here is a copy.

  1. Download the zip for ocaml 4.08
  2. extract in C:/,
  3. open a terminal
  4. write C:\ocaml\bin\ocamlc.exe -v (expected: ocaml version)
  5. write PATH in the Windows search bar (bottom left)
  6. "edit environment variables" then "Environment variables" button
  7. In the first panel, click on Path then modify (right below)
  8. add this entry: C:\ocaml\bin\
  9. open a new terminal and write ocamlc -v
  10. same output as 4.

Then you can use it in any terminal, like in VSCode, using the tuareg mode plugin (as my teacher is explaining).

OCaml in IntelliJ (WSL)
πŸ‘: easy setup
πŸ‘Ž: no tuareg mode, the plugin do not have many features.

You can install OCaml plugin on IntelliJ, and compile using a WSL.

Install a WSL

This is the official tutorial to install a WSL, but if this looks complicated to you, here is what I did

  • open the Windows Store
  • enter "Debian" (or "Ubuntu")
  • install it
  • start it, once the initialization is done, you are good

To compile, simply click on "Terminal" (the Bar at the bottom, with Git/TODO/...). Click on the small caret-down icon and select Debian. Then, simply write your commands πŸš€.

# install OCaml, once
$ sudo apt-get install ocaml
# check installed
$ ocaml --version
# compile
$ ocamlc src/hello_word.ml 
# run
$ ./a.out
Hello, World!
OCaml in IntelliJ (Cygwin)
πŸ‘: easy setup, Makefile
πŸ‘Ž: same as WSL

Download Cygwin.

  • Next
  • Install from the internet, Next
  • Next, Next, Next
  • Pick a link in the list, Next
  • In view, select full

Now, you have to pick the commands you want, which means replacing "Skip" (in the column "New") with a version of the command. You should use the search bar. I picked make, ocaml, opam (not required), vim (just in case), wget and curl. If you are planning to use opam, add libclang and mingw[...]clang.

  • Then process with the installation

Now, you should open a new terminal on Windows (ex: Powershell, cmd, ...) and write a command

$ make -v
# GNU Make 4.3
# ...

You may have to restart your IDE (if you are using one), or your computer. If this is still not working, check that C:/cygwin64/bin is in the PATH.

Now you can write a Makefile in IntelliJ, and compile using Make.

OCaml in IntelliJ (tricks, node.js)
πŸ‘ and πŸ‘Ž: see the README.md

The tutorial for OCaml in IntelliJ/PHPStorm/... is here.

The unmentioned

Every setup before was easy, because I removed any setup complicated. But, if you want more, you need to dig more into it.

Do not look for the ghosts

They are still in the official documentation (or in some online tutorials), but they disappeared πŸ‘».

  • WinCaml: dead, the links are directing to the discontinued installer of the previous section
  • OCPWin: it disappeared