148

How do I reset the root environment of anaconda? There has to be a simple conda reset command that does this.

I don't want to reinstall anaconda all over again. I have other virtualenvs that I don't want to overwrite and that will happen if I install anaconda again.

Kashif
  • 3,063
  • 6
  • 29
  • 45

5 Answers5

155

See https://github.com/conda/conda/issues/1032

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

Leopd
  • 41,333
  • 31
  • 129
  • 167
pierre
  • 1,721
  • 1
  • 12
  • 7
  • 2
    @bonobo I think this was a bug and I personally had to reinstall conda from scratch unfortunately (see [this conversation](https://github.com/conda/conda/issues/6290)). [A fix](https://github.com/conda/conda/pull/6719) has apparently been merged earlier this year but I would still use this command with caution. – pierre May 23 '18 at 20:03
  • 35
    Note: this does not restore or remove packages installed with pip. – mforbes Oct 07 '20 at 20:53
  • 11
    @mforbes haha so it does everything but what I actually want. Thanks for the heads-up. – gargoylebident May 18 '21 at 08:59
  • 3
    Note the output of `conda list --revisions` depends on what conda environment is currently active. – Jasha Sep 29 '21 at 20:43
  • 1
    this link https://www.shriramjaju.page/2018-05-30-2-minute-recipe-how-to-rollback-your-conda-environment/ explains clearly how to rollback anaconda to a previous state – Martin Mar 10 '22 at 04:05
  • @mforbes so to remove pip packages from conda base, could a nuke and reinstall of conda fix that, or would it still linger? – mochsner Aug 04 '22 at 15:01
  • 2
    @mochsner It depends: if you use `pip install --user`, then `pip` will install everything in `site.USER_BASE` (usually `~/.local`) and these will persist, even if you reinstall conda. However, if you don't use `--user`, then nuking conda should fix it. – mforbes Aug 05 '22 at 18:33
  • @mforbes You could do pip uninstall -y -r <(pip freeze) as recommended here https://stackoverflow.com/questions/11248073/what-is-the-easiest-way-to-remove-all-packages-installed-by-pip – Keith Feb 02 '23 at 20:24
11

While this is not exactly what you are asking, I found conda clean --all useful to clean out a bunch of old packages, logs etc. which somewhat restores conda to a new state.

Community
  • 1
  • 1
Nic Cottrell
  • 9,401
  • 7
  • 53
  • 76
  • 2
    This answer is valuable and easy to implement. But it takes time to run, and I first thought my computer had flunked. – Wei Shan Lee May 26 '23 at 01:40
1

This might be overkill but this worked for me when nothing else would. This is what is referred to as "nuking" in the above posts

Revert anaconda back to the install state

conda install --rev 1

Uninstall all pip files

pip uninstall -y -r <(pip freeze)

remove all anaconda files

rm -rf /Users/[username]/opt/anaconda3

reinstall from https://www.anaconda.com/products/distribution

Update anaconda

conda update conda

NOTE: Close your terminal between each step if you want to make sure you don't get "directory not found" errors

Keith
  • 4,646
  • 7
  • 43
  • 72
0

One might also consider conda update anaconda as a "nuclear option". The anaconda meta-package links together certain versions of packages that Continuum Analytics has figured out all play nice together.

Edit: As @mforbes points out, only do this if you are wanting to reset the base anaconda environment as distributed with the Anaconda (not Miniconda) installer. It has about 550 packages and is about a 1G download.

RandyP
  • 497
  • 3
  • 11
  • 20
    That's not resetting the environment at all, no? – AMC Mar 31 '20 at 20:25
  • 3
    I don't understand the downvotes... This approach doesn't reset the environment but it certainly makes it more consistent while still trying to keep it up to date... Given that lack of consistency is usually the main reason for looking after a full reset, then `conda update anaconda` could work as the least invasive first-aid approach, no? – Redoman Mar 08 '22 at 04:29
  • 4
    My downvote was because I stumbled on this question when searching how to reset the base **conda** environment, for which the accepted answer is close to the answer. Executing `conda update anaconda` would have installed the entire anaconda suite, completely the oposite of what I would have wanted and I did not want people to make this mistake. However, since the OP did ask about **anaconda** specifically, perhaps this is reasonable. If a a warning is included in the answer, I would remove my downvote. – mforbes Aug 05 '22 at 18:50
0

This worked for me:

conda update --all
conda update -n base -c defaults conda
moken
  • 3,227
  • 8
  • 13
  • 23