Install OCaml

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

The OCaml compiler and libraries can be installed in several ways. Broadly, the options are:

  • use OPAM, a package manager specific to OCaml
  • use a package manager supported by your platform (Windows, Linux, Mac OS X, ...)
  • install from source code.

The following sections explain how to use each of these methods. For additional information about finding and installing OCaml libraries, see the libraries page. Information about the different versions of OCaml is available on the releases page.

Multi-Platform Package Managers

Some dedicated package managers are available for OCaml, that can be used on multiple platforms:


OPAM is a package manager for OCaml. It is the recommended method to install the OCaml compiler and OCaml packages. The default OPAM repository is actively maintained and serves as the de facto master set of OCaml packages. OPAM also provides features that would be unavailable with the other methods, such as the ability to have multiple versions of OCaml installed at the same time, or have multiple universes of packages for different projects with conflicting package dependencies.

Note that there is a bootstrapping issue, since OPAM is itself implemented in OCaml. To address this, binary OPAM packages are made available on many platforms. See here and below, in the platform specific sections, for installation instructions. Alternatively, you can compile from source by grabbing one of the recent releases. More information is available on the Install pages.

Once you have OPAM installed, the switch and install commands are the ones you're likely to need first. For example:

opam switch 4.02.1
eval `opam config env`

will compile OCaml 4.02.1 and install it in a location managed by OPAM. The second line assures you are now using this version of the compiler. You can skip this step if you're happy with the version of OCaml available on your system , but this lags substantially on many platforms.

Next you can install packages, e.g.

opam install batteries core

will install Batteries and Core, two widely used standard libraries. See the main repository to find hundreds more, and visit OPAM's main page to learn about many additional features.

OPAM is based on the CUDF library developed by the Mancoosi project, which is, among other things, used by Debian to manage their packages. It works well on Unix, Linux, and Mac OS X systems. Windows support is comming soon. OPAM is written and maintained by OCamlPro and OCaml Labs, and is free software (commercial support is available).


See here.


See here.


See here.

Linux Distributions

OCaml is directly available in most Linux distributions, through their package managers. We provide details here for the most popular ones.


OCaml is very easy to install on Debian.

apt-get install ocaml

If you are not going to develop graphical applications, you may want to install ocaml-nox; otherwise install the ocaml package.

We also recommend you to install the following packages:

  • ocaml-native-compilers to be able to compile native binaries (this is not available on some more obscure architectures).
  • ocaml-doc to have the reference manual.
  • tuareg-mode, an Emacs mode for OCaml.
  • ocaml-findlib and oasis to install and use libraries (and their dependencies) easily.
  • libpcre-ocaml-dev which is a binding to PCRE.

Check the packages available in Debian.


Ubuntu is a Debian derivative and uses the same package manager, so Debian instructions are applicable to it too.

You can view the list of OCaml packages in Ubuntu repositories here.

Ubuntu's official repositories often lag substantially behind the latest official releases of OCaml and OPAM. More recent versions are made available by Anil Madhavapeddy in his PPAs. To use, simply add Anil's repository to your apt configuration, update your package lists, and install:

add-apt-repository --yes ppa:avsm/ppa
apt-get update -qq
apt-get install -y opam
eval $(opam config env) which point you should be able to run utop.

Please note PPAs are not reviewed at all by Ubuntu's security team and you are trusting the PPA's distributor by adding them to your system.


Since Fedora 8, Fedora has excellent support for OCaml in the basic distribution. There is an active group of maintainers who keep up to date with the latest OCaml, and there is a wide range of packages available.

To install the OCaml compiler just do:

yum install ocaml

To install an OCaml library called 'foo', and any dependencies it needs, you would do:

yum install ocaml-foo-devel

A good set of basic development libraries can be installed by doing:

yum install ocaml-camlp4-devel ocaml-ocamldoc ocaml-findlib-devel \
   ocaml-extlib-devel ocaml-calendar-devel

To list all OCaml packages use:

yum search ocaml

Packaging policy and mailing lists


In order to get the basic tools under Gentoo, execute:

emerge dev-lang/ocaml

while being logged in as a user that is a member of the portage group (e.g. root). If you want to see what other related packages are available execute

emerge -S ocaml


OCaml can be installed from the repositories on both OpenSuSE and SLES:

zypper install ocaml


Mageia has some support for OCaml in the distribution.

To install the OCaml compilers just do:

urpmi ocaml-compiler

ocaml-compiler has no dependency on X11 libs, to install the libs that have some (for example the module Graphics):

urpmi ocaml-x11

To install camlp4:

urpmi camlp4

To install an OCaml library called 'foo', and any dependencies it needs, you would do:

urpmi ocaml-foo-devel

A good set of basic development libraries can be installed by doing:

urpmi camlp4-devel ocaml-doc ocaml-findlib-devel \
  ocaml-extlib-devel ocaml-extlib-doc ocaml-batteries-devel \
  ocaml-ounit-devel ocaml-sexplib-devel ocaml-xml-light-devel \

To list OCaml packages, use:

