How to install opam

This page describes how to install and configure opam. For further help on how to use opam, either read opam --help or move on to the Usage guide.

Upgrading from a previous version

Generally, you should just reproduce the same installation steps as for the original installation: upgrade from your system's package manager, or re-run the binary installer. Opam will automatically update its internal repository at ~/.opam on first run if needed (if using our installer script, a backup can be made automatically).

To upgrade shell scripts, and enable sandboxing, don't forget to run opam init --reinit -ni.

Then see the Upgrade guide to check the changes.

Binary distribution

The quickest way to get the latest opam up and working is to run this script:

sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)

This will simply check your architecture, download and install the proper pre-compiled binary, backup your opam data if from an older version, and run opam init.

(If you have trouble with curl, just download the script and run sh install.sh)

We provide pre-compiled binaries for:

  • Linux i686, amd64, arm7, arm64
  • OSX (intel 64 bits) (other platforms are available using the other methods below)

If you don't like scripts, you can just pick your download here, put it in your PATH as opam, and set it as executable, e.g.

sudo cp <downloaded file> /usr/local/bin/opam
sudo chmod a+x /usr/local/bin/opam

Note that this script is intended for end-users, not CI. For that purpose, you can use pre-built Docker images for various configurations.

Using your distribution's package system

This is generally the recommended way, when available and up-to-date (you can check here the latest available release per distribution). Here is a list of supported distributions:

Archlinux

The opam package is available in the official distribution. To install it simply run:

pacman -S opam

If you'd like to use the development version there is an opam-git package available in the AUR. Assuming you have yaourt installed just run the following command:

yaourt -S opam-git

Debian

Binary packages of opam are available for the stable, testing and unstable distributions, from the official repositories. You should be set with:

apt-get install opam

Exherbo

The dev-ocaml/opam package can be installed with the command:

cave resolve -x dev-ocaml/opam

You might need to add the ::ocaml-unofficial repository first:

cave resolve -x repository/ocaml-unofficial

Fedora, CentOS and RHEL

The opam package for Fedora can be installed with the command:

dnf install opam

There is not currently a package for CentOS/RHEL. You will need to use our pre-built binaries, or build from sources.

Mageia

The opam package for Mageia can be installed with the command:

urpmi opam

OpenBSD

Opam builds via sources fine on OpenBSD 5.6 or earlier, and is available in the ports and packages tree on OpenBSD 5.7 or higher.

cd /usr/ports/sysutils/opam
make install

FreeBSD

Opam is available in the ports and packages tree on FreeBSD 11 or higher.

cd /usr/ports/devel/ocaml-opam
make install

OSX

Opam packages for homebrew and MacPorts are available. homebrew need a prior installation of gpatch, as opam uses gnu-specific options.

# Homebrew
brew install gpatch
brew install opam

# MacPort
port install opam

See also howto setup Emacs.app for Opam usage.

Ubuntu

Versions 18.04 and newer

There is a ppa available that contains the current stable version of opam.

add-apt-repository ppa:avsm/ppa
apt update
apt install opam
Versions older than 18.04

Use the binary distribution. Instructions provided at https://opam.ocaml.org/doc/Install.html#Binary-distribution

Guix & GuixSD

The opam package for guix can be installed with the command:

# Guix
guix package -i opam

From Sources

Getting the Sources

Sources of the latest stable version of opam are available on Github:

You can also download the full archives, including opam dependencies (these don't require any extra downloads, just the OCaml compiler -- 4.02.3 or later for the latest version):

  • 2.0.2
    • MD5: 8780b0dc4209451e21330b6a3e663fe9
    • SHA384: 2ecbdd28840564f873af2f56fcb337d49477f4b63a39ed3878a38eb55bbda67d7561a8deee697c36d7be50ff36a8fe21
  • 1.2.2
    • MD5: 7d348c2898795e9f325fb80eaaf5eae8
    • SHA384: 3a0a7868b5f510c1248959ed350eecacfe1abd886e373fd31066ce10871354010ef057934df026e5fad389ead6c2857d

Follow the instructions in the included README.md to get opam built and installed from there.

Note that opam1.2.2 doesn't build from source with OCaml 4.06.0. Use this command to compile lib_ext

OCAMLPARAM="safe-string=0,_" make lib-ext