This blog was last modified 233 days before.

Today for some reason I want to reinstall conda on my CentOS server so I decided to record the process.

Uninstall Older Conda

Remove Conda Scripts

First of all we need to reverse all the change conda made to our shell. To do this we use:

conda activate
conda init --reverse --all

This will remove any conda initialization scripts from all your terminal shell profiles.

Remove Conda Files

To do this we need to know where our old conda located in. Usually the default installation directory on CentOS will be: /root/anaconda3

Then we just need to remove all these files:

rm -rf /root/anaconda3

Install Latest Conda

If you just remove your older version of conda, we recommend you run reboot before installing the new conda.

Find Lastest Conda Install Script

Check out Conda Archive List to find out the lastest install .sh file.

Download And Run Script

For example if the one we want to use is: https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh, then we need to run:

curl -O https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh
bash Anaconda3-2024.02-1-Linux-x86_64.sh

Initialize Shell For Conda

Generally when installing conda, the installation script will ask if you need to automatically initialize conda for shell. Here the default option is no but we recommend to type yes at the end of the installation, so conda will do all initial work automatically for you.

But you could init conda after installation by running command below:

source /root/anaconda3/bin/activate
conda init

Notice: To make these changes into effect, you may need to close and reopen the shell.

Conda Usage Basic

Export / Import Environment

Export To File

To export a conda environment to .yml file, run:

conda activate your_env
conda export > env.yml

Or you can use

conda env export -f environment.yml

Notice that if you don't want to include the build info (for example when you want to create env cross-platform, for example, between Windows and Linux), you need to use:

conda env export --no-builds -f environment.yml

Create From File

To create an environment using .yml file, run:

conda env create -f env.yml

Install Packages

To search packages with conda, use conda search pkg_name.

To install packages using conda, use conda install pkg_name.

Activate Conda Using Bash Script

Notice when using Bash Script, you can directly using conda activate command like:

conda activate my_env
python main.py

To activate conda environment using script, you need to do things that like you manually activate conda environment when installing conda, that is:

source /root/anaconda3/bin/activate env_name
python main.py

Refs

Conda - Install Conda On Linux

Conda - Version Archive List

Conda - Environments Management

Conda - Uninstall Conda