urpmq --list | grep ocaml

Packaging policy

  • OCaml packaging policy in Mageia. All Mageia OCaml packages have to obey this policy, ensuring a minimum standard for all OCaml packages we ship.


Under Windows, two solutions are available to use OCaml: the official OCaml distribution, and OCamlPro's OCPWin.

Several ports of OCaml for Microsoft Windows are currently available. For additional information, please consult the list of portability issues or the Windows release notes.

Official OCaml distribution

  • Official OCaml distribution. A self installer with a preliminary version of OPAM for Windows. The OCaml binaries are true Windows executables (don't depend on Cygwin), and generate true Windows executables too (via the mingw64-x86_64 toolchain). However, the installer encourages you to install Cygwin, as it provides an easy way to get packages for the C compiler / assembler. Furthermore, it's a good idea to have cygwin installed, since pretty much every OCaml package depends on sed/bash/make for the build. Finally, the OPAM version bundled in the installer supports system dependencies via cygwinports (see webpage for details) so that you can do opam install depext depext-cygwinports && opam depext sqlite3 && opam install sqlite3.

  • Microsoft-based native Win32 ports. No binary distributions available yet; download the source distribution and compile it. Build instructions including required tools (Cygwin required) and download links in the source distribution (README.win32).

    • Configurations supported include 32-bit/64-bit;

    • Microsoft toolset support provided by Windows 7 SDK;

    • Tested with XP/Windows 7/Windows 8.1.

    • On Windows 8.1

    • Cygwin chmod 0600 appears broken : comment L367 of Makefile.nt (@chmod -w utils/;

    +             This same problem with Cygwin chmod also affects ssh

configuration setup (may affect interaction with github projects). See this page for a suggested workaround.

  • Cygwin-based port. Requires Cygwin. No graphical user interface is provided. The compilers generate executables that do require Cygwin (cygwin1.dll). The precompiled binaries are part of the Cygwin distribution; you can install them using the Cygwin setup tool. Alternatively, download the source distribution and compile it under Cygwin.

To install libraries, you may use Wodi or OPAM.

OCPWIN, Self-Contained OCaml for Windows

OCPWin is a self-contained binary distribution of OCaml for Windows. It supports both 32-bit and 64-bit Windows platforms, and can compile both bytecode and native code applications, directly from a Windows terminal, without installing other software. The license agreement allows both commercial and non-commercial use, as long as the compiler parts themselves are not redistributed. Graphical binary installers and zip archives are provided for OCaml 4.01.0 and 4.02.1. 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).

Mac OS X

On Mac OS X, there are, at least for the base package, a few different ways to go: Install Homebrew package management system and use OPAM (recommeneded); Install via Fink; Install via MacPorts; or build it manually from sources. For each of these approaches, you will need to have at least the OS X developer tools installed — any other requirements will be discussed below.

Inria's binary package

Inria stopped supporting MacOS binaries for OCaml 4.02.X. For earlier versions of OCaml Intel disk image images follow the download link.

The package only includes command-line tools and does not include any graphical applications.


Homebrew is a new and upcoming package management system for Mac OS X and has a very large community. Homebrew requires the command line tools for Xcode and either bash or zsh to install.

After installing Homebrew, you can install OCaml by issuing the following command:

brew install ocaml

You can then install OPAM, the OCaml package manager, which will give you access to all its packages by running:

brew install opam


Fink is the most prevalent package management system for OS X, and is based on Debian's package management system. Fink can be installed by downloading and building the source release (you will need to have the OS X Developer Tools installed before building Fink). After Fink is installed, it must be configured to use the unstable branch of the distribution tree -- this is where the OCaml packages reside.

Once Fink is installed, you can use it to install the following packages:

  • ocaml The basic installation of the ocaml tools including labltk.
  • lablgl The OCaml interface to OpenGL
  • lablgtk The OCaml interface to gtk+
  • ledit An optional line editor for OCaml to make it easier to work with the interactive toplevel in the terminal.

It is likely that Fink will need to download and install a number of other packages required to build the OCaml packages, but this will occur mostly automatically.


MacPorts, formerly known as DarwinPorts, is a package management system for Mac OS X based on the BSD ports system. You will need to have the OS X Developer Tools installed before installing MacPorts. MacPorts can be used to download and build the following packages:

  • ocaml The basic installation of the ocaml tools including labltk.
  • lablgl The OCaml interface to OpenGL
  • lablgtk The OCaml interface to gtk+
  • lablgtk2 The OCaml interface to gtk+ 2.x
  • cryptokit An OCaml interface to several cryptographic functions.
  • ocaml-mode.el An EMACS major mode for editing OCaml programs.
  • tuareg-mode.el A GNU Emacs/XEmacs major mode for editing OCaml programs.

Building from sources

Unfortunately, the packages available for both Fink and DarwinPorts don't yet include some of the more useful additions to the OCaml collection, such as Markus Mottl's PCRE-Ocaml library or Stolpmann's findlib system. In order to get those packages, one must currently build them from source.

The following packages are the most beneficial to install:

If additional components, such as OpenGL and Gtk+ or Gtk+2 have already been installed, packages such as lablgl, lablgtk, etc. can be built as well. The most flexible solution for doing this is often using Fink to install the required dependencies, and build the OCaml packages from source distributions.

Using labltk with OS X

There are a couple of different ways one can go if they wish to use labltk with OS X. One could download and build the Tcl/Tk libraries themselves and use those libraries. However, there are two easier ways to proceed, using Fink to install Tcl/Tk, or using the Tcl/Tk Aqua Framework. There are two very important distinction between the two that one needs to consider before installing OCaml and labltk:

  1. The fink libraries require X11 to be running when any program using labltk is executed, while the Tcl/Tk Aqua libraries will execute (and look and feel) like a native OS X application
  2. As of the time of writing this, it appears as if labltk applications built with the Tcl/Tk Aqua libraries must be built as native OS X applications (and require an extra step at build time). If one requires the portability of bytecode, or needs the interactive environment of a labltk enabled toplevel, then they must use the fink libraries.

Installing the fink libraries

Once Fink is installed and configured, install the Tcl/Tk libraries with the command fink install tcltk tcltk-dev tcltk-shlibs and wait for the build and install process to compete. Once this is done, OCaml's configure script should be able to locate the libraries and header files required to build labltk (provided fink is set up to install its packages in the /sw directory). Running the standard OCaml build will also build labltk.

Installing the Tcl/Tk Aqua libraries

This framework comes with OS X 10.4 and later. Configure the OCaml build by using the following flags:

./configure -tkdefs \
  "-I/Library/Frameworks/Tcl.framework/Headers \
  -I/Library/Frameworks/Tk.framework/Headers" \
  -tklibs "-framework Tcl -framework Tk"

Now building OCaml will also build labltk using the Tcl/Tk Aqua libraries.

As mentioned above, any programs using labltk must be compiled using ocamlopt, and an additional step must be performed before the application can be used. For example, with the simple program,

open Tk;;
let hello () = print_endline "Hello!"; flush stdout in let top = openTk () in let hb = Button.create ~text:"Hello" ~command:hello top in pack [hb]; mainLoop ()

One would compile this program with the command ocamlopt -o hello -I +labltk labltk.cmxa

Now, to make the program work properly, one must perform one of two additional steps: adding a resource fork to the executable, or building a Mac OS X .app structure.

To add a resource fork, one needs to use the program Rez, included in the OS X Developer tools. This can be done with the following command:

/Developer/Tools/Rez -t APPL -o hello ~/dev/mac.r \
  -i /Library/Frameworks/Tcl.framework/Headers \
  -i /Library/Frameworks/Tk.framework/Headers

Where mac.r is a Rez source file. It is part of the FLTK distribution. This will add the required resource fork to the hello application. The program can be run either by typing hello at the command line or by double-clicking the app's icon (note that if it is launched by double-clicking, hello will send its output to the OS X console rather than the terminal).

Unfortunately, files with resource forks can present a problem in that utilities like cp, mv, tar, etc. will strip the resource fork from the file, breaking the application. To aleviate this problem, one can build an OS X application bundle to wrap the compiled executable.

To do this, after compiling with ocamlopt -o hello -I +labltk labltk.cmxa, the following steps will build the bundle:

mv hello

Next, create a file with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">

The hello application can now be run from the command line by typing open, or by double-clicking on the app's icon (again, this will send's output to the console).


