OPAM(1)

πŸ‘‘ OPAM(1) β€” the Opam Manual πŸ‘‘

okay so bestie, welcome to the opam man page πŸ’– this is the page, straight out of the Opam Manual, section 1, and it's giving main character energy from the very first line. Let's get into it 🫢


🌸 NAME 🌸

opam β€” source-based package management ✨


πŸŽ€ SYNOPSIS πŸŽ€

opam [COMMAND] …

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so opam is a package manager. Periodt. πŸ’… It uses the powerful mancoosi tools to handle dependencies β€” and no, not the "eh, probably fine" kind of dependency handling. We're talking real support for version constraints, optional dependencies, and conflict management. The default configuration binds it to the official package repository for OCaml 🌈

She also has support for a whole roster of different remote repositories, like HTTP, rsync, git, darcs and mercurial πŸ”₯ And get this β€” everything gets installed inside a local opam directory, which can literally include multiple installation prefixes, each with a different set of installed packages. multiple. sets. iconic. πŸ‘‘

If you want the tea on a specific command, use either opam <command> --help or opam help <command> πŸ“


🌟 COMMANDS 🌟

πŸ’« admin [OPTION]…

Tools for repository administrators πŸ› οΈ

πŸ’« clean [OPTION]…

Cleans up opam caches 🧹

πŸ’« config [OPTION]… [COMMAND] [ARG]…

Display configuration options for packages. βš™οΈ

πŸ’« env [OPTION]…

Prints appropriate shell variable assignments to stdout 🐚

πŸ’« exec [OPTION]… COMMAND [ARG]...…

Executes a command in the proper opam environment πŸš€

πŸ’« help [--man-format=FMT] [OPTION]… [TOPIC]

Display help about opam and opam commands. πŸ™‹β€β™€οΈ

πŸ’« init [OPTION]… [NAME] [ADDRESS]

Initialize opam state, or set init options. 🌱

πŸ’« install [OPTION]… [PACKAGES]…

Install a list of packages. πŸ“¦

πŸ’« lint [OPTION]… [FILES]…

Checks and validate package description (opam) files. πŸ”

πŸ’« list [--check] [--no-depexts] [--silent] [OPTION]… [PATTERNS]…

Display the list of available packages. πŸ“‹

πŸ’« lock [--direct-only] [--keep-local] [--lock-suffix=SUFFIX] [OPTION]… [PACKAGES]…

Create locked opam files to share build environments across hosts. πŸ”’

πŸ’« option [--global] [OPTION]… [FIELD[(=|+=|-=)[VALUE]]]

Global and switch configuration options settings πŸŽ›οΈ

πŸ’« pin [OPTION]… [COMMAND] [ARG]…

Pin a given package to a specific version or source. πŸ“Œ

πŸ’« reinstall [OPTION]… [PACKAGES]…

Reinstall a list of packages. πŸ”

πŸ’« remove [OPTION]… [PACKAGES]…

Remove a list of packages. πŸ—‘οΈ

πŸ’« repository [--kind=KIND] [--rank=RANK] [--short] [OPTION]… [COMMAND] [ARG]…

Manage opam repositories. πŸ›οΈ

πŸ’« show [OPTION]… [PACKAGES]…

Display information about specific packages. πŸ‘€

πŸ’« source [OPTION]… PACKAGE

Get the source of an opam package. 🧬

πŸ’« switch [OPTION]… [COMMAND] [ARG]…

Manage multiple installation prefixes. πŸ”€

πŸ’« tree [--recursive] [--subpath=PATH] [OPTION]… [PACKAGES]…

Draw the dependency forest of installed packages. 🌳 (a forest, bestie 🌲🌲)

πŸ’« update [OPTION]… [NAMES]…

Update the list of available packages. πŸ”„

πŸ’« upgrade [OPTION]… [PACKAGES]…

Upgrade the installed package to latest version. ⬆️

πŸ’« var [--global] [--package=PACKAGE] [OPTION]… [VAR[=[VALUE]]]

Display and update the value associated with a given variable 🏷️


🧚 COMMAND ALIASES 🧚

yep, opam has a whole little clique of aliases β€” same energy, different name 😌

πŸ’œ info [OPTION]… [PACKAGES]…

An alias for show.

