Revert Anaconda like the first time installed

Question:

I have two environments created in Users/user/conda/envs which I don’t need anymore. I saw that there is also pkgs in Users/user/conda and both of them Users/user/conda/envs and Users/user/conda/pkgs really eat a lot lot lot of my storage. I want to delete those two environment.

  1. Does conda remove -n env_name --all delete the environment and all its installed packages under its environment too? Or does it only delete the environment?

  2. Can I delete directly folder pkgs and env from Users/user without affect the base environment?

  3. How can one revert Anaconda like the first time installed (contain only base environment and the default packages)?

Or do I need uninstall Anaconda and re-install it?

Asked By: Reza Habibi

||

Answers:

Specific Answers

  1. Does conda remove -n env_name --all delete the environment and all its installed packages under its environment too? Or does it only delete the environment?

It will delete environment my_env, which includes the unpacked libraries and the env/env_name directory. It will not delete the cached tarballs in the conda/pkgs directory.

  1. Can I delete directly folder pkgs and env from Users/user without affect the base environment?

Yes. However, be aware that if softlinks (symbolic linking) are being used, deleting the pkgs directory could break environments. One can check whether softlinks are enabled with

conda config --show allow_softlinks always_softlink

though this cannot tell if any are in use.

Also, Conda packages can include pre-unlink scripts, which may contain code expect to be evaluated during the package removal process. Deleting the environment directly would ignore such protocols and could lead to empty references.

Generally, I would recommend using the commands available in the CLI, rather than deleting folders. If you wish to delete an environment, you should use the command in (1). If you wish to delete cached packages, you should use conda clean (use --help flag to see the options available).

  1. How can one revert Anaconda like the first time installed (contain only base environment and the default packages)?

Again, you can delete the other envs with conda remove --all. For base, you can revert it to the original state with

conda install -n base --revision 0

However, I will note that many users report this not working or at least have problems if they revert too far back. Instead, look back at the history of revisions with conda list --revisions and pick a state that removes what you don’t want.

General Recommendation

Miniforge

Since you seem like you want a clean break, I’d recommend the complete uninstall of Anaconda. However, since you appear primarily concerned with space, instead of reinstalling Anaconda, consider switching to a Miniforge variant, which only includes the Conda package manager and minimal infrastructure to support it. Then create environments that only include the packages that you actually require. You can still use conda clean --tarballs to minimize cached downloads, but already with Miniforge you should have a significantly smaller footprint than the full Anaconda distribution.

Managing Environments

As a general rule of thumb, I recommend using base only for installing Conda infrastructure (e.g., conda, mamba, conda-build, boa) and using separate environments for the specific package environments you need (e.g., TensorFlow, PyTorch). In my experience, this helps to keep your base more stable, and allows you to partition off potential package conflicts and wrap up specific projects by clearing out environments after you no longer need them.

Answered By: merv
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.