Documentation. To get quick access to the documentation of a module (whatever the editor you use), use Quicksilver to index the libref/ directory of ocaml's documentation. Since ocamldoc generates the documentation of a module M in a file M.html, you can access it by invoking Quicksilver, type an abbreviation of the module's name you want and hit return to get its html file loaded in your preferred browser.

Profiling. To profile native-code programs do not compile them with the option -p (this is unsupported). Instruments is included with XCode, but not in the Command Line Tools. Start it with the Time Profiler template and then run the native code ocaml executable. Alternatively, iprofiler is a command line interface to it.

OCaml builtins will show up in cleartext but user-defined functions will be replaced by autogenerated symbols. In principle, more function names should show up in the profiles if you compile with -g, but this does not seem to work. Therefore, time profiling on OS X is currently of limited use.


FreeBSD had a great support for OCaml development for a long time. There are easy to use packages available for most popular platforms (i386, amd64, powerpc, sparc64) for both the core languages and supplimentary libraries, documentation, examples and development tools. There is a framework available to make adding new ocaml application and libraries easy.

To install the OCaml compiler from packages, do:

pkg_add -r ocaml


pkg_add -r ocaml-nox11

to install OCaml without X11-dependent libraries (e.g. to deploy on a headless server).

To install the developer documentation, examples and emacs editing macros use the ocaml-doc, ocaml-examples and ocaml-mode.el packages.

The same packages can be installed via the port system. There is a large set of libraries available in the devel category of the ports system as well as in the specific topic-related categories.

From Source

Download the source for your preferred OCaml release (or take the development version using Subversion or Git) and follow the instructions included therein.