πŸ’œ remote [--kind=KIND] [--rank=RANK] [--short] [OPTION]… [COMMAND] [ARG]…

An alias for repository.

πŸ’œ search [--check] [--no-depexts] [--silent] [OPTION]… [PATTERNS]…

An alias for list --search.

πŸ’œ uninstall [OPTION]… [PACKAGES]…

An alias for remove.

πŸ’œ unpin [OPTION]… [ARG]…

An alias for pin remove.

πŸ’œ why [--recursive] [--subpath=PATH] [OPTION]… [PACKAGES]…

An alias for tree --rev-deps.


✨ COMMON OPTIONS ✨

These ones are common to all commands, bestie β€” the shared wardrobe, if you will πŸŽ€

  • --best-effort β€” Don't fail if all requested packages can't be installed: try to install as many as possible. Heads up though, not all external solvers may support this option (recent versions of aspcud or mccs should). This is equivalent to setting the $OPAMBESTEFFORT environment variable. πŸ™ˆ
  • --cli=MAJOR.MINOR (absent=2.6) β€” Use the command-line interface syntax and semantics of MAJOR.MINOR. This is 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 to select the 2.0 CLI, set the OPAMCLI environment variable to 2.0 instead of using this parameter. πŸ•°οΈ
  • --color=WHEN β€” Colorize the output. WHEN must be one of always, never or auto. 🌈
  • --confirm-level=LEVEL β€” Confirmation level, LEVEL must be one of ask, no, yes or unsafe-yes. Can be specified more than once. If --yes or --no are also given, the value of the last --confirm-level is taken into account. This is equivalent to setting $OPAMCONFIRMLEVEL. ❓
  • --criteria=CRITERIA β€” Specify user preferences for dependency solving for this run. Overrides $OPAMCRITERIA, $OPAMFIXUPCRITERIA 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. πŸ“š
  • --cudf=FILENAME β€” Debug option: Save the CUDF requests sent to the solver to FILENAME-<n>.cudf where <n> is the n-th call to the solver during the opam run. πŸ›
  • --debug β€” Print debug message to stderr. This is equivalent to setting $OPAMDEBUG to "true". πŸ’€
  • --debug-level=LEVEL β€” Like --debug, but allows specifying the debug level (--debug sets it to 1). Equivalent to setting $OPAMDEBUG to a positive integer.
  • --git-version β€” 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-pin-depends β€” 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. πŸ“Œ
  • --json=FILENAME β€” 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. πŸ€–
  • --no β€” Answer no to all opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMNO to "true". πŸ™…β€β™€οΈ
  • --no-aspcud β€” Removed in 2.1. ⚰️
  • --no-auto-upgrade β€” 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. ⚠️
  • --no-self-upgrade β€” Opam will replace itself with a newer binary found at OPAMROOT/opam if present. This disables this behaviour. πŸͺž
  • -q, --quiet β€” Disables --verbose. 🀫
  • --root=ROOT β€” 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. πŸ›‘οΈ
  • --solver=CMD β€” 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-0install, 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. 🧠
  • --strict β€” Fail whenever an error is found in a package definition or a configuration file. The default is to continue silently if possible. 😀
  • --switch=SWITCH β€” Use SWITCH as the current compiler switch. This is equivalent to setting $OPAMSWITCH to SWITCH. πŸ”€
  • --use-internal-solver β€” 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". πŸ—£οΈ
  • --version β€” 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 opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMYES to "true". βœ…

🌈 ENVIRONMENT 🌈

