This post describes how to migrate conda environments. It is assumed that you have user-only conda and system-wide conda as described in the post.

  1. Save the full list of packages for all environments (except the base environment)

Check the existing environments.

conda info --envs

Save the list for each environment.

conda list -n <env-name> --explicit > <env-name>.spec

This is an example. $ is the command I typed and others are the output of the command.

$ conda info --envs
# conda environments:
base                     /home/hyonchoi/.miniconda3
py39-work             *  /home/hyonchoi/.miniconda3/envs/py39-work

$ conda list -n py39-work --explicit > py39-work.spec
  1. Comment out the conda-init lines in the ~/.bashrc

This is an example lines in the ~/.bashrc. You can put # at the beginning of the line to comment out the line.

# # >>> conda initialize >>>
# # !! Contents within this block are managed by 'conda init' !!
# __conda_setup="$('/home/hyonchoi/.miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
# if [ $? -eq 0 ]; then
#     eval "$__conda_setup"
# else
#     if [ -f "/home/hyonchoi/.miniconda3/etc/profile.d/" ]; then
#         . "/home/hyonchoi/.miniconda3/etc/profile.d/"
#     else
#         export PATH="/home/hyonchoi/.miniconda3/bin:$PATH"
#     fi
# fi
# unset __conda_setup
# # <<< conda initialize <<<
  1. Launch a new shell and create environments

Launch a new shell or connect in a new terminal.


For each saved list, create new environments with the same name.

conda create -n <env-name> --file <env-name>.spec