How to Delete Conda Environments and Free the Space on Mac
A few months of data work leaves a Mac with conda environments nobody remembers making: one per course, one per paper, one for a tool you tried once. Each holds its own Python and packages, and together with conda's package cache they can take tens of gigabytes. Removing them is two commands, but the space often does not come back after the first one, and the reason is how conda shares files between environments.
This guide covers listing what you have, removing an environment by name or by path, why the disk figure barely moves afterward, and how conda clean returns the rest. It applies to Anaconda, Miniconda, Miniforge and Mambaforge alike. To remove conda itself, uninstalling Python and Node on Mac covers that.
List Your Environments
conda env list
The same list comes from conda info --envs. The active environment carries an asterisk, and each line shows its folder, usually ~/miniconda3/envs/<name> or ~/anaconda3/envs/<name>. The line without a name is base, the environment conda itself lives in; leave it alone.
To see how much each one uses:
conda info --size
That reports conda's own disk use per environment. If your conda version does not have it, measure the folders directly:
du -sh ~/miniconda3/envs/* ~/miniconda3/pkgs
Swap miniconda3 for anaconda3, miniforge3 or mambaforge to match your install.
Save It Before You Remove It
An environment you might need again costs one small file to keep. Activate it and export:
conda activate myenv
conda env export --from-history > myenv.yml
--from-history writes only the packages you asked for, so the file can be rebuilt on another Mac or a newer conda. For a byte-exact rebuild on the same platform, use conda list --explicit > myenv-spec.txt instead. Either file brings the environment back later with conda create --file myenv.yml (or conda env create --file myenv.yml on older versions).
Remove an Environment
Conda's documentation says the environment must not be active when you remove it, so step out first:
conda deactivate
conda remove --name myenv --all
conda env remove --name myenv does the same. Add --dry-run to see what would go without removing anything.
An environment created with --prefix somewhere outside envs, such as inside a project folder, has no name conda can look up. Remove it by path:
conda remove --prefix ~/projects/thesis/.env --all
Moving an environment folder to the Trash in Finder frees the same files, but the command is the cleaner path: it also updates conda's own record of environments, which conda env list and conda clean read.
Why the Space Did Not Come Back
Conda downloads every package once into its package cache, pkgs in the install folder, and then hard-links those files into each environment that uses them. Conda's own documentation puts it this way: environments take up little space thanks to hard links. A hard link is a second name for the same data on disk, so the data stays until the last name is gone.
Removing an environment deletes its names. The copy in pkgs is still there, which is why du on the install folder looks almost the same as before. The cache also keeps the downloaded .conda and .tar.bz2 archives and the channel index files, none of which any environment needs once a package is installed.
Return the Rest with conda clean
Preview first:
conda clean --all --dry-run
Then run it:
conda clean --all
| Flag | What it removes |
|---|---|
-i, --index-cache |
Downloaded channel index files; conda fetches them again |
-t, --tarballs |
Package archives already extracted into the cache |
-p, --packages |
Extracted packages no environment links to |
-c, --tempfiles |
Leftover temporary files |
-l, --logfiles |
Log files |
-a, --all |
All of the above |
One warning in conda's documentation is worth reading before -p: it checks only environments that conda info --envs lists. An environment it does not know about, for example one created by another conda install or registered under a different user, can lose packages it still links to. If you keep environments outside the normal places, run conda env list first and make sure they appear.
Leave --force-pkgs-dirs alone. It deletes every writable package cache, is deliberately not part of --all, and breaks environments that rely on those files.
Mamba and Other Installs
Mamba accepts the same commands: mamba env list, mamba remove --name myenv --all, mamba clean --all. If you have more than one installer, say Anaconda from years ago and Miniforge now, each has its own envs and pkgs; run the cleanup with each one's conda, or check both folders in Finder before assuming the space went somewhere else. CONDA_PKGS_DIRS and CONDA_ENVS_PATH move those folders if they are set in your shell.
Where Mole Fits
Mole's Clean looks for conda installs in your home folder (~/miniconda3, ~/anaconda3, ~/miniforge3, ~/mambaforge, and the two under ~/opt) and only counts one that has real conda-meta and pkgs folders. Under Developer Tools it lists a Conda Cache group with two kinds of rows: package archives in pkgs whose extracted copy is already in place and that have not been touched for a day, and the pkgs/cache index folder, the same thing conda clean --index-cache removes. Every row is marked Review and starts unchecked. Mole never touches extracted packages or environments, never runs conda, and moves what you tick to the Trash. Removing environments themselves stays a conda remove job. For other development caches, clearing developer caches on Mac goes through Xcode, npm and the rest.
FAQ
Is it safe to delete the pkgs folder by hand?
Not the whole folder. Environments are hard-linked to files in it, and conda expects its records there. Use conda clean --all, which removes only what no environment needs.
Does removing an environment delete my notebooks and data?
Only files inside the environment folder go. Notebooks, scripts and data in your project folders stay, unless you created the environment with --prefix inside the project and kept data in that same folder.
Can I remove the base environment?
No. Base holds conda itself. To get rid of everything, uninstall conda, which the Python and Node uninstall guide covers.
Will conda clean --all slow down my next install?
Slightly. Conda downloads the index again and fetches any package it no longer has in the cache. Your environments keep working.