ok bestie so opam reads a whole lil family of environment variables and honestly? they run the show. here's the thing about the boolean ones: to turn them off, set them to "0", "no", "false", or just the literal empty string. to turn them on, set them to "1", "yes", or "true". that's it, that's the rule πŸ’…

  • OPAMALLPARENS β€” wraps every single filter in parenthesis. all of them. the parens era πŸŽ€
  • OPAMASSUMEDEPEXTS β€” see the --assume-depexts option.
  • OPAMAUTOANSWER β€” internal use only, bestie, nothing to see here πŸ™ˆ
  • OPAMAUTOREMOVE β€” see the remove option --auto-remove.
  • OPAMBESTEFFORT β€” see the --best-effort option.
  • OPAMBESTEFFORTPREFIXCRITERIA β€” sets the string that must be prepended to the criteria when the --best-effort option is set, and it's expected to maximise the opam-query property in the solution.
  • OPAMBUILDDOC β€” removed in 2.1. rip πŸ’€
  • OPAMBUILDTEST β€” also removed in 2.1. double rip πŸ’€πŸ’€
  • OPAMCLI β€” see the --cli option.
  • OPAMCOLOR β€” when you set it to always or never, it sets a default value for the --color option. so you don't have to type it every time, iconic behavior ⭐
  • OPAMCONFIRMLEVEL β€” see the --confirm-level option. heads up: OPAMCONFIRMLEVEL has priority over OPAMYES and OPAMNO, it's the main character here πŸ‘‘
  • OPAMCRITERIA β€” specifies your user preferences for dependency solving. the default value depends on the solver version, so run config report to find out the current setting. see also the --criteria option.
  • OPAMCUDFFILE β€” save the cudf graph to file-actions-explicit.dot.
  • OPAMCUDFTRIM β€” controls the filtering of unrelated packages during CUDF preprocessing.
  • OPAMDIGDEPTH β€” defines how aggressive the lookup for conflicts during CUDF preprocessing is. how deep is it gonna dig? you decide πŸ•³οΈ
  • OPAMDOWNLOADJOBS β€” sets the maximum number of simultaneous downloads.
  • OPAMDROPWORKINGDIR β€” overrides packages that were previously updated with --working-dir on update. without this variable set, opam would keep them unchanged unless you explicitly name them on the command-line.
  • OPAMDRYRUN β€” see the --dry-run option.
  • OPAMEDITOR β€” sets the editor to use for opam file editing, and it overrides $EDITOR and $VISUAL. it said "i'm the boss now" 😀
  • OPAMERRLOGLEN β€” sets the number of log lines printed when a sub-process fails. set it to 0 to print all of them.
  • OPAMEXTERNALSOLVER β€” see the --solver option.
  • OPAMFAKE β€” see the --fake option.
  • OPAMFETCH β€” specifies how to download files: either wget, curl, or a custom command where the variables %{url}%, %{out}%, %{retry}%, %{compress}% and %{checksum}% will be replaced. this overrides the 'download-command' value from the main config file.
  • OPAMFIXUPCRITERIA β€” same as OPAMUPGRADECRITERIA, but specific to fixup and reinstall.
  • OPAMIGNOREAVAILABLE β€” see the install option --ignore-available-on.
  • OPAMIGNORECONSTRAINTS β€” see the install option --ignore-constraints-on.
  • OPAMIGNOREPINDEPENDS β€” see the --ignore-pin-depends option.
  • OPAMINPLACEBUILD β€” see the --inplace-build option.
  • OPAMJOBS β€” sets the maximum number of parallel workers to run. multitasking queen energy ✨
  • OPAMJSON β€” log json output to the given file (use the character % to index the files).
  • OPAMKEEPBUILDDIR β€” see the install option --keep-build-dir.
  • OPAMKEEPLOGS β€” tells opam to not remove some temporary command logs and some backups. this skips some finalisers and may also help you get more reliable backtraces. keeping the receipts, love that for you πŸŽ€
  • OPAMLOCKED β€” combination of the --locked and --lock-suffix options.
  • OPAMLOGS β€” logdir sets the log directory, and the default is a temporary directory in /tmp.
  • OPAMMAKECMD β€” set the system make command to use.
  • OPAMMERGEOUT β€” merge process outputs, with stderr going on stdout.
  • OPAMNO β€” answer no to any question asked, see the --no and --confirm-level options. OPAMNO is ignored if either OPAMCONFIRMLEVEL or OPAMYES is set.
  • OPAMNOAGGREGATE β€” with opam admin check, don't aggregate packages.
  • OPAMNOASPCUD β€” deprecated. step away from the legacy, bestie πŸ™ˆ
  • OPAMNOAUTOUPGRADE β€” disables the automatic internal upgrade of repositories in an earlier format to the current one, on 'update' or 'init'.
  • OPAMNOCHECKSUMS β€” enables the option --no-checksums when available.
  • OPAMNODEPEXTS β€” disables system dependencies handling, see the --no-depexts option.
  • OPAMNOENVNOTICE β€” internal.
  • OPAMNOSELFUPGRADE β€” see the 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. pinkinda... auto. she's been doing this since 1.3.0 and she's tired πŸ’…
  • OPAMPRECISETRACKING β€” fine grain tracking of directories.
  • OPAMPREPRO β€” set this to false to disable CUDF preprocessing. less efficient, but it might help with debugging solver issues.
  • OPAMREPOSITORYTARRING β€” internally store all non-vcs repositories as tar.gz files (by default, http repositories are stored as archive). this can be much faster on filesystems that don't cope well with scanning large trees. all operations are done in-memory, with no I/O for scanning the repository. glow up fr fr πŸ”₯
  • OPAMREQUIRECHECKSUMS β€” enables the option --require-checksums when available (e.g. for opam install).
  • OPAMRETRIES β€” sets the number of tries before failing downloads.
  • OPAMREUSEBUILDDIR β€” see the --reuse-build-dir option.
  • OPAMROOT β€” see the --root option. this one is automatically set by opam env --root=DIR --set-root.
  • OPAMROOTISOK β€” don't complain when running as root. let her live 😌
  • OPAMSAFE β€” see the --safe option.
  • OPAMSHOW β€” see the --show option.
  • OPAMSKIPUPDATE β€” see the --skip-updates option.
  • OPAMSKIPVERSIONCHECKS β€” bypasses some version checks. unsafe, for compatibility testing only. do not do this for fun, i'm begging 🫢
  • 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 willcontinue with a warning; if false, a timeout is an error. currently only the builtin-z3 backend handles this degraded case.
  • OPAMSOLVERTIMEOUT β€” change the time allowance of the solver. default is 60.0, set it to 0 for unlimited. note that not all solvers may support this option.
  • OPAMSOLVERTOLERANCE β€” changes the tolerance towards the solver choosing an unoptimized solution (i.e. it might pull outdated packages, not cute). typical values range from 0.0 (best solution known to the solver) to 1.0 (unoptimized solution). default is 0.0. this option is useful in case the solver can't find a solution in a reasonable time (see $OPAMSOLVERTIMEOUT). note that not all solvers may support this option.
  • OPAMSTATS β€” removed in 2.4. πŸ’€
  • OPAMSTATUSLINE β€” display a dynamic status line showing what's currently going on on the terminal. (one of one of always, never or auto)
  • OPAMSTRICT β€” fail on inconsistencies (file reading, switch import, etc.). no sloppy behavior allowed 🚫
  • OPAMSWITCH β€” see the --switch option. automatically set by opam env --switch=SWITCH --set-switch.
  • OPAMUNLOCKBASE β€” see the install option --unlock-base.
  • OPAMUPGRADECRITERIA β€” specifies user preferences for dependency solving when performing an upgrade. it overrides OPAMCRITERIA in upgrades if both are set. see also the --criteria option.
  • OPAMUSEINTERNALSOLVER β€” see the --use-internal-solver option.
  • OPAMUSEOPENSSL β€” removed in 2.2. gone bestie πŸ’”
  • OPAMUTF8 β€” use UTF8 characters in output (one of one of always, never or auto). by default it's auto, which is determined from the locale.
  • OPAMUTF8MSGS β€” use extended UTF8 characters (camels πŸͺ) in opam messages. implies OPAMUTF8. this is set by default on macOS only. the camels are macOS exclusive, iykyk ✨
  • OPAMVALIDATIONHOOK β€” if set, uses the %{hook}% command to validate an opam repository update.
  • OPAMVERBOSE β€” see the --verbose option.
  • OPAMVERBOSEON β€” see the option --verbose-on.
  • OPAMVERSIONLAGPOWER β€” do not use. that's the whole thing. do not use πŸ™…β€β™€οΈ
  • OPAMWITHDEVSETUP β€” see the install option --with-dev-setup.
  • OPAMWITHDOC β€” see the install option --with-doc.
  • OPAMWITHTEST β€” see the install option --with-test.
  • OPAMWORKINGDIR β€” see the --working-dir option.
  • OPAMYES β€” see the --yes and --confirm-level options. OPAMYES has priority over OPAMNO and is ignored if OPAMCONFIRMLEVEL is set.
  • 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.

