OPAM-EXEC(1)

πŸ’– OPAM-EXEC πŸ’–

okay bestie, welcome to the OPAM-EXEC(1) page from the Opam Manual ✨ this is the one that runs stuff in the right env, and it's lowkey iconic. buckle up πŸŽ€


🌸 NAME 🌸

opam-exec β€” Executes a command in the proper opam environment


πŸ¦‹ SYNOPSIS πŸ¦‹

opam exec [OPTION]… COMMAND [ARG]……

✨ DESCRIPTION ✨

So basically: you run COMMAND and opam makes sure it gets the correct environment variables 🫢. That's the whole vibe.

The way that this is also how you cross-compile between switches is by doing:

opam config exec --switch=SWITCH -- COMMAND ARG1 ... ARGn

Opam expansion happens inside the command and the args, so don't be shocked when things get expanded on you πŸ’….

If there's no switch on the command line and no switch in the OPAMSWITCH environment variable, then OPAMSWITCH just… doesn't get set in COMMAND's environment. no cap πŸ™ˆ that's literally what it says.

Oh and heads up: this is a shortcut, and it's equivalent to opam config exec ✨


πŸ‘‘ OPTIONS πŸ‘‘

  • --inplace-path β€” When opam updates the PATH variable, this makes it replace any pre-existing opam path in-place instead of yeeting the new path in front. Consequence? Programs installed in opam that were shadowed will remain shadowed after opam env. so yeah, that's the tradeoff bestie 😭
  • --no-switch β€” Execute the command with the updates that opam did to the environment reverted instead. like a lil undo button πŸ’€
  • --set-root β€” With the env and exec subcommands, this also sets the OPAMROOT variable, so you can be sure any further calls to opam will use the same root πŸ”₯
  • --set-switch β€” With the env and exec subcommands, this also sets the OPAMSWITCH variable, making sure further calls to opam use the same switch as this one 🫢

🌈 COMMON OPTIONS 🌈

These ones are common to all commands, so they show up everywhere like that one friend who's at every party πŸ’œ

  • --best-effort β€” Don't fail if all the requested packages can't be installed: just try to install as many as possible. Fair warning, not all external solvers support this (recent versions of aspcud or mccs should though). It's 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.), and any version of opam in the same MAJOR series will behave as it would for the specified MINOR release. Important lore: the flag was not available in opam 2.0, so if you want 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. cute output only πŸ’…
  • --confirm-level=LEVEL β€” Confirmation level, and 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. This is equivalent to setting $OPAMCONFIRMLEVEL. 😌
  • --criteria=CRITERIA β€” Specify user preferences for dependency solving for this run. It overrides $OPAMCRITERIA, $OPAMFIXUPCRITERIA and $OPAMUPGRADECRITERIA. For the details on the supported language and the external solvers available, go look at http://opam.ocaml.org/doc/External_solvers.html. And there's a general guide to using solver preferences at http://www.dicosmo.org/Articles/usercriteria.pdf. iykyk πŸ“š
  • --cudf=FILENAME β€” Debug option bestie: saves 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. very detective of you πŸ•΅οΈ
  • --debug β€” Print debug messages to stderr. This is equivalent to setting $OPAMDEBUG to "true".
  • --debug-level=LEVEL β€” Like --debug, but it lets you specify 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 it's set (i.e. you're using a development version), and exit. bye ✌️
  • --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, whether that happened 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. data girlies rise πŸ“
  • --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. she's gone bestie πŸ’€
  • --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. 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 that behaviour. main character opam staying in her lane πŸ‘‘
  • -q, --quiet β€” Disables --verbose. shhh 🀫
  • --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. Super 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. 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. no more vibing past your problems πŸ’…
  • --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, and repeating it also displays commands called internally (e.g. tar, curl, patch etc.). Repeating it n times is equivalent to setting $OPAMVERBOSE to "n". tell me everything bestie 😭
  • --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're pointing to. Heads up: 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 β€” Answer yes to all opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMYES to "true". periodt πŸ’…

