OPAM-SWITCH(1)
β¨ NAME β¨
opam-switch β the one that manages multiple installation prefixes π
(this is part of the Opam Manual, bestie, so you know it's official)
π¦ SYNOPSIS π¦
opam switch [OPTION]β¦ [COMMAND] [ARG]β¦
πΈ DESCRIPTION πΈ
Okay so, this command is literally the switch manager. A "switch" is an independent installation prefix β it's got its own compiler, its own set of installed packages, and its own set of pinned packages. Nothing bleeds between them, which is the whole point. The classic use case: you want different versions of the compiler hanging around at the same time. Iconic. π
Use opam switch create to create a new switch, and opam switch set to set the currently active one. With no argument at all, it just lists your installed switches. With exactly one switch argument, it defaults to set. Periodt.
Now, whenever you see SWITCH in this page, it can be either of these two things:
- a plain name, for switches that live inside
~/.opam, or - a directory name β and in that case, that directory is where the switch prefix gets installed, as
_opam.
Opam will automatically pick a switch by that name if it finds one in the current directory or any of its parents β unless OPAMSWITCH is set or you passed --switch. And oh, when you're creating a directory switch, if there are package definitions sitting locally, the user gets automatically prompted to install them right after the switch is created. Unless you passed --no-install. π
opam switch set sets the default switch globally. The shell hook, when it's enabled, keeps your current shell session in sync with that switch β unless the current directory is a local switch, in which case that local switch wins instead. And you can always use eval $(opam env --switch=SWITCH --set-switch) to name the switch explicitly, which overrides the shell hook. No cap.
π« COMMANDS π«
With no argument, it defaults to list.
SWITCH
With a SWITCH argument, this defaults to set SWITCH.
-
Switches back to the previous non-local switch (basically like git switch -). If you actually want to set the current switch to a switch literally named -, then you gotta use --cli=2.1 or lower, or use opam switch set -.
create SWITCH [COMPILER]
Create a new switch, and install the given compiler in it. SWITCH can be a plain name, or a directory β absolute or relative β and in that case a local switch gets created below the given directory. COMPILER, if you leave it out, defaults to SWITCH when it's a plain name β unless you passed --packages, --formula or --empty.
When you're creating a local switch and none of those options are present, the compiler gets chosen according to the configuration default (peep opam-init(1) for that). And if the directory you chose contains package definitions, a compatible compiler is searched within the default selection, and the packages will automatically get installed. Slay. β¨
set SWITCH
Set the currently active switch, from among the installed switches.
remove SWITCH
Removes that switch from disk. Bye bestie π
export FILE
Save the current switch state to a file. If --full is specified, it includes the metadata of all installed packages, and if --freeze is specified, it freezes all vcs to their current commit.
import FILE
Import a saved switch state. If --switch is specified and doesn't point to an existing switch, the switch will be created just for the import. Cute.
reinstall [SWITCH]
Reinstall the given compiler switch and all its packages.
list
Lists installed switches. That's it, that's the whole job. π
list-available [PATTERN]
Lists all the possible packages that are advised for installation when creating a new switch β i.e. packages with the compiler flag set. If no pattern is supplied, all versions are shown. By default, packages flagged with avoid-version or deprecated will not appear unless you give --all.
show
Prints the name of the current switch.
invariant
Prints the active switch invariant.
set-invariant PACKAGES
Updates the switch invariant β which is, like, the formula that the switch must keep verifying throughout all operations. The previous setting gets overridden. See also the options --force and --no-action. With no arguments, an invariant is just chosen automatically.
set-description STRING
Sets the description for the selected switch.
link SWITCH [DIR]
Sets a local alias for a given switch, so the switch gets automatically selected whenever you're in that directory or any descendant of it. Handy fr fr.
install SWITCH
Removed in 2.1. Use create instead.
set-base PACKAGES
Removed in 2.1. Use set-invariant instead.
π EXAMPLES π
opam switch create 4.08.0
Create a new switch called 4.08.0 and select it, with a compiler automatically selected at version 4.08.0 (note that this can fail in case there is more than one compiler matching that version).
opam switch create ./ --deps-only
Prepare a local switch for building the packages defined in ./. This scans the current directory for package definitions, chooses a compatible compiler, creates a local switch and installs the local package dependencies.
opam switch create trunk --repos default,beta=https://github.com/ocaml/ocaml-beta-repository.git ocaml-variants.4.10.0+trunk
Create a new switch called trunk, with ocaml-variants.4.10.0+trunk as compiler, with a new beta repository bound to the given URL selected besides the default one.
π₯ OPTIONS π₯
-A COMP,--alias-of=COMPβ Removed in 2.1. π--allβ Only forlist-available: show all available compilers, regardless of whether they are flagged withavoid-versionordeprecated.--deps-onlyβ When creating a local switch in a project directory (i.e. a directory containing opam package definitions), install the dependencies of the project but not the project itself. When importing a switch, do not install root packages.--description=STRINGβ Attach the given description to a switch when creating it. Use theset-descriptionsubcommand to modify the description of an existing switch.--emptyβ Allow creating an empty switch, with no invariant.--forceβ Only forset-invariant: force setting the invariant, bypassing consistency checks.--formula=FORMULAβ Lets you specify a complete "dependency formula", possibly including disjunction cases, as the switch invariant. The format is the same as for expressing dependencies in package definition files, e.g.'"foo" {>= "1.1"}'--freezeβ When exporting, locks all VCS urls to their current commit, failing if it can not be retrieved. This ensures that an import will restore the exact state. Implies--full.--fullβ When exporting, include the metadata of all installed packages, allowing you to re-import even if they don't exist in the repositories (the default is to include only the metadata of pinned packages).-n,--no-actionβ Only forset-invariant: set the invariant, but don't enforce it right away β wait for the next install, upgrade or similar command.--no-autoinstallβ Removed in 2.1. π--no-installβ When creating a local switch, don't look for any local package definitions to install.--no-switchβ Don't automatically select newly installed switches.--packages=PACKAGESβ When installing a switch, explicitly define the set of packages to enforce as the switch invariant.--repositories=REPOSβ When creating a new switch, use the given selection of repositories instead of the default.REPOSshould be a comma-separated list of either already registered repository names (configured through e.g.opam repository add --dont-select), orNAME=URLbindings β in which caseNAMEshould not be registered already to a different URL, and the new repository will be registered. Seeopam repositoryfor more details. This option also affectslist-available.-s,--shortβ Output raw lists of names, one per line, skipping any details.
π οΈ PACKAGE BUILD OPTIONS π οΈ
okay bestie this is the section where opam gets β¨opinionsβ¨ about how your packages actually get built. buckle up π
--assume-depextsβ skips the whole "install your missing system packages" step and just yolo-tries to compile the opam packages anyway. if it works out, opam will never nag you about those system packages again π«Ά. only does anything when external dependency handling is turned on, so don't expect magic otherwise.-b,--keep-build-dirβ keeps the build directories around after compiling. literally the same thing as setting$OPAMKEEPBUILDDIRto"true". hoarder energy, we respect it π--build-docβ bestie. this got removed in 2.1. use--with-docinstead, okay? don't be out here using the fossilized flag π--build-testβ also removed in 2.1 π use--with-testinstead. same deal, same vibe, new name.-d,--with-docβ builds the package docs π. heads up: this only touches packages you actually listed on the command-line. same as setting$OPAMWITHDOC(or the deprecated$OPAMBUILDDOC) to"true".--dry-runβ simulates the command but doesn't actually change anything. a rehearsal, a dress run, no consequences πΈ. can also be set with the environment variable$OPAMDEBUG.--fakeβ registers actions into the opam database without actually doing them. WARNING: this one is dangerous and is likely to break your opam environment ππ. you probably want--dry-runinstead. you've been warned, bestie, don't come crying to me.--ignore-available-on[=PACKAGES](default=) β forces opam to mark the listed packages as available. great for testing compatibility, but fr fr expect builds to break when you use this π. note that version constraints of the packages' dependencies are unaffected.--ignore-constraints-on[=PACKAGES](default=) β forces opam to ignore version constraints on all dependencies of the listed packages. again: compatibility testing tool, and again: expect builds to break π. note that the availability of the packages, plus version constraints on optional dependencies and conflicts, are all unaffected. same as setting$OPAMIGNORECONSTRAINTS.--inplace-buildβ when a package's source is bound to a local directory, does the build and install actions directly in that directory instead of in a clean copy that opam handles. only affects packages explicitly listed on the command-line. same as setting$OPAMINPLACEBUILDto"true". gettin' cozy in there π-j JOBS,--jobs=JOBSβ sets the max number of concurrent jobs. default is calculated from your core count π₯. you can also set this with the$OPAMJOBSenvironment variable.--lock-suffix=SUFFIX(absent=locked) β sets the locked files suffix to SUFFIX.--lockedβ in commands that use opam files found from pinned sources, if a variant of the file with an added.lockedextension exists (likefoo.opam.lockedsitting right next tofoo.opam), then that one gets used instead π. this is usually for offering a more specific set of dependencies and reproducing similar build contexts β hence the name, iykyk. thelockoption can generate such files based on the versions of the dependencies currently installed on your host. same as setting the$OPAMLOCKEDenvironment variable. note that this option doesn't generally affect packages that are already pinned.-m MAKE,--make=MAKEβ removed in 2.1. useopam config set[-global] make MAKEinstead, bestie β¨--no-checksumsβ do not verify the checksum of downloaded archives. same as setting$OPAMNOCHECKSUMSto"true".--no-depextsβ temporarily disables handling of external dependencies. useful when a package isn't available through your system package manager but you installed the needed dependency by hand π. this implies--assume-depexts, and it also stores the exceptions upon success. two-for-one, no cap.--require-checksumsβ rejects installation of packages that don't provide a checksum for the upstream archives. same as setting$OPAMREQUIRECHECKSUMSto"true". strict queen behavior π--reuse-build-dirβ reuses existing build directories (the ones you kept by using--keep-build-dir) instead of compiling from a fresh clone of the source. can be faster, but it can also lead to failures if the build systems of the packages don't handle upgrades of dependencies well. same as setting$OPAMREUSEBUILDDIRto"true".--show-actionsβ calls the solver and displays the actions. performs no changes. same as setting$OPAMSHOW. a peek, not a touch π--skip-updatesβ when running an install, upgrade or reinstall on source-pinned packages, they normally get updated from their origin first. this flag disables that behavior and keeps them at their version in cache. same as setting$OPAMSKIPUPDATE.-t,--with-testβ builds and runs the package unit-tests π§ͺ. only affects packages listed on the command-line. same as setting$OPAMWITHTEST(or the deprecated$OPAMBUILDTEST) to"true".--unlock-baseβ removed in 2.1. use--update-invariantinstead π--update-invariantβ allows changes to the packages set as switch base (typically, the main compiler). use with caution β οΈ. same as setting the$OPAMUNLOCKBASEenvironment variable.--verbose-on=PACKAGESβ be more verbose on specific packages. same as setting$OPAMVERBOSE.--with-dev-setupβ include development tools only dependencies.
β¨ COMMON OPTIONS β¨
okay bestie, these are the common options β the ones every command shares. like, universal vibes. no cap. π
--best-effortβ Don't fail if all requested packages can't be installed: try to install as many as possible. Note that not all external solvers may support this option (recent versions ofaspcudormccsshould). This is equivalent to setting the$OPAMBESTEFFORTenvironment variable. manifesting a partial win β¨--cli=MAJOR.MINOR(absent=2.6) β Use the command-line interface syntax and semantics ofMAJOR.MINOR. Intended for any persistent use of opam (scripts, blog posts, etc.), any version of opam in the sameMAJORseries will behave as for the specifiedMINORrelease. The flag was not available in opam 2.0, so to select the 2.0 CLI, set theOPAMCLIenvironment variable to2.0instead of using this parameter. time travel but make it CLI π°οΈ--color=WHENβ Colorize the output.WHENmust be one ofalways,neverorauto. aesthetic choices matter π--confirm-level=LEVELβ Confirmation level,LEVELmust be one ofask,no,yesorunsafe-yes. Can be specified more than once. If--yesor--noare also given, the value of the last--confirm-levelis taken into account. This is equivalent to setting$OPAMCONFIRMLEVEL. choose your own adventure π--criteria=CRITERIAβ Specify user preferences for dependency solving for this run. Overrides$OPAMCRITERIA,$OPAMFIXUPCRITERIAand$OPAMUPGRADECRITERIA. For details on the supported language, and the external solvers available, seehttp://opam.ocaml.org/doc/External_solvers.html. A general guide to using solver preferences can be found athttp://www.dicosmo.org/Articles/usercriteria.pdf. solver taste, but make it yours π--cudf=FILENAMEβ Debug option: Save the CUDF requests sent to the solver toFILENAME-<n>.cudfwhere<n>is the n-th call to the solver during the opam run. receipts, but for the solver π§Ύ--debugβ Print debug message to stderr. This is equivalent to setting$OPAMDEBUGto"true". yell it out π’--debug-level=LEVELβ Like--debug, but allows specifying the debug level (--debugsets it to1). Equivalent to setting$OPAMDEBUGto a positive integer. dial the chaos up π₯--git-versionβ Print the git version of opam, if set (i.e. you are using a development version), and exit. dev build girlies rise π οΈ--help[=FMT](default=auto) β Show this help in formatFMT. The valueFMTmust be one ofauto,pager,grofforplain. Withauto, the format ispagerorplainwhenever theTERMenv var isdumbor undefined. help is help, bestie π«Ά--ignore-pin-dependsβ Ignore extra pins required by packages that get pinned, either manually throughopam pinor throughopam install DIR. This is equivalent to settingIGNOREPINDEPENDS=true. mind your business, pins π--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. machine-readable slay π€--noβ Answer no to all opam yes/no questions without prompting. See also--confirm-level. This is equivalent to setting$OPAMNOto"true". nope, not today π--no-aspcudβ Removed in 2.1. rip bozo π--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 usingopam admin upgrade [--mirror URL]when possible. do it by hand if you can, bestie π§Ό--no-self-upgradeβ Opam will replace itself with a newer binary found atOPAMROOT/opamif present. This disables this behaviour. stay in your lane, opam π«-q,--quietβ Disables--verbose. shhh π€«--root=ROOTβ UseROOTas the current root path. This is equivalent to setting$OPAMROOTtoROOT. new home, who dis π--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$OPAMDEBUGvariable. This is equivalent to set environment variable$OPAMSAFE. look but don't touch π--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. choose your fighter βοΈ--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 sweeping under the rug π§Ή--switch=SWITCHβ UseSWITCHas the current compiler switch. This is equivalent to setting$OPAMSWITCHtoSWITCH. switch it up π--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. homegrown solver moment π±-v,--verboseβ Be more verbose. One-vshows all package commands, repeat to also display commands called internally (e.g.tar,curl,patchetc.) Repeating n times is equivalent to setting$OPAMVERBOSEto"n". say it louder for the people in the back π£--versionβ Show version information. who am i? you're opam, bestie π-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. use the messy current you π-y,--yesβ Answer yes to all opam yes/no questions without prompting. See also--confirm-level. This is equivalent to setting$OPAMYESto"true". yes queen, install everything π
πΈ ENVIRONMENT πΈ
okay so opam is lowkey obsessed with environment variables, and honestly? here's the entire roster, bestie. but first, the one rule you cannot fumble: the boolean ones want "0", "no", "false" or the empty string to be turned off, and "1", "yes" or "true" to be turned on. that's the whole vibe, no cap. β¨
OPAMALLPARENSβ surround all filters with parenthesis. yep, all of them. πOPAMASSUMEDEPEXTSβ see the option--assume-depexts.OPAMAUTOANSWERβ internal use only π (not for you, bestie).OPAMAUTOREMOVEβ see the remove option--auto-remove.OPAMBESTEFFORTβ see the option--best-effort.OPAMBESTEFFORTPREFIXCRITERIAβ sets the string that must be prepended to the criteria when the--best-effortoption is set, and is expected to maximise theopam-queryproperty in the solution.OPAMBUILDDOCβ Removed in 2.1. π gone, periodt.OPAMBUILDTESTβ Removed in 2.1. π also gone.OPAMCLIβ see the option--cli.OPAMCOLORβ when set toalwaysornever, sets a default value for the--coloroption.OPAMCONFIRMLEVELβ see the option--confirm-level. 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 useconfig reportto know the current setting. see also the option--criteria.OPAMCUDFFILEβ save the cudf graph tofile-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 the options--debugand--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-dironupdate. without this variable set, opam would keep them unchanged unless they're explicitly named on the command-line.OPAMDRYRUNβ see the 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 of them.OPAMEXTERNALSOLVERβ see the option--solver.OPAMFAKEβ see the option--fake.OPAMFETCHβ specifies how to download files: eitherwget,curlor a custom command where the 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.OPAMIGNOREAVAILABLEβ see the install option--ignore-available-on.OPAMIGNORECONSTRAINTSβ see the install option--ignore-constraints-on.OPAMIGNOREPINDEPENDSβ see the option--ignore-pin-depends.OPAMINPLACEBUILDβ see the option--inplace-build.OPAMJOBSβ sets the maximum 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 you get more reliable backtraces.OPAMLOCKEDβ the combination of the--lockedand--lock-suffixoptions.OPAMLOGSlogdir β sets the 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 the options--noand--confirm-level. OPAMNO is ignored if either OPAMCONFIRMLEVEL or OPAMYES is set.OPAMNOAGGREGATEβ withopam admin check, don't aggregate packages.OPAMNOASPCUDβ Deprecated. π«OPAMNOAUTOUPGRADEβ disables automatic internal upgrade of repositories in an earlier format to the current one, onupdateorinit.OPAMNOCHECKSUMSβ enables the option--no-checksumswhen available.OPAMNODEPEXTSβ disables system dependencies handling, see the option--no-depexts.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.OPAMPRECISETRACKINGβ fine grain tracking of directories.OPAMPREPROβ set this to false to disable CUDF preprocessing. less efficient, but might help debugging a 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 operations are done in-memory, no I/O for scanning the repository. π§OPAMREQUIRECHECKSUMSβ enables the option--require-checksumswhen available (e.g. foropam install).OPAMRETRIESβ sets the number of tries before failing downloads.OPAMREUSEBUILDDIRβ see the option--reuse-build-dir.OPAMROOTβ see the option--root. this is automatically set byopam env --root=DIR --set-root.OPAMROOTISOKβ don't complain when running as root.OPAMSAFEβ see the option--safe.OPAMSHOWβ see the option--show.OPAMSKIPUPDATEβ see the option--skip-updates.OPAMSKIPVERSIONCHECKSβ bypasses some version checks. Unsafe, for compatibility testing only. β οΈ bestie be careful.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 will continue 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. it 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. πOPAMSTATUSLINEβ display a dynamic status line showing what's currently going on on the terminal (one ofalways,neverorauto).OPAMSTRICTβ fail on inconsistencies (file reading, switch import, etc.).OPAMSWITCHβ see the option--switch. automatically set byopam env --switch=SWITCH --set-switch.OPAMUNLOCKBASEβ see the 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 the option--criteria.OPAMUSEINTERNALSOLVERβ see the option--use-internal-solver.OPAMUSEOPENSSLβ Removed in 2.2. πOPAMUTF8β use UTF8 characters in output (one ofalways,neverorauto). by defaultauto, 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.OPAMVALIDATIONHOOKβ if set, uses the%{hook}%command to validate an opam repository update.OPAMVERBOSEβ see the option--verbose.OPAMVERBOSEONβ see the option--verbose-on.OPAMVERSIONLAGPOWERβ do not use. π ββοΈ (for real. don't.)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 option--working-dir.OPAMYESβ see the options--yesand--confirm-level. 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 inopamfiles.OPAMVAR_package_varβ overrides the contents of the variable package:var when substituting%{package:var}%strings inopamfiles.
π CLI VERSION π
okay so this next bit is the part where past-you and future-you team up, and it's lowkey iconic. 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. πβ¨
although opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface. slay.
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. π
the command-line version is selected by using the --cli option or the OPAMCLI environment variable. --cli may be specified more than once, where the last instance takes precedence. OPAMCLI is only inspected if --cli is not given. π
bestie reminder: if you're writing anything that talks to opam programmatically, pass --cli and thank yourself later. iykyk. π
π EXIT STATUS π
okay bestie, real talk β the exit code is the receipt of what just happened. every command hands one back, and here's the whole chart.
β¨ ONE BIG EXCEPTION before we start, and it's important: theexeccommand is the rebel of the family. It returns127if the command wasn't found or couldn't be executed at all, and otherwise it just returns the command's own exit value. no vibes, no filtering, just passing it straight through. π
0β Success β¨ or, for boolean queries, true. she ate.1β False. This one shows up when a boolean return value is expected, like when you run with--check, or for queries such asopam lint.2β Bad command-line arguments π or command-line arguments that point at an invalid context (say, a file that doesn't follow the expected format).5β Not found. You asked for something β a package, a version, a repository, whatever β and it genuinely could not be found. π«₯10β Aborted. The operation needed confirmation and you didn't give it. fair honestly.15β Could not acquire the locks required for the operation. π someone else is in there.20β There is no solution to the user request. This can happen when you ask to install two incompatible packages, for example.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 or an incompatibility with your system. It can be a partial error.40β Sync error. Could not fetch some remotes from the network. Also can be a partial error.50β Configuration error. Opam or system configuration doesn't allow the operation, and it needs fixing.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. π§ π₯99β Internal error. Something went wrong, most likely a bug in opam itself. not our fault, not yours either.130β User interrupt.SIGINTwas received β generally because the user pressed Ctrl+C. iconic behaviour, no notes.
and then there's this little cluster at the end, also on the list:
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 π
See https://opam.ocaml.org/doc. that's the tea, go read it, iykyk πβ¨
π AUTHORS π
the whole friend group that made this happen, in order, with their emails, exactly as the page lists them:
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)β that's the main character, go read her too π
π BUGS π
found something cursed? Check bug reports at https://github.com/ocaml/opam/issues. we're not mad, we're just disappointed. (we're not even disappointed. we love you. file the issue. π«Ά)
and that's a wrap bestie!! π this whole thing is from Opam 2.6.1, dated OPAM-SWITCH(1) β yes the manual page IDs itself as the switch page, we don't question the queen's choices. 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