OPAM-ENV(1)

πŸŽ€ OPAM-ENV(1) β€” the Opam Manual page, bestie edition πŸŽ€

okay so this is the man page for opam-env, straight outta the Opam Manual. it's the lil command that hands your shell the environment variables it's been craving. let's go πŸ’…


✨ NAME ✨

opam-env β€” prints the appropriate shell variable assignments to stdout. that's it, that's the job 🫢


✨ SYNOPSIS ✨

opam env [OPTION]…

✨ DESCRIPTION ✨

It returns the bindings for the environment variables that get set in your current switch β€” think PATH and friends β€” in a format that's literally meant to be evaluated by a shell. ✨

Slap -v on it and it also adds comments telling you why each binding exists or which package it came from. super useful, iykyk. πŸ’–

The most iconic way to use this is:

eval $(opam env)

and boom β€” every shell command after that runs in the proper opam context. main character energy fr fr. πŸ‘‘

ngl this is just a shortcut β€” it's equivalent to opam config env.


✨ OPTIONS ✨

  • --check β€” exits with 0 if your environment is already up-to-date, and 1 if it isn't β€” and before it bails it prints the list of variables that are not up-to-date. a lil vibe check for your env 🌸
  • --inplace-path β€” when it's updating the PATH variable, this swaps out any pre-existing opam path in-place instead of yeeting the new path to the front. what that means: programs installed in opam that were already shadowed stay shadowed after opam env. no cap.
  • --revert β€” outputs the environment with the updates opam did reverted instead. undo era πŸ™ˆ
  • --set-root β€” with the env and exec subcommands, also sets the OPAMROOT variable, so every further call to opam uses the same root. consistency slay. πŸ’…
  • --set-switch β€” with the env and exec subcommands, also sets the OPAMSWITCH variable, making sure further calls to opam use the same switch as this one. locked in. πŸ”’
  • --sexp β€” prints the environment as an s-expression instead of the usual shell format. for the lisp girlies πŸ¦‹
  • --shell=SHELL β€” sets the config mode for the opam environment appropriate for SHELL. it's one of bash, sh, csh, zsh, fish, pwsh, cmd or powershell. by default it's guessed from the parent processes and the $SHELL variable. ✨

✨ COMMON OPTIONS ✨

