How to Reset Anaconda Root Environment

How to reset anaconda root environment


This has been implemented as conda list --revisions and conda install --rev REV_NUM.

EDIT: be careful though if you execute conda install --rev 0 as this will remove your root environment and the conda command. Maybe conda install --rev 1 would produce the desired behavior (restore root environment to its state after first installation).

EDIT 2018-03-07: Use the --revision argument instead of --rev

Revert Anaconda like the first time installed

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?

You shouldn't do this because Conda may be using hard or soft links to share packages across environments, and hence it can be difficult to determine what you may affect by such blunt deletion. 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.

General Recommendation


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 Miniconda, which only includes the Conda package manager and minimal infrastructure to support it. Then create envs that only include the packages that you actually require. You can still use conda clean --tarballs to minimize cached downloads, but already with Miniconda 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 infrastructure (Jupyter, git, emacs, etc.) 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 envs after you no longer need them.

clean the base environment in Anaconda

There's not a slick and safe one-liner to do this. You can uninstall things one-by-one, but that is tedious and risks accidentally uninstalling something you need. Having extra stuff installed in your base environment shouldn't be much of a problem; it's fine to just leave stuff there.

Related Topics

Leave a reply