Section: Opam Manual (1)
Index Return to Main Contents


opam-switch - Manage multiple installation prefixes.  


opam switch [OPTION]... [COMMAND] [ARG]...  


This command is used to manage "switches", which are independent installation prefixes with their own compiler and sets of installed and pinned packages. This is typically useful to have different versions of the compiler available at once.

Use opam switch create to create a new switch, and opam switch set to set the currently active switch. Without argument, lists installed switches, with one switch argument, defaults to set.

Switch handles SWITCH can be either a plain name, for switches that will be held inside ~/.opam, or a directory name, which in that case is the directory where the switch prefix will be installed, as _opam. Opam will automatically select a switch by that name found in the current directory or its parents, unless OPAMSWITCH is set or --switch is specified. When creating a directory switch, if package definitions are found locally, the user is automatically prompted to install them after the switch is created unless --no-install is specified.

opam switch set sets the default switch globally, but it is also possible to select a switch in a given shell session, using the environment. For that, use eval $(opam env --switch=SWITCH --set-switch).  


Without argument, defaults to list.

With a SWITCH argument, defaults to set SWITCH.
Create a new switch, and install the given compiler there. SWITCH can be a plain name, or a directory, absolute or relative, in which case a local switch is created below the given directory. COMPILER, if omitted, defaults to SWITCH if it is a plain name, unless --packages, --formula or --empty is specified. When creating a local switch, and none of these options are present, the compiler is chosen according to the configuration default (see opam-init(1)). If the chosen directory contains package definitions, a compatible compiler is searched within the default selection, and the packages will automatically get installed.
Set the currently active switch, among the installed switches.
remove SWITCH
Remove the given switch from disk.
export FILE
Save the current switch state to a file. If --full is specified, it includes the metadata of all installed packages, and if --freeze is specified, it freezes all vcs to their current commit.
import FILE
Import a saved switch state. If --switch is specified and doesn't point to an existing switch, the switch will be created for the import.
reinstall [SWITCH]
Reinstall the given compiler switch and all its packages.
Lists installed switches.
list-available [PATTERN]
Lists all the possible packages that are advised for installation when creating a new switch, i.e. packages with the compiler flag set. If no pattern is supplied, all versions are shown.
Prints the name of the current switch.
Prints the active switch invariant.
set-invariant PACKAGES
Updates the switch invariant, that is, the formula that the switch must keep verifying throughout all operations. The previous setting is overriden. See also options --force and --no-action. Without arguments, an invariant is chosen automatically.
set-description STRING
Sets the description for the selected switch.
Sets a local alias for a given switch, so that the switch gets automatically selected whenever in that directory or a descendant.
install SWITCH
Deprecated alias for 'create'.
set-base PACKAGES
Deprecated alias for 'set-invariant'.


    opam switch create 4.08.0

Create a new switch called "4.08.0" and select it, with a compiler automatically selected at version 4.08.0 (note that this can fail in case there is more than one compiler matching that version).

    opam switch create ./ --deps-only

Prepare a local switch for building the packages defined in ./. This scans the current directory for package definitions, chooses a compatible compiler, creates a local switch and installs the local package dependencies.

    opam switch create trunk --repos default,beta=https://github.com/ocaml/ocaml-beta-repository.git ocaml-variants.4.10.0+trunk

Create a new switch called "trunk", with ocaml-variants.4.10.0+trunk as compiler, with a new beta repository bound to the given URL selected besides the default one.  


-A COMP, --alias-of=COMP
This option is deprecated.
When creating a local switch in a project directory (i.e. a directory containing opam package definitions), install the dependencies of the project but not the project itself.
Attach the given description to a switch when creating it. Use the set-description subcommand to modify the description of an existing switch.
Allow creating an empty switch, with no invariant.
Only for set-invariant: force setting the invariant, bypassing consistency checks.
Allows specifying a complete "dependency formula", possibly including disjunction cases, as the switch invariant.
When exporting, locks all VCS urls to their current commit, failing if it can not be retrieved. This ensures that an import will restore the exact state. Implies --full.
When exporting, include the metadata of all installed packages, allowing to re-import even if they don't exist in the repositories (the default is to include only the metadata of pinned packages).
-j JOBS, --jobs=JOBS
Set the maximal number of concurrent jobs to use. The default value is calculated from the number of cores. You can also set it using the $OPAMJOBS environment variable.
-n, --no-action
Only for set-invariant: set the invariant, but don't enforce it right away: wait for the next install, upgrade or similar command.
This option is deprecated.
When creating a local switch, don't look for any local package definitions to install.
Don't automatically select newly installed switches.
When installing a switch, explicitly define the set of packages to enforce as the switch invariant.
When creating a new switch, use the given selection of repositories instead of the default. REPOS should be a comma-separated list of either already registered repository names (configured through e.g. opam repository add --dont-select), or NAME=URL bindings, in which case NAME should not be registered already to a different URL, and the new repository will be registered. See opam repository for more details. This option also affects list-available.
-s, --short
Output raw lists of names, one per line, skipping any details.


