OPAM(1)
π OPAM(1) β the Opam Manual π
okay so bestie, welcome to the opam man page π this is the page, straight out of the Opam Manual, section 1, and it's giving main character energy from the very first line. Let's get into it π«Ά
πΈ NAME πΈ
opam β source-based package management β¨
π SYNOPSIS π
opam [COMMAND] β¦
π¦ DESCRIPTION π¦
Okay so opam is a package manager. Periodt. π It uses the powerful mancoosi tools to handle dependencies β and no, not the "eh, probably fine" kind of dependency handling. We're talking real support for version constraints, optional dependencies, and conflict management. The default configuration binds it to the official package repository for OCaml π
She also has support for a whole roster of different remote repositories, like HTTP, rsync, git, darcs and mercurial π₯ And get this β everything gets installed inside a local opam directory, which can literally include multiple installation prefixes, each with a different set of installed packages. multiple. sets. iconic. π
If you want the tea on a specific command, use either opam <command> --help or opam help <command> π
π COMMANDS π
π« admin [OPTION]β¦
Tools for repository administrators π οΈ
π« clean [OPTION]β¦
Cleans up opam caches π§Ή
π« config [OPTION]β¦ [COMMAND] [ARG]β¦
Display configuration options for packages. βοΈ
π« env [OPTION]β¦
Prints appropriate shell variable assignments to stdout π
π« exec [OPTION]β¦ COMMAND [ARG]...β¦
Executes a command in the proper opam environment π
π« help [--man-format=FMT] [OPTION]β¦ [TOPIC]
Display help about opam and opam commands. πββοΈ
π« init [OPTION]β¦ [NAME] [ADDRESS]
Initialize opam state, or set init options. π±
π« install [OPTION]β¦ [PACKAGES]β¦
Install a list of packages. π¦
π« lint [OPTION]β¦ [FILES]β¦
Checks and validate package description (opam) files. π
π« list [--check] [--no-depexts] [--silent] [OPTION]β¦ [PATTERNS]β¦
Display the list of available packages. π
π« lock [--direct-only] [--keep-local] [--lock-suffix=SUFFIX] [OPTION]β¦ [PACKAGES]β¦
Create locked opam files to share build environments across hosts. π
π« option [--global] [OPTION]β¦ [FIELD[(=|+=|-=)[VALUE]]]
Global and switch configuration options settings ποΈ
π« pin [OPTION]β¦ [COMMAND] [ARG]β¦
Pin a given package to a specific version or source. π
π« reinstall [OPTION]β¦ [PACKAGES]β¦
Reinstall a list of packages. π
π« remove [OPTION]β¦ [PACKAGES]β¦
Remove a list of packages. ποΈ
π« repository [--kind=KIND] [--rank=RANK] [--short] [OPTION]β¦ [COMMAND] [ARG]β¦
Manage opam repositories. ποΈ
π« show [OPTION]β¦ [PACKAGES]β¦
Display information about specific packages. π
π« source [OPTION]β¦ PACKAGE
Get the source of an opam package. π§¬
π« switch [OPTION]β¦ [COMMAND] [ARG]β¦
Manage multiple installation prefixes. π
π« tree [--recursive] [--subpath=PATH] [OPTION]β¦ [PACKAGES]β¦
Draw the dependency forest of installed packages. π³ (a forest, bestie π²π²)
π« update [OPTION]β¦ [NAMES]β¦
Update the list of available packages. π
π« upgrade [OPTION]β¦ [PACKAGES]β¦
Upgrade the installed package to latest version. β¬οΈ
π« var [--global] [--package=PACKAGE] [OPTION]β¦ [VAR[=[VALUE]]]
Display and update the value associated with a given variable π·οΈ
π§ COMMAND ALIASES π§
yep, opam has a whole little clique of aliases β same energy, different name π
π info [OPTION]β¦ [PACKAGES]β¦
An alias for show.
π remote [--kind=KIND] [--rank=RANK] [--short] [OPTION]β¦ [COMMAND] [ARG]β¦
An alias for repository.
π search [--check] [--no-depexts] [--silent] [OPTION]β¦ [PATTERNS]β¦
An alias for list --search.
π uninstall [OPTION]β¦ [PACKAGES]β¦
An alias for remove.
π unpin [OPTION]β¦ [ARG]β¦
An alias for pin remove.
π why [--recursive] [--subpath=PATH] [OPTION]β¦ [PACKAGES]β¦
An alias for tree --rev-deps.
β¨ COMMON OPTIONS β¨
These ones are common to all commands, bestie β the shared wardrobe, if you will π
--best-effortβ Don't fail if all requested packages can't be installed: try to install as many as possible. Heads up though, not all external solvers may support this option (recent versions of aspcud or mccs should). This is 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 intended 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 was not available in opam 2.0, so to select the 2.0 CLI, set theOPAMCLIenvironment variable to2.0instead of using this parameter. π°οΈ--color=WHENβ Colorize the output. WHEN must 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 taken into account. This is equivalent to setting$OPAMCONFIRMLEVEL. β--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. π--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. π--debugβ Print debug message tostderr. This is equivalent to setting$OPAMDEBUGto"true". π--debug-level=LEVELβ Like--debug, but allows specifying the debug level (--debugsets it to1). Equivalent to setting$OPAMDEBUGto a positive integer.--git-versionβ Print the git version of opam, if set (i.e. you are using a development version), and exit. π§¬--help[=FMT](default=auto)β Show this help in format FMT. The value FMT must 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, either 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. π€--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. β°οΈ--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. β οΈ--no-self-upgradeβ Opam will replace itself with a newer binary found atOPAMROOT/opamif present. This disables this behaviour. πͺ-q,--quietβ Disables--verbose. π€«--root=ROOTβ Use ROOT as the current root path. This is equivalent to setting$OPAMROOTto ROOT. π--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. π‘οΈ--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. π€--switch=SWITCHβ Use SWITCH as the current compiler switch. This is equivalent to setting$OPAMSWITCHto 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$OPAMNOASPCUDor$OPAMUSEINTERNALSOLVER. ποΈ-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". π£οΈ--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 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. β οΈ-y,--yesβ Answer yes to all opam yes/no questions without prompting. See also--confirm-level. This is equivalent to setting$OPAMYESto"true". β
π ENVIRONMENT π
ok bestie so opam reads a whole lil family of environment variables and honestly? they run the show. here's the thing about the boolean ones: to turn them off, set them to "0", "no", "false", or just the literal empty string. to turn them on, set them to "1", "yes", or "true". that's it, that's the rule π
OPAMALLPARENSβ wraps every single filter in parenthesis. all of them. the parens era πOPAMASSUMEDEPEXTSβ see the--assume-depextsoption.OPAMAUTOANSWERβ internal use only, bestie, nothing to see here πOPAMAUTOREMOVEβ see theremoveoption--auto-remove.OPAMBESTEFFORTβ see the--best-effortoption.OPAMBESTEFFORTPREFIXCRITERIAβ sets the string that must be prepended to the criteria when the--best-effortoption is set, and it's expected to maximise theopam-queryproperty in the solution.OPAMBUILDDOCβ removed in 2.1. rip πOPAMBUILDTESTβ also removed in 2.1. double rip ππOPAMCLIβ see the--clioption.OPAMCOLORβ when you set it toalwaysornever, it sets a default value for the--coloroption. so you don't have to type it every time, iconic behavior βOPAMCONFIRMLEVELβ see the--confirm-leveloption. heads up:OPAMCONFIRMLEVELhas priority overOPAMYESandOPAMNO, it's the main character here πOPAMCRITERIAβ specifies your user preferences for dependency solving. the default value depends on the solver version, so runconfig reportto find out the current setting. see also the--criteriaoption.OPAMCUDFFILEβ save the cudf graph tofile-actions-explicit.dot.OPAMCUDFTRIMβ controls the filtering of unrelated packages during CUDF preprocessing.OPAMDIGDEPTHβ defines how aggressive the lookup for conflicts during CUDF preprocessing is. how deep is it gonna dig? you decide π³οΈOPAMDOWNLOADJOBSβ sets the maximum number of simultaneous downloads.OPAMDROPWORKINGDIRβ overrides packages that were previously updated with--working-diron update. without this variable set, opam would keep them unchanged unless you explicitly name them on the command-line.OPAMDRYRUNβ see the--dry-runoption.OPAMEDITORβ sets the editor to use for opam file editing, and it overrides$EDITORand$VISUAL. it said "i'm the boss now" π€OPAMERRLOGLENβ sets the number of log lines printed when a sub-process fails. set it to0to print all of them.OPAMEXTERNALSOLVERβ see the--solveroption.OPAMFAKEβ see the--fakeoption.OPAMFETCHβ specifies how to download files: eitherwget,curl, or a custom command where the variables%{url}%,%{out}%,%{retry}%,%{compress}%and%{checksum}%will be replaced. this overrides the'download-command'value from the main config file.OPAMFIXUPCRITERIAβ same asOPAMUPGRADECRITERIA, but specific to fixup and reinstall.OPAMIGNOREAVAILABLEβ see theinstalloption--ignore-available-on.OPAMIGNORECONSTRAINTSβ see theinstalloption--ignore-constraints-on.OPAMIGNOREPINDEPENDSβ see the--ignore-pin-dependsoption.OPAMINPLACEBUILDβ see the--inplace-buildoption.OPAMJOBSβ sets the maximum number of parallel workers to run. multitasking queen energy β¨OPAMJSONβ log json output to the given file (use the character%to index the files).OPAMKEEPBUILDDIRβ see theinstalloption--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. keeping the receipts, love that for you πOPAMLOCKEDβ combination of the--lockedand--lock-suffixoptions.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, with stderr going on stdout.OPAMNOβ answer no to any question asked, see the--noand--confirm-leveloptions.OPAMNOis ignored if eitherOPAMCONFIRMLEVELorOPAMYESis set.OPAMNOAGGREGATEβ withopam admin check, don't aggregate packages.OPAMNOASPCUDβ deprecated. step away from the legacy, bestie πOPAMNOAUTOUPGRADEβ disables the automatic internal upgrade of repositories in an earlier format to the current one, on'update'or'init'.OPAMNOCHECKSUMSβ enables the option--no-checksumswhen available.OPAMNODEPEXTSβ disables system dependencies handling, see the--no-depextsoption.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. pinkinda... auto. she's been doing this since 1.3.0 and she's tired πOPAMPRECISETRACKINGβ fine grain tracking of directories.OPAMPREPROβ set this tofalseto disable CUDF preprocessing. less efficient, but it might help with debugging solver issues.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, with no I/O for scanning the repository. glow up fr fr π₯OPAMREQUIRECHECKSUMSβ enables the option--require-checksumswhen available (e.g. foropam install).OPAMRETRIESβ sets the number of tries before failing downloads.OPAMREUSEBUILDDIRβ see the--reuse-build-diroption.OPAMROOTβ see the--rootoption. this one is automatically set byopam env --root=DIR --set-root.OPAMROOTISOKβ don't complain when running as root. let her live πOPAMSAFEβ see the--safeoption.OPAMSHOWβ see the--showoption.OPAMSKIPUPDATEβ see the--skip-updatesoption.OPAMSKIPVERSIONCHECKSβ bypasses some version checks. unsafe, for compatibility testing only. do not do this for fun, i'm begging π«Ά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; iffalse, a 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 it to0for unlimited. note that not all solvers may support this option.OPAMSOLVERTOLERANCEβ changes the tolerance towards the solver choosing an unoptimized solution (i.e. it might pull outdated packages, not cute). 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 not all solvers may support this option.OPAMSTATSβ removed in 2.4. πOPAMSTATUSLINEβ display a dynamic status line showing what's currently going on on the terminal. (one of one ofalways,neverorauto)OPAMSTRICTβ fail on inconsistencies (file reading, switch import, etc.). no sloppy behavior allowed π«OPAMSWITCHβ see the--switchoption. automatically set byopam env --switch=SWITCH --set-switch.OPAMUNLOCKBASEβ see theinstalloption--unlock-base.OPAMUPGRADECRITERIAβ specifies user preferences for dependency solving when performing an upgrade. it overridesOPAMCRITERIAin upgrades if both are set. see also the--criteriaoption.OPAMUSEINTERNALSOLVERβ see the--use-internal-solveroption.OPAMUSEOPENSSLβ removed in 2.2. gone bestie π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 macOS exclusive, iykyk β¨OPAMVALIDATIONHOOKβ if set, uses the%{hook}%command to validate an opam repository update.OPAMVERBOSEβ see the--verboseoption.OPAMVERBOSEONβ see the option--verbose-on.OPAMVERSIONLAGPOWERβ do not use. that's the whole thing. do not use π ββοΈOPAMWITHDEVSETUPβ see theinstalloption--with-dev-setup.OPAMWITHDOCβ see theinstalloption--with-doc.OPAMWITHTESTβ see theinstalloption--with-test.OPAMWORKINGDIRβ see the--working-diroption.OPAMYESβ see the--yesand--confirm-leveloptions.OPAMYEShas priority overOPAMNOand is ignored ifOPAMCONFIRMLEVELis 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 part is important so gather round π«Ά every single script and programmatic invocation of opam should use --cli, and the reason is genuinely so real: it's how you make sure your stuff works seamlessly with future versions of the opam client. and it's not just for scripts either β blog posts and other documentation benefit too, because it stops information from going stale. no more ancient tutorials that don't work anymore, we love to see it π
so here's the sitch: opam only supports roots (~/.opam/) for the current version, but it does provide backwards compatibility for its command-line interface. slay.
now, since CLI version support was only added in opam 2.1, you use OPAMCLI to select 2.0 support (because opam 2.0 will just ignore it, so it's safe), and you use --cli=2.1 for 2.1 (or later) versions β since an environment variable controlling the parsing of syntax is brittle. like, fragile. 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. so if you see warnings, that's why bestie π
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, the env var sits in the waiting room π
π EXIT STATUS π
okay bestie, listen up, because this is the part where opam tells you exactly what went wrong by handing you a number. learn these, they're your love language π’
one tiny exception first, and it's important: the exec command does not follow the list below. If the command wasn't found or couldn't be executed, exec returns 127. Otherwise it returns the command's own exit value, periodt.
Now the actual list:
0β success, ortruefor boolean queries. we love to see it π1βfalse. this one shows up when a boolean return value is expected, like when you're running with--check, or for queries likeopam lint.2β bad command-line arguments, or command-line arguments pointing at an invalid context (e.g. a file that doesn't follow the expected format). π5β not found. you asked for something (package, version, repository, etc.) and it simply could not be found. it's giving ghosted.10β aborted. the operation needed confirmation and you didn't give it.15β couldn't get the locks required for the operation. someone else is holding them π20β there's no solution to your request. this can happen when you ask to install two incompatible packages, for example.30β error in package definition, or in other metadata files. heads up: using--strictraises this error way more often.31β package script error. some package operations were unsuccessful. this can be an error in the packages, or an incompatibility with your system. can be only a partial error.40β sync error. some remotes couldn't be fetched from the network. also can be a partial error.50β configuration error. opam or your system config doesn't allow the operation, and it needs fixing before you go anywhere. π§60β solver failure. the solver failed to return a sound answer. could be a broken external solver, or an error in the solver configuration.99β internal error π something went wrong, likely a bug in opam itself.130β user interrupt.SIGINTwas received, generally because the user pressed Ctrl+C.
and then there's this last little cluster of codes, also on the menu:
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 π
want more? go read https://opam.ocaml.org/doc. the docs are right there, bestie, go feast β¨
π AUTHORS π
the legends who made this. absolute icons, all of them, no notes π«Ά
- 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>
π BUGS π
found something cursed? check the bug reports at https://github.com/ocaml/opam/issues. don't suffer in silence, tell the devs π
and that's a wrap on the whole page, babe π this was Opam 2.6.1, manual section OPAM(1) β screenshot it, bookmark it, tattoo it on your forearm, whatever works for you. go forth and opam responsibly, bestie π
πΈπ¦
π¦ 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