Install OCaml
Install OCaml on Linux, macOS, or *BSD
-
Install the
opam
package managerOCaml's package manager opam installs both the compiler, as well as any additional packages. Ensure
gcc
,build-essential
,curl
,unzip
, andbubblewrap
are installed on your system, then run the following in your terminal to download and install the newest version ofopam
:Other installation methods
You can also install opam using your operating system's package manager - however, you may get an older version ofopam
that does not support the most recent OCaml compiler version. If you need the most recent version, you can buildopam
from sources, following the instructions at opam's GitHub repository. -
Initialise
opam
opam
needs to be initialised, which will create a default opam switch. Anopam
switch is an isolated environment for the OCaml compiler and any packages you install.During
opam init
, you will be asked if you want to add a hook to your shell to put the tools available in the currentopam
switch on your PATH. If you answer no, you will need to activate theopam
switch by runningeval $(opam env)
.
Congratulations, you have now installed OCaml!
Set Up an OCaml Development Environment
The OCaml Platform Tools,
which include the build system dune,
complete your OCaml development environment. To install them in your current opam
switch, run this command:
Now you are ready to write some OCaml code!
If the instructions on this page did not work for you, or you want to know more, you can find a more detailed explanation of the installation process here.
Install OCaml on Windows
-
Use the Diskuv OCaml ("DKML") Windows installer
The installer sets up OCaml 4.14.0 and OCaml's package manager opam, with Git and the Visual Studio compiler. If you need a different OCaml version, check out the alternative installation instructions provided in the "OCaml on Windows" guide.
Download DKML InstallerBefore you run the installer: Make sure your Windows username does not contain a space character (e.g. for
C:\Users\Jane Smith
, OCaml will not install properly).
Congratulations, you have now installed OCaml as well as the OCaml Platform Tools!
The OCaml Platform Tools include the build system dune, and provide you with a complete OCaml development environment.
Now you are ready to write some OCaml code!
If the instructions on this page did not work for you, or you want to know more, you can find a more detailed explanation of the installation process here.