these options are common to all commands, so they show up everywhere like that one friend who's always in the group chat πŸ’–

  • --best-effort β€” don't fail if all the requested packages can't be installed; just try to install as many as possible. heads up though: not all external solvers may support this (recent versions of aspcud or mccs should). 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 meant 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 wasn't available in opam 2.0, so to select the 2.0 CLI you set the OPAMCLI environment variable to 2.0 instead of using this parameter. ⭐
  • --color=WHEN β€” colorizes the output. WHEN has to 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 what counts. equivalent to setting $OPAMCONFIRMLEVEL. 😭
  • --criteria=CRITERIA β€” specify your user preferences for dependency solving for this run. this overrides $OPAMCRITERIA, $OPAMFIXUPCRITERIA and $OPAMUPGRADECRITERIA. for the deets 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 lives at http://www.dicosmo.org/Articles/usercriteria.pdf. 🧚
  • --cudf=FILENAME β€” debug option: saves the CUDF requests sent to the solver into FILENAME-<n>.cudf, where <n> is the n-th call to the solver during the opam run. πŸ”
  • --debug β€” prints debug messages to stderr. equivalent to setting $OPAMDEBUG to "true". πŸ›
  • --debug-level=LEVEL β€” like --debug, but you get to pick the debug level (--debug just sets it to 1). equivalent to setting $OPAMDEBUG to a positive integer.
  • --git-version β€” prints the git version of opam, if one is set (i.e. you're running a development version), then exits. πŸ’€
  • --help[=FMT] (default=auto) β€” shows this help in format FMT. 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 β€” ignores extra pins required by packages that get pinned, whether manually through opam pin or through opam install DIR. equivalent to setting IGNOREPINDEPENDS=true. πŸ™ˆ
  • --json=FILENAME β€” saves the results of the opam run into a computer-readable file. if the filename contains the character %, it gets replaced by an index that doesn't overwrite an existing file. similar to setting the $OPAMJSON variable. ✨
  • --no β€” answers no to all opam yes/no questions without prompting. see also --confirm-level. equivalent to setting $OPAMNO to "true". πŸ™…
  • --no-aspcud β€” removed in 2.1. RIP bestie, she's gone πŸ’€
  • --no-auto-upgrade β€” when configuring or updating a repository that was written for an earlier opam version (1.2), opam internally converts it to the current format. this disables that behaviour. note that repositories should define their format version in a repo file at their root, or they'll be assumed to be in the older format. in any case, it's 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 that behaviour. βœ‹
  • -q, --quiet β€” disables --verbose. shhh 🀫
  • --root=ROOT β€” use ROOT as the current root path. equivalent to setting $OPAMROOT to ROOT. 🌱
  • --safe, --readonly β€” makes sure nothing will be automatically updated or rewritten. useful for calling from completion scripts, for example. it will fail whenever such an operation is needed; it also avoids waiting for locks, skips interactive questions and overrides the $OPAMDEBUG variable. equivalent to setting the 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}%. equivalent to setting $OPAMEXTERNALSOLVER. πŸ”₯
  • --strict β€” fails whenever an error is found in a package definition or a configuration file. the default is to continue silently if possible. no more pretending you didn't see it πŸ’…
  • --switch=SWITCH β€” use SWITCH as the current compiler switch. equivalent to setting $OPAMSWITCH to SWITCH. πŸ”„
  • --use-internal-solver β€” disables any external solver and uses the built-in one (this requires that opam was compiled with a built-in solver). equivalent to setting $OPAMNOASPCUD or $OPAMUSEINTERNALSOLVER. 🧠
  • -v, --verbose β€” be more verbose. one -v shows all package commands; repeat it to also display commands called internally (e.g. tar, curl, patch etc.). repeating it n times is equivalent to setting $OPAMVERBOSE to "n". πŸ—£οΈ
  • --version β€” shows 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're pointing to. since the source directory is copied as it is, if it isn't clean it may result in an opam build failure. this only affects packages explicitly listed on the command-line. it can also be set with $OPAMWORKINGDIR. ⚠️
  • -y, --yes β€” answers yes to all opam yes/no questions without prompting. see also --confirm-level. equivalent to setting $OPAMYES to "true". βœ…


✨ ENVIRONMENT ✨ (aka the vibe check on your shell)

okay bestie, listen πŸ’– opam is obsessed with environment variables. doesn't it ever. here's the whole roster β€” set these in your shell and opam will pick them up like the moment of recognition.

