How to uninstall Anaconda and remove its path from .bash_profile on Ubuntu 22

Anaconda Distribution is a Python/R data science distribution. Using its package manager conda, one can manage over 7,500+ open-source packages. Anaconda is free and easy to install and offers free community support. When you install Anaconda, it adds its path to .bash_profile if you select ‘yes’ to the option. That’s why you see the conda environment activated automatically whenever you open the terminal. If you want to uninstall Anaconda, you should also remove its path from the .bash_profile.

In this post, I will show how to uninstall the Anaconda distribution and remove its path from the .bash_profile on Ubuntu 22. Here are the steps:

  • Install the anaconda-clean package by running the following command on the terminal:
conda install anaconda-clean
  • Run the command anaconda-clean. It creates a backup of all files and directories in a folder named .anaconda_backup in your home directory.
# If you want to confirm each file and directory you are deleting
anaconda-clean

# If you don't want to be asked about each file and directory
anaconda-clean --yes
  • Remove the entire Anaconda directory from your home holder by running the following command:
rm -rf anaconda*
rm -rf .anaconda_backup
  • To remove its path from .bash_profile, open .bashrc file in an editor, e.g.
nano .bashrc
  • Scroll down and look for “conda initialize.” The code block should look like the following:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/USER/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/USER/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/USER/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/USER/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
  • Delete every lines between “# >>> conda initialize >>>” and “# <<< conda initialize <<<” including these two.
  • Close the terminal and open it again. You will not find the conda environment activated automatically.

Hope these steps work for you. Please let me know in the comment section.

Reference 1

Similar Posts

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.