How to rename a Conda environment [2 simple Ways]

avatar
Borislav Hadzhiev

Last updated: Apr 11, 2024
2 min

banner

# How to rename a Conda environment

To rename a conda environment:

  1. Use the conda env list command if you need to get the name of the environment.
shell
conda env list

get environment you want to rename

  1. Deactivate the environment if it's currently active.
shell
conda deactivate

deactivate the conda environment

  1. Use the conda rename -n old_name new_name command to rename the environment.

The following example runs the command in with the --dry-run option to test the expected behavior.

shell
conda rename -n old_name --dry-run new_name

Once you're ready to run the real command, remove the --dry-run option.

shell
conda rename -n old_name new_name

The conda rename command renames a conda environment via its name.

The -n (--name) option is used to specify the current name of the conda environment.

When the -d (--dry-run) option is set, the command only displays what would have happened if you had run it without the flag but it doesn't actually change the environment's name.

Note that you can't rename the base environment.

# Renaming a conda environment by creating a new one and cloning it

If you use an older conda version ( < 4.14), you might have to rename the environment in a couple of steps:

  1. Deactivate the current environment.
shell
conda deactivate

Note that you can't rename a conda environment that is currently active.

  1. Create a new environment.
shell
conda create --name new_name --copy --clone old_name

conda create new environment copying old one

  1. Remove the old environment.
shell
conda env remove --name old_name

However, when using this approach, conda would have to re-download the installed packages, so it is less performant than using conda rename.

There is no good reason to create a new environment and clone the old one if you use conda version > 4.14 and can use conda rename.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.