Skip the installation step for any missing system packages, and attempt to proceed with compilation of the opam packages anyway. If the installation is successful, opam won't prompt again about these system packages. Only meaningful if external dependency handling is enabled.
-b, --keep-build-dir
Keep the build directories after compiling packages. This is equivalent to setting $OPAMKEEPBUILDDIR to "true".
-d, --with-doc, --build-doc
Build the package documentation. This only affects packages listed on the command-line. The --build-doc form is deprecated as this does also installation. This is equivalent to setting $OPAMWITHDOC (or the deprecated $OPAMBUILDDOC) to "true".
Simulate the command, but don't actually perform any changes. This also can be set with environment variable $OPAMDEBUG.
This option registers the actions into the opam database, without actually performing them. WARNING: This option is dangerous and likely to break your opam environment. You probably want --dry-run. You've been warned.
--ignore-constraints-on[=PACKAGES] (default=)
Forces opam to ignore version constraints on all dependencies to the listed packages. This can be used to test compatibility, but expect builds to break when using this. Note that version constraints on optional dependencies and conflicts are unaffected. This is equivalent to setting $OPAMIGNORECONSTRAINTS.
When compiling a package which has its source bound to a local directory, process the build and install actions directly in that directory, rather than in a clean copy handled by opam. This only affects packages that are explicitly listed on the command-line. This is equivalent to setting $OPAMINPLACEBUILD to "true".
--lock-suffix=SUFFIX (absent=locked)
Set locked files suffix to SUFFIX.
In commands that use opam files found from pinned sources, if a variant of the file with an added .locked extension is found (e.g. foo.opam.locked besides foo.opam), that will be used instead. This is typically useful to offer a more specific set of dependencies and reproduce similar build contexts, hence the name. The lockoption can be used to generate such files, based on the versions of the dependencies currently installed on the host. This is equivalent to setting the $OPAMLOCKED environment variable. Note that this option doesn't generally affect already pinned packages.
-m MAKE, --make=MAKE
Use MAKE as the default 'make' command. Deprecated: use opam config set[-global] make MAKE instead. Has no effect if the make variable is defined.
Do not verify the checksum of downloaded archives.This is equivalent to setting $OPAMNOCHECKSUMS to "true".
Temporarily disables handling of external dependencies. This can be used if a package is not available on your system package manager, but you installed the required dependency by hand. Implies --assume-depexts, and stores the exceptions upon success as well.
Reject the installation of packages that don't provide a checksum for the upstream archives. This is equivalent to setting $OPAMREQUIRECHECKSUMS to "true".
Reuse existing build directories (kept by using --keep-build-dir), instead of compiling from a fresh clone of the source. This can be faster, but also lead to failures if the build systems of the packages don't handle upgrades of dependencies well. This is equivalent to setting $OPAMREUSEBUILDDIR to "true".
Call the solver and display the actions. Don't perform any changes. This is equivalent to setting $OPAMSHOW.
When running an install, upgrade or reinstall on source-pinned packages, they are normally updated from their origin first. This flag disables that behaviour and will keep them to their version in cache. This is equivalent to setting $OPAMSKIPUPDATE.
-t, --with-test, --build-test
Build and run the package unit-tests. This only affects packages listed on the command-line. The --build-test form is deprecated as this also affects installation. This is equivalent to setting $OPAMWITHTEST (or the deprecated $OPAMBUILDTEST) to "true".
--update-invariant, --unlock-base
Allow changes to the packages set as switch base (typically, the main compiler). Use with caution. This is equivalent to setting the $OPAMUNLOCKBASE environment variable


These options are common to all commands.