🌿 ENVIRONMENT 🌿

ok so bestie, opam is very into environment variables, and here's the whole list, no cap. one thing first: for the boolean ones, set them to "0", "no", "false" or just the empty string to turn them off, and "1", "yes" or "true" to turn them on. periodt. πŸ’…

  • OPAMALLPARENS β€” surround all filters with parenthesis, every last one. yes queen, all of them. ✨
  • OPAMASSUMEDEPEXTS β€” literally just see the --assume-depexts option, it's the same vibe. πŸ¦‹
  • OPAMAUTOANSWER β€” internal use only, so don't touch, this one's not for us. πŸ™ˆ
  • OPAMAUTOREMOVE β€” check the --auto-remove option on remove, that's the one. 😌
  • OPAMBESTEFFORT β€” see the --best-effort option. 🫢
  • OPAMBESTEFFORTPREFIXCRITERIA β€” sets the string that has to be prepended to the criteria when --best-effort is on, and it's supposed to maximise the opam-query property in the solution. iconic behaviour honestly. πŸ’–
  • OPAMBUILDDOC β€” Removed in 2.1. rip to her. πŸ’€
  • OPAMBUILDTEST β€” Removed in 2.1. also gone, also mourned. πŸ₯€
  • OPAMCLI β€” see the --cli option. 🌈
  • OPAMCOLOR β€” when you set it to always or never, it gives a default value to the --color option. easy. πŸŽ€
  • OPAMCONFIRMLEVEL β€” see --confirm-level. and heads up, OPAMCONFIRMLEVEL has priority over OPAMYES and OPAMNO, so she wins every argument. πŸ’…
  • OPAMCRITERIA β€” your user preferences for dependency solving, bestie. the default value depends on the solver version, so run config report if you wanna know the current setting. also see the --criteria option. ⭐
  • OPAMCUDFFILE β€” saves the cudf graph to file-actions-explicit.dot. cute little artifact. ✨
  • OPAMCUDFTRIM β€” controls the filtering of unrelated packages during CUDF preprocessing. 🧚
  • OPAMCURL β€” pick which curl program you want. for more options check OPAMFETCH below. πŸŒ€
  • OPAMDEBUG β€” see options --debug and --debug-level. πŸ‘‘
  • OPAMDEBUGSECTIONS β€” if set, it limits debug messages to the space-separated list of sections. sections can optionally have their own specific debug level (like CLIENT:2 or CLIENT CUDF:2), but otherwise just use --debug-level. πŸ’œ
  • OPAMDIGDEPTH β€” defines how aggressive the lookup for conflicts is during CUDF preprocessing. she's thorough. πŸ”₯
  • OPAMDOWNLOADJOBS β€” sets the max number of simultaneous downloads. multitasking queen. 🌸
  • 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. so yes it's petty like that. πŸ’…
  • OPAMDRYRUN β€” see the --dry-run option. ✨
  • OPAMEDITOR β€” sets the editor to use for opam file editing, and it overrides $EDITOR and $VISUAL. sorry to them but she said it. πŸŽ€
  • OPAMERRLOGLEN β€” sets how many log lines get printed when a sub-process fails. 0 prints all of them, no filter. 😭
  • OPAMEXTERNALSOLVER β€” see the --solver option. πŸ¦‹
  • OPAMFAKE β€” see the --fake option. 🫢
  • OPAMFETCH β€” tells opam how to download files: either wget, curl, or a custom command where %{url}%, %{out}%, %{retry}%, %{compress}% and %{checksum}% get replaced. this overrides the download-command value from the main config file. 🌈
  • OPAMFIXUPCRITERIA β€” same energy 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 max number of parallel workers to run. πŸ’ͺ
  • 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 to get more reliable backtraces. πŸ’œ
  • OPAMLOCKED β€” a combo of the --locked and --lock-suffix options. two for one. πŸ”₯
  • 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, so stderr goes onto stdout. 😌
  • OPAMNO β€” answers no to any question asked, see options --no and --confirm-level. and jsyk, OPAMNO is ignored if either OPAMCONFIRMLEVEL or OPAMYES is set. πŸ™ˆ
  • OPAMNOAGGREGATE β€” with opam admin check, don't aggregate packages. 🚫
  • OPAMNOASPCUD β€” Deprecated. πŸ’€
  • OPAMNOAUTOUPGRADE β€” disables the automatic internal upgrade of repositories in an earlier format to the current one, which normally happens on update or init. 🌸
  • OPAMNOCHECKSUMS β€” enables option --no-checksums when it's available. ✨
  • OPAMNODEPEXTS β€” disables system dependencies handling, see option --no-depexts. πŸ¦‹
  • OPAMNOENVNOTICE β€” Internal. 🫢
  • 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, so she's been the default for a while. πŸ’–
  • OPAMPRECISETRACKING β€” fine grain tracking of directories. πŸ”
  • OPAMPREPRO β€” set this to false to disable CUDF preprocessing. less efficient, but might help you debug a solver issue. the tradeoff is real. βš–οΈ
  • 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, no I/O for scanning the repository. slay. πŸ”₯
  • OPAMREQUIRECHECKSUMS β€” enables option --require-checksums when it's available (e.g. for opam install). πŸŽ€
  • OPAMRETRIES β€” sets the number of tries before downloads fail. she's persistent. πŸ’ͺ
  • 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. she'll keep quiet. 🀫
  • OPAMSAFE β€” see option --safe. πŸ›‘οΈ
  • OPAMSHOW β€” see option --show. πŸ‘€
  • OPAMSKIPUPDATE β€” see option --skip-updates. ⏭️
  • OPAMSKIPVERSIONCHECKS β€” bypasses some version checks. Unsafe, for compatibility testing only. (so like… don't unless you know, bestie.) ⚠️
  • OPAMSOLVERALLOWSUBOPTIMAL β€” (default true) allows some solvers to still return a solution when they hit timeout; while the solution remains assured to be consistent, there's 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. 🧚
  • OPAMSOLVERTIMEOUT β€” changes 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, so keep expectations realistic. ⏳
  • OPAMSOLVERTOLERANCE β€” changes the tolerance towards the solver choosing an unoptimized solution (i.e. it 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 one is useful when 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. she's at peace now. πŸ’€
  • OPAMSTATUSLINE β€” displays a dynamic status line showing what's currently going on on the terminal. (one of one of always, never or auto) β€” yes the original says "one of" twice, and yes we're keeping it, character for character, iykyk. 😭
  • OPAMSTRICT β€” fail on inconsistencies (file reading, switch import, etc.). no chill, no mercy. πŸ”₯
  • OPAMSWITCH β€” see option --switch. automatically set by opam env --switch=SWITCH --set-switch. πŸ”„
  • OPAMUNLOCKBASE β€” see the install option --unlock-base. πŸ”“
  • OPAMUPGRADECRITERIA β€” your user preferences for dependency solving when doing an upgrade. it overrides OPAMCRITERIA in upgrades if both are set. also see 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 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 iconic, we don't make the rules. πŸŽ€
  • 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. that's it, that's the whole thing. πŸ™ˆ
  • OPAMWITHDEVSETUP β€” see the install option --with-dev-setup. πŸ› οΈ
  • OPAMWITHDOC β€” see the install option --with-doc. πŸ“š
  • OPAMWITHTEST β€” see the install option --with-test. πŸ§ͺ
  • OPAMWORKINGDIR β€” see option --working-dir. πŸ“‚
  • OPAMYES β€” see options --yes and --confirm-level. OPAMYES has priority over OPAMNO and is ignored if OPAMCONFIRMLEVEL is set. so the hierarchy is: OPAMCONFIRMLEVEL > OPAMYES > OPAMNO. πŸ’…
  • 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 πŸ¦‹

ok so this section is important, listen up. all scripts and programmatic invocations of opam should use --cli so that they work seamlessly with future versions of the opam client. not optional, bestie, it's the move. πŸ’…

bonus: blog posts or other documentation can benefit too, because it stops information from becoming stale. your old tutorial stays valid, iconic. ✨

even though opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface. so she's flexible like that. 🫢

since CLI version support was only added in opam 2.1, use OPAMCLI to select 2.0 support (because opam 2.0 will just ignore it, bless her), and --cli=2.1 for 2.1 (or later) versions β€” because an environment variable controlling the parsing of syntax is brittle. that's the whole reason. 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. it's just keeping you honest. 😌

the command-line version gets selected by using the --cli option or the OPAMCLI environment variable. and the way that --cli may be specified morethan once, where the last instance takes precedence β€” yes the original says morethan, we're keeping it, character for character, don't look at me. 😭 and OPAMCLI is only inspected if --cli is not given. 🌸

πŸ’€ EXIT STATUS πŸ’€

okay bestie, here's the tea on how opam says goodbye. every exit code is a little vibe check of what just went down. πŸ‘‘

BIG EXCEPTION ALERT: the exec command does not play by these rules. exec returns 127 if the command was not found or couldn't be executed, and the command's exit value otherwise. that's it, that's the whole rule. periodt. πŸ’…

now for everyone else:

  • 0 β€” Success, or true for boolean queries. slay, we ate. ✨
  • 1 β€” False. Returned when a boolean return value is expected, e.g. when running with --check, or for queries like opam lint. nope, not today. πŸ™ˆ
  • 2 β€” Bad command-line arguments, or command-line arguments pointing to an invalid context (e.g. file not following the expected format). you did what now 😭
  • 5 β€” Not found. You requested something (package, version, repository, etc.) that couldn't be found. it's giving lost in the sauce πŸ¦‹
  • 10 β€” Aborted. The operation required confirmation, which wasn't given. lowkey you ghosted it πŸ’€
  • 15 β€” Could not acquire the locks required for the operation. someone else is holding the aux cord πŸ”’
  • 20 β€” There is no solution to the user request. This can be caused by asking to install two incompatible packages, for example. bestie these two are NOT compatible, i fear 🌸
  • 30 β€” Error in package definition, or other metadata files. Using --strict raises this error more often. the metadata is messy fr fr
  • 31 β€” 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. so close yet so far πŸ˜”
  • 40 β€” Sync error. Could not fetch some remotes from the network. This can be a partial error. the network said no 🌈
  • 50 β€” Configuration error. Opam or system configuration doesn't allow operation, and needs fixing. config is not configing πŸŽ€
  • 60 β€” 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. the solver is going through it πŸ’œ
  • 99 β€” Internal error. Something went wrong, likely due to a bug in opam itself. not opam being the problem for once 😭
  • 130 β€” User interrupt. SIGINT was received, generally due to the user pressing Ctrl+C. you pressed the panic button, iconic πŸ’…

and then there's this lil extra crew, for the other errors:

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

go read the docs, they're right here: https://opam.ocaml.org/doc. obsessed, honestly. 🫢


πŸ‘‘ AUTHORS πŸ‘‘

the absolute legends who built this, no cap:

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

🌟 SEE ALSO 🌟

  • opam(1) β€” the main character, obviously. go say hi. πŸ’–

πŸ› BUGS πŸ›

found something cursed? check the bug reports at https://github.com/ocaml/opam/issues. tell them everything, they'll fix it, queen behavior. πŸ’œ


okay that's the whole page bestie!! this was Opam 2.6.1, page OPAM-EXEC(1). thanks for reading, you're literally the main character of your own terminal now. mwah πŸ’‹βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from