πŸŽ€ CLI VERSION πŸŽ€

okay this part is important so gather round 🫢 every single script and programmatic invocation of opam should use --cli, and the reason is genuinely so real: it's how you make sure your stuff works seamlessly with future versions of the opam client. and it's not just for scripts either β€” blog posts and other documentation benefit too, because it stops information from going stale. no more ancient tutorials that don't work anymore, we love to see it πŸ’–

so here's the sitch: opam only supports roots (~/.opam/) for the current version, but it does provide backwards compatibility for its command-line interface. slay.

now, since CLI version support was only added in opam 2.1, you use OPAMCLI to select 2.0 support (because opam 2.0 will just ignore it, so it's safe), and you use --cli=2.1 for 2.1 (or later) versions β€” since an environment variable controlling the parsing of syntax is brittle. like, fragile. 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. so if you see warnings, that's why bestie πŸ‘€

the command-line version is selected by using the --cli option or the OPAMCLI environment variable. --cli may be specified morethan once, where the last instance takes precedence. OPAMCLI is only inspected if --cli is not given. last one wins, the env var sits in the waiting room 😌

πŸ’€ EXIT STATUS πŸ’€

okay bestie, listen up, because this is the part where opam tells you exactly what went wrong by handing you a number. learn these, they're your love language πŸ”’

one tiny exception first, and it's important: the exec command does not follow the list below. If the command wasn't found or couldn't be executed, exec returns 127. Otherwise it returns the command's own exit value, periodt.

Now the actual list:

  • 0 β€” success, or true for boolean queries. we love to see it πŸ’–
  • 1 β€” false. this one shows up when a boolean return value is expected, like when you're running with --check, or for queries like opam lint.
  • 2 β€” bad command-line arguments, or command-line arguments pointing at an invalid context (e.g. a file that doesn't follow the expected format). πŸ™ˆ
  • 5 β€” not found. you asked for something (package, version, repository, etc.) and it simply could not be found. it's giving ghosted.
  • 10 β€” aborted. the operation needed confirmation and you didn't give it.
  • 15 β€” couldn't get the locks required for the operation. someone else is holding them πŸ”’
  • 20 β€” there's no solution to your request. this can happen when you ask to install two incompatible packages, for example.
  • 30 β€” error in package definition, or in other metadata files. heads up: using --strict raises this error way more often.
  • 31 β€” package script error. some package operations were unsuccessful. this can be an error in the packages, or an incompatibility with your system. can be only a partial error.
  • 40 β€” sync error. some remotes couldn't be fetched from the network. also can be a partial error.
  • 50 β€” configuration error. opam or your system config doesn't allow the operation, and it needs fixing before you go anywhere. πŸ”§
  • 60 β€” solver failure. the solver failed to return a sound answer. could be a broken external solver, or an error in the solver configuration.
  • 99 β€” internal error πŸ’€ something went wrong, likely a bug in opam itself.
  • 130 β€” user interrupt. SIGINT was received, generally because the user pressed Ctrl+C.

and then there's this last little cluster of codes, also on the menu:

  • 0 β€” on success.
  • 123 β€” on indiscriminate errors reported on standard error.
  • 124 β€” on command line parsing errors.
  • 125 β€” on unexpected internal errors (bugs).

πŸ“š FURTHER DOCUMENTATION πŸ“š

want more? go read https://opam.ocaml.org/doc. the docs are right there, bestie, go feast ✨


πŸ‘‘ AUTHORS πŸ‘‘

the legends who made this. absolute icons, all of them, no notes 🫢

  • David Allsopp <david@tarides.com>
  • Vincent Bernardoff <vb@luminar.eu.org>
  • Raja Boujbel <raja.boujbel@ocamlpro.com>
  • Kate Deplaix <kit-ty-kate@exn.st>
  • 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>

πŸ› BUGS πŸ›

found something cursed? check the bug reports at https://github.com/ocaml/opam/issues. don't suffer in silence, tell the devs πŸ™


and that's a wrap on the whole page, babe πŸŽ€ this was Opam 2.6.1, manual section OPAM(1) β€” screenshot it, bookmark it, tattoo it on your forearm, whatever works for you. go forth and opam responsibly, bestie πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from