Install OCaml

The latest version of OCaml is 4.10.0. For more information about this release, see the 4.10.0 page.

The OCaml compiler and libraries can be installed in several ways:

For finding and installing OCaml libraries, see the libraries page. Information about the different versions of OCaml is available on the releases page.

OPAM

OPAM is the package manager for OCaml. It is the recommended way to install the OCaml compiler and OCaml packages. Simply follow the OPAM install instructions.

Then, use opam to install an ocaml compiler. Example using the Bash shell and opam-2.0:

# environment setup
opam init
eval `opam env`
# install given version of the compiler
opam switch create 4.10.0
eval `opam env`
# check you got what you want
which ocaml
ocaml -version

Linux

Most Linux distributions allow OCaml and/or OPAM to be installed directly through the system package manager.

Debian Debian Unstable

apt install ocaml-nox # If you don't want X11 support
apt install ocaml

Other Debian packages related to OCaml are listed here. They are made available through The Debian OCaml Packaging Policy.

Ubuntu Ubuntu 19.10

apt install ocaml-nox # If you don't want X11 support.
apt install ocaml

Other Ubuntu packages related to OCaml are listed here.

Fedora Fedora 31

dnf install ocaml
dnf search ocaml   # List packages related to OCaml

OCaml packages are packaged according to this policy. There is an OCaml Special Interest Group and a mailing list for people interested in OCaml on Fedora or Red Hat Enterprise Linux.

Centos / Red Hat Enterprise Linux CentOS 8

yum install ocaml
yum search ocaml   # List packages related to OCaml

Gentoo Gentoo

With a user that is a member of the portage group do:

emerge dev-lang/ocaml
emerge -S ocaml # List packages related to OCaml

SuSE OpenSUSE

zypper install ocaml

Mageia Mageia Cauldron

urpmi ocaml-compiler
urpmi ocaml-x11           # To install X11 support
urpmq --list | grep ocaml # List OCaml packages

The Mageia OCaml packaging policy.

Arch Linux Arch Linux

pacman -S ocaml

Other Arch Linux packages related to OCaml are listed here.

macOS

On macOS OCaml and/or OPAM can be installed via the existing third-party package systems.

Homebrew Homebrew

brew install ocaml
brew install opam

Fink

apt install ocaml

MacPorts MacPorts

port install ocaml
port install opam

FreeBSD FreeBSD port

pkg install ocaml-nox11 # If you don't want X11 support
pkg install ocaml
pkg install ocaml-opam

OpenBSD OpenBSD port

pkg_add ocaml
pkg_add opam

NetBSD NetBSD port

pkg_add ocaml
pkg_add opam

Windows

Under Windows, the following direct solutions are available to use OCaml:

  • OCaml for Windows provides an experimental OPAM repository and opam build for Windows.

  • OCPWin is a self-contained binary distribution of OCaml for Windows. Some additional features have been added to OCaml for better support of Windows, such as auto-detection of MSVC and support for MSVC 9.0, 10.0, 11.0, 12.0 and 14.0 (VS2015).

Here are a few other alternatives:

  • The OCaml source distribution directly supports many different Windows ports. You will have to compile from source. See the README.win32 file included in the distribution for details.

  • Use « Bash on Windows » and install OCaml as on Ubuntu. Main OCaml versions and OPAM work. The disadvantage of this method is that you don't build native Windows binaries but Linux binaries. See tutorial.

  • Cygwin-based port. Requires Cygwin, you can install them using the setup tool. The compilers generate executables that do require Cygwin (cygwin1.dll).

Browser

The following pages allow to directly try snippets of OCaml in your browser:

From Source

Download an OCaml release or the development version and follow the instructions included therein.

Available versions

Here is the list of available versions across different Linux and UNIX distributions:

Packaging status