Quick rule for the boolean girlies: these bad boys want "0", "no", "false" or an empty string to be off, and "1", "yes" or "true" to be on. that's it, that's the whole system πŸŽ€

  • OPAMALLPARENS β€” surround all filters with parenthesis. yes ma'am, maximum parentheses, we love a full enclosure πŸ’…
  • OPAMASSUMEDEPEXTS β€” see option --assume-depexts.
  • OPAMAUTOANSWER β€” internal use only. don't touch, that's not yours πŸ™ˆ
  • 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.
  • OPAMBUILDDOC β€” Removed in 2.1. gone, deceased, no longer with us πŸ’€
  • OPAMBUILDTEST β€” Removed in 2.1. same energy, also gone πŸ’€
  • OPAMCLI β€” see option `--cli'.
  • OPAMCOLOR β€” when set to always or never, sets a default value for the `--color' option.
  • OPAMCONFIRMLEVEL β€” see option --confirm-level. heads up: OPAMCONFIRMLEVEL has priority over OPAMYES and OPAMNO. it's the main character here πŸ‘‘
  • OPAMCRITERIA β€” specifies user preferences for dependency solving. the default value depends on the solver version, so use `config report' to know the current setting. see also option --criteria.
  • OPAMCUDFFILE β€” save the cudf graph to file-actions-explicit.dot.
  • OPAMCUDFTRIM β€” controls the filtering of unrelated packages during CUDF preprocessing.
  • 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'.
  • OPAMDIGDEPTH β€” defines how aggressive the lookup for conflicts during CUDF preprocessing is.
  • OPAMDOWNLOADJOBS β€” sets the maximum number of simultaneous downloads.
  • OPAMDROPWORKINGDIR β€” overrides packages previously updated with --working-dir on update. without this variable set, opam would keep them unchanged unless explicitly named on the command-line.
  • OPAMDRYRUN β€” see option `--dry-run'.
  • OPAMEDITOR β€” sets the editor to use for opam file editing, and it 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.
  • OPAMFIXUPCRITERIA β€” same as OPAMUPGRADECRITERIA, but specific to fixup and reinstall. it's the specialised sibling, iykyk ✨
  • OPAMIGNOREAVAILABLE β€” see install option `--ignore-available-on'.
  • OPAMIGNORECONSTRAINTS β€” see install option `--ignore-constraints-on'.
  • OPAMIGNOREPINDEPENDS β€” see option `--ignore-pin-depends'.
  • OPAMINPLACEBUILD β€” see option `--inplace-build'.
  • OPAMJOBS β€” sets the maximum number of parallel workers to run.
  • OPAMJSON β€” log json output to the given file (use character % to index the files).
  • OPAMKEEPBUILDDIR β€” see 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 to get more reliable backtraces.
  • 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.
  • OPAMMERGEOUT β€” merge process outputs, stderr on stdout.
  • OPAMNO β€” answer no to any question asked, see options --no and --confirm-level. careful bestie: OPAMNO is ignored if either OPAMCONFIRMLEVEL or OPAMYES is set.
  • OPAMNOAGGREGATE β€” with `opam admin check', don't aggregate packages.
  • OPAMNOASPCUD β€” Deprecated. it's giving legacy πŸ’€
  • OPAMNOAUTOUPGRADE β€” disables automatic internal upgrade of repositories in an earlier format to the current one, on 'update' or 'init'.
  • OPAMNOCHECKSUMS β€” enables option --no-checksums when available.
  • OPAMNODEPEXTS β€” disables system dependencies handling, see option `--no-depexts'.
  • OPAMNOENVNOTICE β€” Internal. not for you πŸ™ˆ
  • 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.
  • OPAMPREPRO β€” set this to false to disable CUDF preprocessing. less efficient, but might help debugging solver issue.
  • 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 operation are done in-memory, no I/O for scanning the repository. speed queen behaviour ✨
  • OPAMREQUIRECHECKSUMS β€” enables option --require-checksums' when available (e.g. for opam install').
  • OPAMRETRIES β€” sets the number of tries before failing downloads.
  • OPAMREUSEBUILDDIR β€” see option `--reuse-build-dir'.
  • 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. do not make this your personality fr fr.
  • 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 to 0 for unlimited. note that all solvers may not support this option.
  • OPAMSOLVERTOLERANCE β€” changes the tolerance towards the solver choosing an unoptimized solution (i.e. might pull outdated packages). 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 all solvers may not support this option.
  • OPAMSTATS β€” Removed in 2.4. rip πŸ’€
  • 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.).
  • 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 β€” Removed in 2.2. ✝️
  • 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 macOS only. πŸͺ iconic honestly
  • OPAMVALIDATIONHOOK β€” if set, uses the %{hook}% command to validate an opam repository update.
  • OPAMVERBOSE β€” see option `--verbose'.
  • OPAMVERBOSEON β€” see option --verbose-on
  • OPAMVERSIONLAGPOWER β€” do not use. like, genuinely, bestie, don't 😭
  • OPAMWITHDEVSETUP β€” see install option `--with-dev-setup'.
  • OPAMWITHDOC β€” see install option `--with-doc'.
  • OPAMWITHTEST β€” see install option `--with-test.
  • OPAMWORKINGDIR β€” see option `--working-dir'.
  • OPAMYES β€” see options --yes' and --confirm-level. OPAMYEShas <hotpink>priority</hotpink> overOPAMNOand is ignored ifOPAMCONFIRMLEVEL` 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 bit is actually so important, listen up 🫢

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. no more writing stale tutorials in 2020 and watching them rot, we love a girl who future-proofs πŸ’…

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

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 (or 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. she's warning you out of love, ok? πŸŽ€

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, like a group chat vote πŸ‘‘


πŸ’₯ EXIT STATUS πŸ’₯

Okay bestie, so here's the tea β€” the exit codes. But first, one big heads up, an exception to literally everything below:

The exec command is not like the others. When you run exec, it returns 127 if the command wasn't found or couldn't be executed, and otherwise it hands you back the command's own exit value. Demure. Different. Slay. πŸŽ€

Now the regular codes, one by one, no skipping:

  • 0 β€” Success, or true for boolean queries. Living your best life ✨
  • 1 β€” False. This one shows up when a boolean return value is what's expected, like when you're running with --check, or for queries like opam lint. It's giving "no babe".
  • 2 β€” Bad command-line arguments, or command-line arguments pointing to an invalid context (e.g. a file that isn't following the expected format). Rude of you honestly πŸ™ˆ
  • 5 β€” Not found. You asked for something (package, version, repository, etc.) and it just… wasn't there. πŸ’€
  • 10 β€” Aborted. The operation needed confirmation and you didn't give it. She needed a yes and got silence.
  • 15 β€” Could not acquire the locks required for the operation. The lock said no. πŸ”’
  • 20 β€” There is no solution to the user request. This can happen when you ask to install two incompatible packages, for example. Math said no, bestie.
  • 30 β€” Error in package definition, or other metadata files. Heads up: using --strict raises this error more often. πŸ‘€
  • 31 β€” Package script error. Some package operations were unsuccessful. This may be an error in the packages themselves or an incompatibility with your system. Noteworthy: this can be a partial error.
  • 40 β€” Sync error. Couldn't fetch some remotes from the network. Also can be a partial error. The wifi girlies are in shambles. 😭
  • 50 β€” Configuration error. Opam or system configuration doesn't allow the operation, and it needs fixing. Bestie you gotta go fix it fr fr.
  • 60 β€” Solver failure. The solver failed to return a sound answer. This can be due to a broken external solver, or an error in the solver configuration. The solver simply did not eat. πŸ’…
  • 99 β€” Internal error. Something went wrong, and it's likely due to a bug in opam itself. Not your fault, icon behavior on your part, chaos on theirs.
  • 130 β€” User interrupt. SIGINT was received, generally because the user pressed Ctrl+C. You did this. You know you did this. πŸ™ˆ

And then these three, chilling separately:

  • 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 πŸ“–

Need more? More exists, and it's gorgeous: see https://opam.ocaml.org/doc. Go be a scholar. πŸ¦‹


πŸ‘‘ AUTHORS πŸ‘‘

The literal legends who made this happen, show them some respect:

  • 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>

The way they all pulled up to build opam… main character energy across the board, no cap. 🌈✨


πŸ”— SEE ALSO πŸ”—

That's it, that's the whole clique. Iykyk. πŸ’œ


πŸ› BUGS πŸ›

Found something cursed? First of all, valid. Check bug reports at https://github.com/ocaml/opam/issues 🫢


This was Opam 2.6.1, documented as OPAM-ENV(1). That's the whole chapter, bestie β€” go forth and export something iconic. periodt πŸ’…
πŸ“¦ where this page comes from