Don't fail if all requested packages can't be installed: try to install as many as possible. Note that not all external solvers may support this option (recent versions of aspcud or mccs should). This is equivalent to setting $OPAMBESTEFFORT environment variable.
--cli=MAJOR.MINOR (absent=2.1)
Use the command-line interface syntax and semantics of MAJOR.MINOR. Intended for any persistent use of opam (scripts, blog posts, etc.), any version of opam in the same MAJOR series will behave as for the specified MINOR release. The flag was not available in opam 2.0, so for 2.0, use $OPAMCLI. This is equivalent to setting $OPAMCLI to MAJOR.MINOR.
Colorize the output. WHEN must be one of `always', `never' or `auto'.
Specify user preferences for dependency solving for this run. Overrides both $OPAMCRITERIA and $OPAMUPGRADECRITERIA. For details on the supported language, and the external solvers available, see http://opam.ocaml.org/doc/External_solvers.html. A general guide to using solver preferences can be found at http://www.dicosmo.org/Articles/usercriteria.pdf.
Debug option: Save the CUDF requests sent to the solver to FILENAME-<n>.cudf.
Print debug message to stderr. This is equivalent to setting $OPAMDEBUG to "true".
Like --debug, but allows specifying the debug level (--debug sets it to 1). Equivalent to setting $OPAMDEBUG to a positive integer.
Print the git version of opam, if set (i.e. you are using a development version), and exit.
--help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of `auto', `pager', `groff' or `plain'. With `auto', the format is `pager` or `plain' whenever the TERM env var is `dumb' or undefined.
Ignore extra pins required by packages that get pinned, either manually through opam pin or through opam install DIR. This is equivalent to setting IGNOREPINDEPENDS=true.
Save the results of the opam run in a computer-readable file. If the filename contains the character `%', it will be replaced by an index that doesn't overwrite an existing file. Similar to setting the $OPAMJSON variable.
When configuring or updating a repository that is written for an earlier opam version (1.2), opam internally converts it to the current format. This disables this behaviour. Note that repositories should define their format version in a 'repo' file at their root, or they will be assumed to be in the older format. It is, in any case, preferable to upgrade the repositories manually using opam admin upgrade [--mirror URL] when possible.
Opam will replace itself with a newer binary found at OPAMROOT/opam if present. This disables this behaviour.
-q, --quiet
Disables --verbose.
Use ROOT as the current root path. This is equivalent to setting $OPAMROOT to ROOT.
--safe, --readonly
Make sure nothing will be automatically updated or rewritten. Useful for calling from completion scripts, for example. Will fail whenever such an operation is needed ; also avoids waiting for locks, skips interactive questions and overrides the $OPAMDEBUG variable. This is equivalent to set environment variable $OPAMSAFE.
Specify the CUDF solver to use for resolving package installation problems. This is either a predefined solver (this version of opam supports builtin-mccs+lp(), builtin-mccs+glpk, builtin-dummy-z3-solver, builtin-dummy-0install-solver, aspcud, mccs, aspcud-old, packup), or a custom command that should contain the variables %{input}%, %{output}%, %{criteria}%, and optionally %{timeout}%. This is equivalent to setting $OPAMEXTERNALSOLVER.
Fail whenever an error is found in a package definition or a configuration file. The default is to continue silently if possible.
Use SWITCH as the current compiler switch. This is equivalent to setting $OPAMSWITCH to SWITCH.
Disable any external solver, and use the built-in one (this requires that opam has been compiled with a built-in solver). This is equivalent to setting $OPAMNOASPCUD or $OPAMUSEINTERNALSOLVER.
-v, --verbose
Be more verbose. One -v shows all package commands, repeat to also display commands called internally (e.g. tar, curl, patch etc.) Repeating n times is equivalent to setting $OPAMVERBOSE to "n".
Show version information.
-w, --working-dir
Whenever updating packages that are bound to a local, version-controlled directory, update to the current working state of their source instead of the last committed state, or the ref they are pointing to. As source directory is copied as it is, if it isn't clean it may result on a opam build failure.This only affects packages explicitly listed on the command-line.It can also be set with $OPAMWORKINGDIR.
-y, --yes
Answer yes to all yes/no questions without prompting. This is equivalent to setting $OPAMYES to "true".


