OPAM-CLEAN(1)
πΈ OPAM-CLEAN(1) πΈ
okay so this is opam-clean, straight out of the Opam Manual, and bestie it is exactly the page you want when your disk is full and you're like "why is this folder 40GB" π
β¨ NAME β¨
opam-clean β cleans up opam caches π§Όβ¨
π«§ SYNOPSIS π«§
opam clean [OPTION]β¦
π DESCRIPTION π
So basically: opam clean cleans up your opam caches and reclaims some disk space, which is giving "spring cleaning but for your ~/.opam folder" π§Ήπ¦
And here's the tea you actually need to know β if you specify no options at all, the default is:
--logs --download-cache --switch-cleanup
so it's not just sitting there doing nothing, she came ready. π
π OPTIONS π
-a,--all-switchesβ run the switch cleanup commands in all switches. This implies--switch-cleanup, so yeah, that one's coming along for the ride too. ππ¨-c,--download-cacheβ clear the cache of downloaded files (that's$OPAMROOT/download-cache, iykyk), and also the obsolete$OPAMROOT/archives, if that exists. Old archives, we don't know her anymore π--dry-runβ print the removal commands like a lil preview reel, but don't execute them. Main character move for the cautious girlies π--logsβ clear the logs directory. bye bye receipts β¨-r,--repo-cacheβ clear the repository cache. It will be rebuilt by the next opam command that needs it, so like, it comes back. She's resilient. π±-s,--switch-cleanupβ run the switch-specific cleanup: clears backups, build dirs, uncompressed package sources of non-dev packages, local metadata of previously pinned packages, etc. the whole under-the-bed situation, gone π§Ί--untrackedβ clean untracked file and directories π«§--unused-repositoriesβ clear any configured repository that is not used by any switch nor the default. if nobody's using her, she doesn't get to live in your config rent-free π
π«Ά COMMON OPTIONS π«Ά
These options are common to all commands β so like, the shared group-chat of opam flags π±
--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$OPAMBESTEFFORTenvironment variable. lowkey "we tried our best and that's enough" energy π₯Ί--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. β³--color=WHENβ colorize the output.WHENmust be one ofalways,neverorauto. π--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. π«‘--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, see http://opam.ocaml.org/doc/External_solvers.html. A general guide to using solver preferences can be found at http://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 to stderr. This is equivalent to setting$OPAMDEBUGto"true". π--debug-level=LEVELβ like--debug, but allows specifying the debug level (--debugsets it to 1). 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 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, 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. π she's gone, don't look for her--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β useROOTas the current root path. This is equivalent to setting$OPAMROOTtoROOT. π--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. π
careful babe β this one will fail whenever such an operation is needed. that's not a bug, that's the whole point.
--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β 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, 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 π
opam is lowkey obsessed with environment variables, bestie, and this is the full roster. Set them and opam listens, no cap.
Quick note before we dive in: all the boolean ones take the same lil vocabulary of vibes β set them to "0", "no", "false" or just the empty string to disable them, and "1", "yes" or "true" to enable them. Pick your fighter, they all work. π
OPAMALLPARENSβ surrounds all filters with parenthesis. yeah. all of them. parenthesise everything bestie.OPAMASSUMEDEPEXTSβ see option--assume-depexts.OPAMAUTOANSWERβ internal use only, nothing to see here, mind your business πOPAMAUTOREMOVEβ see the remove option--auto-remove.OPAMBESTEFFORTβ see option--best-effort.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. the way it just patches the criteriaβ¦ πOPAMBUILDDOCβ removed in 2.1. rest in peace icon πOPAMBUILDTESTβ removed in 2.1. also gone, also missed.OPAMCLIβ see option--cli.OPAMCOLORβ when set toalwaysornever, sets a default value for the--coloroption.OPAMCONFIRMLEVELβ see option--confirm-level. and know this:OPAMCONFIRMLEVELhas priority overOPAMYESandOPAMNO. it's the main character, everyone else waits their turn πOPAMCRITERIAβ specifies user preferences for dependency solving. the default value depends on the solver version, so runconfig reportto know the current setting. see also option--criteria.OPAMCUDFFILEβ saves the cudf graph to the filefile-actions-explicit.dot. dot file bestie!!OPAMCUDFTRIMβ controls the filtering of unrelated packages during CUDF preprocessing.OPAMCURLβ can be used to select a givencurlprogram. seeOPAMFETCHfor more options.OPAMDEBUGβ see 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. how deep are we digging? yes π³οΈ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. yeah it goes over their heads, sorry π«ΆOPAMERRLOGLENβ sets the number of log lines printed when a sub-process fails.0prints all of them. all. every single line. good luck πOPAMEXTERNALSOLVERβ see option--solver.OPAMFAKEβ see option--fake.OPAMFETCHβ specifies how to download files: eitherwget,curl, or a custom command where the variables%{url}%,%{out}%,%{retry}%,%{compress}%and%{checksum}%will be replaced. overrides thedownload-commandvalue from the main config file.OPAMFIXUPCRITERIAβ same asOPAMUPGRADECRITERIA, but specific to fixup and reinstall.OPAMIGNOREAVAILABLEβ see the install option--ignore-available-on.OPAMIGNORECONSTRAINTSβ see the 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. we love a little multitasking moment β¨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 combination of the--lockedand--lock-suffixoptions.OPAMLOGSβlogdirsets the log directory; the default is a temporary directory in/tmp.OPAMMAKECMDβ set the systemmakecommand to use.OPAMMERGEOUTβ merge process outputs, with stderr going on stdout.OPAMNOβ answer no to any question asked, see options--noand--confirm-level.OPAMNOis ignored if eitherOPAMCONFIRMLEVELorOPAMYESis set. it knows its place, it's not fighting anybody πOPAMNOAGGREGATEβ withopam admin check, don't aggregate packages.OPAMNOASPCUDβ deprecated. don't use it, it's giving vintage for no reason.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 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.OPAMPRECISETRACKINGβ fine grain tracking of directories. πOPAMPREPROβ set this to false to disable CUDF preprocessing. it's less efficient, but it might help debugging solver issue.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. it's giving speed, it's giving elegance β¨OPAMREQUIRECHECKSUMSβ enables the option--require-checksumswhen 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. seriously bestie, testing only, do not make this your personality π¨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; iffalse, a timeout is an error. currently only thebuiltin-z3backend 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. gone but not forgotten ποΈ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.). no chaos tolerated, periodt.OPAMSWITCHβ see 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. it overridesOPAMCRITERIAin upgrades if both are set. see also option--criteria.OPAMUSEINTERNALSOLVERβ see option--use-internal-solver.OPAMUSEOPENSSLβ removed in 2.2. bye bye πOPAMUTF8β use UTF8 characters in output (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.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 description, do not use it π ββοΈ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.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 bestie this section is important so 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. and not just for you! blog posts and other documentation can benefit too, because it prevents information from becoming stale. nobody wants a tutorial that aged like milk π₯
Although opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface. iconic behaviour honestly π
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. π¨ yeah, it will call you out, gently.
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. last one wins, always πΈ
π EXIT STATUS π
okay bestie, this is the part where opam tells you exactly what went wrong by handing back a number, and you're gonna learn every single one of them because they are iconic.
tiny little exception alert!! theexeccommand is the drama queen that refuses to play by these rules: it returns127if the command wasn't found or couldn't be executed at all, and otherwise it just hands you the command's own exit value. periodt.
Here's the whole roster, no skips, no skimming:
0β Success, ortruefor boolean queries. we love a win β¨1β False. Comes back when a boolean return value is expected, like when you run with--check, or for queries likeopam lint. it's not an error bestie it's just no π2β Bad command-line arguments, or args pointing at an invalid context (think: file not following the expected format). your input said no π5β Not found. You asked for something (package, version, repository, etc.) that simply could not be found. she's not here π10β Aborted. The operation needed confirmation and it never got given. you ghosted the prompt π«Ά15β Could not acquire the locks required for the operation. locks said no π20β There is no solution to the user request. Example: asking to install two incompatible packages. the solver is like "ma'am" π30β Error in package definition, or other metadata files. Heads up: using--strictraises this error more often. strict mode is strict31β Package script error. Some package operations were unsuccessful. This may be an error in the packages or an incompatibility with your system. Also: this can be a partial error.40β Sync error. Could not fetch some remotes from the network. Also can be a partial error. the wifi is giving nothing π¦50β Configuration error. Opam or system configuration doesn't allow the operation, and needs fixing. fix it bestie60β Solver failure. The solver failed to return a sound answer. Could be a broken external solver, or an error in solver configuration. she's confused π§99β Internal error. Something went wrong, likely due to a bug in opam itself. not us, it's literally opam130β User interrupt.SIGINTwas received, generally because the user pressed Ctrl+C. that was you, wasn't it π
and then these three, in their own little crew:
0on success.123on indiscriminate errors reported on standard error.124on command line parsing errors.125on unexpected internal errors (bugs).
π FURTHER DOCUMENTATION π
the lore is out there, bestie β go read it:
π AUTHORS π
these are the actual legends who built this. say thank you. icons, every one of 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)β the main character herself β¨
π BUGS π
found something cursed? Check bug reports at https://github.com/ocaml/opam/issues. the devs wanna know, fr fr π
and that's the whole page bestie!! this was Opam 2.6.1, the OPAM-CLEAN(1) era, and you ate every single section. go forth and opam clean responsibly π
ππ«Ά
π¦ 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