A2oz

How Do You Set Environment Variables on Activate Conda?

Published in Conda Environment Management 2 mins read

You can set environment variables when activating a Conda environment using the conda env config vars command.

Setting Environment Variables

  1. Activate your Conda environment:
     conda activate your_environment_name
  2. Set the environment variable:
     conda env config vars set MY_VARIABLE your_value

    Replace MY_VARIABLE with the name of your environment variable and your_value with the value you want to assign.

  3. Verify the variable is set:
     conda env config vars list

    You should see your variable listed with its assigned value.

Example

Let's say you want to set the MY_PATH environment variable to /home/user/projects within your my_env environment:

  1. Activate your environment:
     conda activate my_env
  2. Set the variable:
     conda env config vars set MY_PATH /home/user/projects
  3. Verify the variable:
     conda env config vars list

Practical Insights

  • Environment variables are useful for storing configuration settings, paths, or other information that your programs might need.
  • You can set multiple environment variables by repeating the conda env config vars set command.
  • To unset an environment variable, use the unset command:
      conda env config vars unset MY_VARIABLE

Related Articles