Opam makes use of the environment variables listed here. Boolean variables should be set to "0", "no", "false" or the empty string to disable, "1", "yes" or "true" to enable.

OPAMALLPARENS surround all filters with parenthesis

OPAMAUTOREMOVE see remove option `--auto-remove`

OPAMBESTEFFORT see option `--best-effort`

OPAMBESTEFFORTPREFIXCRITERIA sets the string that must be prepended to the criteria when the `--best-effort` option is set, and is expected to maximise the `opam-query` property in the solution

OPAMCLI see option `--cli'

OPAMCOLOR, when set to always or never, sets a default value for the --color option.

OPAMCRITERIA specifies user preferences for dependency solving. The default value depends on the solver version, use `config report` to know the current setting. See also option --criteria

OPAMCUDFFILE file save the cudf graph to file-actions-explicit.dot

OPAMDEPEXTYES launch system package managers in non-interactive mode

OPAMCURL can be used to select a given 'curl' program. See OPAMFETCH for more options.

OPAMDEBUG see options `--debug' and `--debug-level'.

OPAMDEBUGSECTIONS if set, limits debug messages to the space-separated list of sections. Sections can optionally have a specific debug level (for example, CLIENT:2 or CLIENT CUDF:2, but otherwise use `--debug-level'.

OPAMDOWNLOADJOBS sets the maximum number of simultaneous downloads.

OPAMDRYRUN see option `--dry-run`

OPAMEDITOR sets the editor to use for opam file editing, overrides $EDITOR and $VISUAL

OPAMERRLOGLEN sets the number of log lines printed when a sub-process fails. 0 to print all.

OPAMEXTERNALSOLVER see option `--solver'.

OPAMFAKE see option `--fake`

OPAMFETCH specifies how to download files: either `wget', `curl' or a custom command where variables %{url}%, %{out}%, %{retry}%, %{compress}% and %{checksum}% will be replaced. Overrides the 'download-command' value from the main config file.


OPAMIGNORECONSTRAINTS see install option `--ignore-constraints-on`

OPAMIGNOREPINDEPENDS see option `--ignore-pin-depends`

OPAMJOBS sets the maximum number of parallel workers to run.

OPAMJSON log json output to the given file (use character `%' to index the files)

OPAMLOCKED combination of `--locked` and `--lock-suffix` options

OPAMLOGS logdir sets log directory, default is a temporary directory in /tmp

OPAMMAKECMD set the system make command to use

OPAMNOAUTOUPGRADE disables automatic internal upgrade of repositories in an earlier format to the current one, on 'update' or 'init'.

OPAMKEEPLOGS tells opam to not remove some temporary command logs and some backups. This skips some finalisers and may also help to get more reliable backtraces

OPAMLOCKRETRIES sets the number of tries after which opam gives up acquiring its lock and fails. <= 0 means infinite wait.

OPAMMERGEOUT merge process outputs, stderr on stdout

OPAMNO answer no to any question asked.


OPAMNOCHECKSUMS enables option --no-checksums when available.

OPAMDROPWORKINGDIR overrides packages previously updated with --working-dir on update. Without this variable set, opam would keep them unchanged unless explicitely named on the command-line.

OPAMNOSELFUPGRADE see option `--no-self-upgrade'.

OPAMPINKINDAUTO sets whether version control systems should be detected when pinning to a local path. Enabled by default since 1.3.0.

OPAMPRECISETRACKING fine grain tracking of directories

OPAMREQUIRECHECKSUMS Enables option `--require-checksums' when available (e.g. for `opam install`).

OPAMRETRIES sets the number of tries before failing downloads.

OPAMROOT see option `--root'. This is automatically set by `opam env --root=DIR --set-root'.

OPAMROOTISOK don't complain when running as root.

OPAMSAFE see option `--safe'

OPAMSHOW see option `--show`

OPAMSKIPUPDATE see option `--skip-updates`

OPAMSKIPVERSIONCHECKS bypasses some version checks. Unsafe, for compatibility testing only.

OPAMSOLVERTIMEOUT change the time allowance of the solver. Default is 60.0, set to 0 for unlimited. Note that all solvers may not support this option.

OPAMSOLVERALLOWSUBOPTIMAL (default `true') allows some solvers to still return a solution when they reach timeout; while the solution remains assured to be consistent, there is no guarantee in this case that it fits the expected optimisation criteria. If `true', opam will continue with a warning, if `false' a timeout is an error. Currently only the builtin-z3 backend handles this degraded case.

OPAMSTATUSLINE display a dynamic status line showing what's currently going on on the terminal. (one of one of `always', `never' or `auto')

OPAMSTATS display stats at the end of command

OPAMSTRICT fail on inconsistencies (file reading, switch import, etc.)

OPAMSWITCH see option `--switch'. Automatically set by `opam env --switch=SWITCH --set-switch'.

OPAMUNLOCKBASE see install option `--unlock-base`

OPAMUPGRADECRITERIA specifies user preferences for dependency solving when performing an upgrade. Overrides OPAMCRITERIA in upgrades if both are set. See also option --criteria

OPAMUSEINTERNALSOLVER see option `--use-internal-solver'.

OPAMUSEOPENSSL force openssl use for hash computing

OPAMUTF8 use UTF8 characters in output (one of one of `always', `never' or `auto'). By default `auto', which is determined from the locale).

OPAMUTF8MSGS use extended UTF8 characters (camels) in opam messages. Implies OPAMUTF8. This is set by default on OSX only.

OPAMVALIDATIONHOOK hook if set, uses the `%{hook%}` command to validate an opam repository update

OPAMVAR_var overrides the contents of the variable var when substituting `%{var}%` strings in `opam` files.

OPAMVAR_package_var overrides the contents of the variable package:var when substituting `%{package:var}%` strings in `opam` files.

OPAMVERBOSE see option `--verbose'.

OPAMWORKINGDIR see option `--working-dir`

OPAMYES see option `--yes'.  


All scripts and programmatic invocations of opam should use `--cli' in order to ensure that they work seamlessly with future versions of the opam client. Additionally, blog posts or other documentation can benefit, as it prevents information from becoming stale.

Although opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface.

The command-line version is selected by using the `--cli' option or the OPAMCLI environment variable. `--cli' may be specified more than once, where the last instance takes precedence. OPAMCLI is only inspected if `--cli' is not given.

Since CLI version support was only added in opam 2.1, use OPAMCLI to select 2.0 support (as opam 2.0 will just ignore it), and `--cli=2.1' for 2.1 later versions, since an environment variable controlling the parsing of syntax is brittle. To this end, opam displays a warning if OPAMCLI specifies a valid version other than 2.0, and also if `--cli=2.0' is specified.  


As an exception to the following, the `exec' command returns 127 if the command was not found or couldn't be executed, and the command's exit value otherwise.

Success, or true for boolean queries.
False. Returned when a boolean return value is expected, e.g. when running with --check, or for queries like opam lint.
Bad command-line arguments, or command-line arguments pointing to an invalid context (e.g. file not following the expected format).
Not found. You requested something (package, version, repository, etc.) that couldn't be found.
Aborted. The operation required confirmation, which wasn't given.
Could not acquire the locks required for the operation.
There is no solution to the user request. This can be caused by asking to install two incompatible packages, for example.
Error in package definition, or other metadata files. Using --strict raises this error more often.
Package script error. Some package operations were unsuccessful. This may be an error in the packages or an incompatibility with your system. This can be a partial error.
Sync error. Could not fetch some remotes from the network. This can be a partial error.
Configuration error. Opam or system configuration doesn't allow operation, and needs fixing.
Solver failure. The solver failed to return a sound answer. It can be due to a broken external solver, or an error in solver configuration.
Internal error. Something went wrong, likely due to a bug in opam itself.
User interrupt. SIGINT was received, generally due to the user pressing Ctrl-C.


See https://opam.ocaml.org/doc.  


Vincent Bernardoff <vb@luminar.eu.org>

Raja Boujbel <raja.boujbel@ocamlpro.com>

Roberto Di Cosmo <roberto@dicosmo.org>

Thomas Gazagnaire <thomas@gazagnaire.org>

Louis Gesbert <louis.gesbert@ocamlpro.com>

Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr>

Anil Madhavapeddy <anil@recoil.org>

Guillem Rieu <guillem.rieu@ocamlpro.com>

Ralf Treinen <ralf.treinen@pps.jussieu.fr>

Frederic Tuong <tuong@users.gforge.inria.fr>  


Check bug reports at https://github.com/ocaml/opam/issues.




This document was created by man2html, using the manual pages.
Time: 01:01:31 GMT, December 01, 2020