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 thePATHvariable, 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 afteropam 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 theenvandexecsubcommands, this also sets theOPAMROOTvariable, so you can be sure any further calls to opam will use the same root π₯--set-switchβ With theenvandexecsubcommands, this also sets theOPAMSWITCHvariable, 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 ofaspcudormccsshould though). It's equivalent to setting the$OPAMBESTEFFORTenvironment variable.--cli=MAJOR.MINOR(absent=2.6) β Use the command-line interface syntax and semantics ofMAJOR.MINOR. This is intended for any persistent use of opam (scripts, blog posts, etc.), and any version of opam in the sameMAJORseries will behave as it would for the specifiedMINORrelease. Important lore: the flag was not available in opam 2.0, so if you want the 2.0 CLI, set theOPAMCLIenvironment variable to2.0instead of using this parameter π--color=WHENβ Colorize the output.WHENmust be one ofalways,neverorauto. cute output only π--confirm-level=LEVELβ Confirmation level, andLEVELmust 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. This is equivalent to setting$OPAMCONFIRMLEVEL. π--criteria=CRITERIAβ Specify user preferences for dependency solving for this run. It overrides$OPAMCRITERIA,$OPAMFIXUPCRITERIAand$OPAMUPGRADECRITERIA. For the details on the supported language and the external solvers available, go look athttp://opam.ocaml.org/doc/External_solvers.html. And there's a general guide to using solver preferences athttp://www.dicosmo.org/Articles/usercriteria.pdf. iykyk π--cudf=FILENAMEβ Debug option bestie: saves the CUDF requests sent to the solver toFILENAME-<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$OPAMDEBUGto"true".--debug-level=LEVELβ Like--debug, but it lets you specify the debug level (--debugsets it to1). Equivalent to setting$OPAMDEBUGto 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 formatFMT. The valueFMTmust be one ofauto,pager,grofforplain. Withauto, the format ispagerorplainwhenever theTERMenv var isdumbor undefined. π--ignore-pin-dependsβ Ignore extra pins required by packages that get pinned, whether that happened manually throughopam pinor throughopam install DIR. This is equivalent to settingIGNOREPINDEPENDS=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$OPAMJSONvariable. data girlies rise π--noβ Answer no to all opam yes/no questions without prompting. See also--confirm-level. This is equivalent to setting$OPAMNOto"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 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. main character opam staying in her lane π-q,--quietβ Disables--verbose. shhh π€«--root=ROOTβ UseROOTas the current root path. This is equivalent to setting$OPAMROOTtoROOT.--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$OPAMDEBUGvariable. 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 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}%. 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β UseSWITCHas the current compiler switch. This is equivalent to setting$OPAMSWITCHtoSWITCH.--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$OPAMNOASPCUDor$OPAMUSEINTERNALSOLVER. β¨-v,--verboseβ Be more verbose. One-vshows all package commands, and repeating it also displays commands called internally (e.g.tar,curl,patchetc.). Repeating it n times is equivalent to setting$OPAMVERBOSEto"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$OPAMYESto"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-depextsoption, it's the same vibe. π¦OPAMAUTOANSWERβ internal use only, so don't touch, this one's not for us. πOPAMAUTOREMOVEβ check the--auto-removeoption onremove, that's the one. πOPAMBESTEFFORTβ see the--best-effortoption. π«ΆOPAMBESTEFFORTPREFIXCRITERIAβ sets the string that has to be prepended to the criteria when--best-effortis on, and it's supposed to maximise theopam-queryproperty 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--clioption. πOPAMCOLORβ when you set it toalwaysornever, it gives a default value to the--coloroption. easy. πOPAMCONFIRMLEVELβ see--confirm-level. and heads up,OPAMCONFIRMLEVELhas priority overOPAMYESandOPAMNO, so she wins every argument. πOPAMCRITERIAβ your user preferences for dependency solving, bestie. the default value depends on the solver version, so runconfig reportif you wanna know the current setting. also see the--criteriaoption. βOPAMCUDFFILEβ saves the cudf graph tofile-actions-explicit.dot. cute little artifact. β¨OPAMCUDFTRIMβ controls the filtering of unrelated packages during CUDF preprocessing. π§OPAMCURLβ pick whichcurlprogram you want. for more options checkOPAMFETCHbelow. πOPAMDEBUGβ see options--debugand--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 (likeCLIENT:2orCLIENT 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-dironupdate. 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-runoption. β¨OPAMEDITORβ sets the editor to use for opam file editing, and it overrides$EDITORand$VISUAL. sorry to them but she said it. πOPAMERRLOGLENβ sets how many log lines get printed when a sub-process fails.0prints all of them, no filter. πOPAMEXTERNALSOLVERβ see the--solveroption. π¦OPAMFAKEβ see the--fakeoption. π«ΆOPAMFETCHβ tells opam how to download files: eitherwget,curl, or a custom command where%{url}%,%{out}%,%{retry}%,%{compress}%and%{checksum}%get replaced. this overrides thedownload-commandvalue from the main config file. πOPAMFIXUPCRITERIAβ same energy asOPAMUPGRADECRITERIA, but specific tofixupandreinstall. πOPAMIGNOREAVAILABLEβ see the install option--ignore-available-on. πΈOPAMIGNORECONSTRAINTSβ see the install option--ignore-constraints-on. π§OPAMIGNOREPINDEPENDSβ see the--ignore-pin-dependsoption. βOPAMINPLACEBUILDβ see the--inplace-buildoption. π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--lockedand--lock-suffixoptions. two for one. π₯OPAMLOGSβlogdirsets 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--noand--confirm-level. and jsyk,OPAMNOis ignored if eitherOPAMCONFIRMLEVELorOPAMYESis set. πOPAMNOAGGREGATEβ withopam 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 onupdateorinit. πΈOPAMNOCHECKSUMSβ enables option--no-checksumswhen 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 tofalseto disable CUDF preprocessing. less efficient, but might help you debug a solver issue. the tradeoff is real. βοΈOPAMREPOSITORYTARRINGβ internally store all non-vcs repositories astar.gzfiles (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-checksumswhen it's available (e.g. foropam 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 byopam 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β (defaulttrue) 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. iftrue, opam will continue with a warning; iffalse, a timeout is an error. currently only the builtin-z3 backend handles this degraded case. π§OPAMSOLVERTIMEOUTβ changes the time allowance of the solver. default is60.0, set it to0for 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 from0.0(best solution known to the solver) to1.0(unoptimized solution). default is0.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 ofalways,neverorauto) β 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 byopam env --switch=SWITCH --set-switch. πOPAMUNLOCKBASEβ see the install option--unlock-base. πOPAMUPGRADECRITERIAβ your user preferences for dependency solving when doing an upgrade. it overridesOPAMCRITERIAin 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 ofalways,neverorauto). by default it'sauto, which is determined from the locale. β¨OPAMUTF8MSGSβ use extended UTF8 characters (camels πͺ) in opam messages. impliesOPAMUTF8. 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--yesand--confirm-level.OPAMYEShas priority overOPAMNOand is ignored ifOPAMCONFIRMLEVELis set. so the hierarchy is:OPAMCONFIRMLEVEL>OPAMYES>OPAMNO. π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 π¦
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: theexeccommand does not play by these rules.execreturns127if 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 likeopam 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--strictraises this error more often. the metadata is messy fr fr31β 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.SIGINTwas 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
- 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