Where Does Opam Store Switches and Packages?
Opam roots everything at ~/.opam with switches inside. OPAMROOT plus per switch env.
Last updated
Opam keeps its root at ~/.opam: switches as install prefixes inside, repo caches, logs, and the opam binary self upgrade copy. The man page documents --root and $OPAMROOT to relocate it, plus $OPAMSWITCH for the active compiler.
Each switch is a full prefix with its own bin, lib, and share, activated with opam env for the shell. Never hand edit inside switches; reinstall or pin instead. opam clean trims caches and build dirs when the root balloons.
Where Opam stores this, by platform
~/.opam
Root with switches, repo, log, and config inside. --root or OPAMROOT moves it. Per switch env via eval $(opam env). Same layout on macOS.
~/.opam
Same root layout as Linux. Homebrew and installer builds agree on the default. Move with OPAMROOT when home is cramped.
%USERPROFILE%\.opam
Same relative root under the profile for Cygwin and WSL builds. Native Windows support varies by release; check the docs for your version.
Frequently asked questions
how do i move the opam root
Set OPAMROOT to the new path (or --root per command) and migrate the tree with permissions intact. Re run opam env to refresh shell paths pointing at switches inside.
opam root is huge, what can i delete
Run opam clean to drop caches, logs, and stale build dirs safely. Switch directories themselves are live installs; remove unused ones with opam switch remove.
Notice an outdated path? Let us know.