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 with0if your environment is already up-to-date, and1if 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 thePATHvariable, 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 afteropam env. no cap.--revertβ outputs the environment with the updates opam did reverted instead. undo era π--set-rootβ with theenvandexecsubcommands, also sets theOPAMROOTvariable, so every further call to opam uses the same root. consistency slay. π--set-switchβ with theenvandexecsubcommands, also sets theOPAMSWITCHvariable, 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 ofbash,sh,csh,zsh,fish,pwsh,cmdorpowershell. by default it's guessed from the parent processes and the$SHELLvariable. β¨
β¨ 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 ofaspcudormccsshould). equivalent to setting the$OPAMBESTEFFORTenvironment 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 theOPAMCLIenvironment variable to2.0instead of using this parameter. β--color=WHENβ colorizes the output. WHEN has to be one ofalways,neverorauto. π--confirm-level=LEVELβ confirmation level. LEVEL must be one ofask,no,yesorunsafe-yes. can be specified more than once. if--yesor--noare also given, the value of the last--confirm-levelis what counts. equivalent to setting$OPAMCONFIRMLEVEL. π--criteria=CRITERIAβ specify your user preferences for dependency solving for this run. this overrides$OPAMCRITERIA,$OPAMFIXUPCRITERIAand$OPAMUPGRADECRITERIA. for the deets on the supported language and the external solvers available, seehttp://opam.ocaml.org/doc/External_solvers.html. a general guide to using solver preferences lives athttp://www.dicosmo.org/Articles/usercriteria.pdf. π§--cudf=FILENAMEβ debug option: saves the CUDF requests sent to the solver intoFILENAME-<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$OPAMDEBUGto"true". π--debug-level=LEVELβ like--debug, but you get to pick the debug level (--debugjust sets it to1). equivalent to setting$OPAMDEBUGto 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 ofauto,pager,grofforplain. withauto, the format ispagerorplainwhenever theTERMenv var isdumbor undefined. π--ignore-pin-dependsβ ignores extra pins required by packages that get pinned, whether manually throughopam pinor throughopam install DIR. equivalent to settingIGNOREPINDEPENDS=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$OPAMJSONvariable. β¨--noβ answers no to all opam yes/no questions without prompting. see also--confirm-level. equivalent to setting$OPAMNOto"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 arepofile 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 usingopam admin upgrade [--mirror URL]when possible. π--no-self-upgradeβ opam will replace itself with a newer binary found atOPAMROOT/opamif present. this disables that behaviour. β-q,--quietβ disables--verbose. shhh π€«--root=ROOTβ use ROOT as the current root path. equivalent to setting$OPAMROOTto 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$OPAMDEBUGvariable. 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 supportsbuiltin-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$OPAMSWITCHto 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$OPAMNOASPCUDor$OPAMUSEINTERNALSOLVER. π§-v,--verboseβ be more verbose. one-vshows all package commands; repeat it to also display commands called internally (e.g.tar,curl,patchetc.). repeating it n times is equivalent to setting$OPAMVERBOSEto"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$OPAMYESto"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 theopam-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:OPAMCONFIRMLEVELhas priority overOPAMYESandOPAMNO. 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. seeOPAMFETCHfor 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:2orCLIENT 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-diron 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$EDITORand$VISUAL.OPAMERRLOGLENβ sets the number of log lines printed when a sub-process fails.0to print all.OPAMEXTERNALSOLVERβ see option `--solver'.OPAMFAKEβ see option `--fake'.OPAMFETCHβ specifies how to download files: eitherwget',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 asOPAMUPGRADECRITERIA, 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--noand--confirm-level. careful bestie:OPAMNOis ignored if eitherOPAMCONFIRMLEVELorOPAMYESis 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. foropam install').OPAMRETRIESβ sets the number of tries before failing downloads.OPAMREUSEBUILDDIRβ see option `--reuse-build-dir'.OPAMROOTβ see option--root'. this is automatically set byopam 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β (defaulttrue) 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. iftrue, opam willcontinue with a warning, iffalsea timeout is an error. currently only the builtin-z3 backend handles this degraded case.OPAMSOLVERTIMEOUTβ change the time allowance of the solver. default is60.0, set to0for 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 from0.0(best solution known to the solver) to1.0(unoptimized solution). default is0.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 byopam env --switch=SWITCH --set-switch'.OPAMUNLOCKBASEβ see install option `--unlock-base'.OPAMUPGRADECRITERIAβ specifies user preferences for dependency solving when performing an upgrade. OverridesOPAMCRITERIAin 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. impliesOPAMUTF8. this is set by default on macOS only. πͺ iconic honestlyOPAMVALIDATIONHOOKβ if set, uses the%{hook}%command to validate an opam repository update.OPAMVERBOSEβ see option `--verbose'.OPAMVERBOSEONβ see option --verbose-onOPAMVERSIONLAGPOWERβ 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 inopamfiles.OPAMVAR_package_varβ overrides the contents of the variable package:var when substituting%{package:var}%strings inopamfiles.
π 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:
Theexeccommand is not like the others. When you runexec, it returns127if 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, ortruefor 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 likeopam 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--strictraises 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.SIGINTwas 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 asOPAM-ENV(1). That's the whole chapter, bestie β go forth andexportsomething iconic. periodt π
π¦ where this page comes from
- arch rolling: opam 2.6.1-1 Β· LGPL-2.1-only
- fedora 44: opam 2.6.1-1.fc44 Β· LGPL-2.1-only WITH OCaml-LGPL-linking-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms