Skip to content

Every opam switch is a full OCaml compiler with its own packages

OCaml's opam keeps a complete compiler and package set per switch, plus a download cache. How to list switches, remove old ones and clear the cache.

4 min read

opam makes it easy to create a switch per project or per compiler version. Each switch is a full OCaml compiler and every package installed in it, often several hundred MB to a few GB. Local switches live inside projects as _opam folders.

opam switch list
du -sh ~/.opam ~/.opam/* 2>/dev/null | sort -h
find ~ -maxdepth 4 -type d -name _opam -prune -exec du -sh {} + 2>/dev/null

Clean up

# Remove a switch you no longer use
opam switch remove 4.14.1

# Clear download caches and build logs
opam clean -a -c -s --logs

Project _build folders from dune can also be removed; they rebuild.

More toolchains: version managers and Haskell's Stack and Cabal.

Common questions

Where does opam store switches on a Mac?

Global switches in ~/.opam, and local switches in an _opam folder inside each project.

How do I remove an opam switch?

Run opam switch remove followed by the switch name. opam switch list shows them.

What does opam clean remove?

Download caches, build directories and logs, depending on the options. Installed switches stay.

Read next