Install OCaml
If you need more explicit instructions than provided on this quick-install page, you can find a more detailed explanation of the installation process here.
Install OCaml on Linux, macOS, or *BSD
-
Install the opam package manager
OCaml'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 of opam:Other installation methods
You can also install opam using your operating system's package manager - however, you may get an older version of opam that does not support the most recent OCaml compiler version. If you need the most recent version, you can build opam from sources, following the instructions at opam's GitHub repository. -
Initialise opam
Opam needs to be initialised, which will create a default opam switch. An opam 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 current opam switch on your PATH. -
Activate the opam switch
If you answered no when prompted in the previous step, you need to activate the opam switch by running
eval $(opam env)
or explicitly execute commands within the switch by usingopam exec -- [CMD]
.
Congratulations, you have now installed OCaml!
Set Up an OCaml Development Environment
The OCaml Platform Tools, which includes 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!
Install OCaml on Windows
-
Install the opam package manager
OCaml's package manager, opam, supports Windows natively since version 2.2.0 and is the recommended way to install OCaml on Windows. If you are looking for a different installation method, check out the alternative installation instructions provided in the "OCaml on Windows" guide.
Run the following in a terminal (either Windows PowerShell or Command Prompt):
-
Initialise opam
Now, we are ready to initialise opam, which will create a default opam switch. An opam switch is an isolated environment for the OCaml compiler and any packages you install.
During
opam init
, you will be asked about Unix support infrastructure. You can select option 1 to let opam manage it for you. For details of more advanced alternatives, see the opam blog. -
Activate the opam switch
You need to activate the opam switch by running on cmd
Congratulations, you have now installed OCaml!!
Set Up an OCaml Development Environment
The OCaml Platform Tools, which includes 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!