Environment Variables#

Note

This is for Windows Operating Systems only.

Your computer has environment variables which define the behavior of your operating system. For example, one commonly used variable is PATH, which helps your computer locate key files, especially when using a CLI.

Tip

Keep in mind that the Windows OS allows you to set environment variables for a specific user as well as for the system (all users). It is important to note which environment variable you should set for a given activity, as choosing the wrong one can have unintended consequences (or lead to much frustration!). The difference can be seen in the example here:

../../_images/environment_var_system_user.png

Fig. 13 Environment variables, highlighting the difference between those for the user and system (all users).#

The PATH Variable#

The PATH variable is like an address book for your computer: it lists various folders (directories) where the computer should look when executing commands. Updating the PATH variable is often required when installing software that is to be used with a CLI. In addition, updating this variable is often the solution to the problem of trying to execute a command and getting a “not found” message in response. For example, the following Windows Command Prompt illustrates what happens when (first) a command is executed that cannot be found by the CLI and (second) conda is called:

C:\Users\YOUR_USERNAME>software_that_is_not_on_path --version
'software_that_is_not_on_path' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\YOUR_USERNAME>conda --version
conda 23.11.0

Tip

Note the two dashes used with --version, not one, -!

The message that is returned with the conda version number indicates not only that conda is installed and that it is findable via the Windows PATH environment variable.

Setting the PATH Variable#

Setting the PATH variable is as simple as giving the path to the folder (directory) where the file or program of interest is located. All that is needed is to explain where the variable needs to be updated.

The easiest way to find the appropriate setting window is by typing the first letters of “environment” in the Windows toolbar. The first three letters are usually enough to cause several relevant options to appear; select Edit environment variables for your account and see the figure below for an illustration:

As a general rule you should only adjust the PATH variable for the user, not the system. Failing to do this is a common mistake and leads to frustration when installing applications like Anaconda and Miniconda.

To set the right variable, pay particular attention to the descriptions provided in the environment variable window, as it is easy to miss; the right location is illustrated clearly in the following figure:

../../_images/environment_var_miniconda_not_system.png

Fig. 15 Unless specified otherwise, don’t set an environment variable for the system, only your account!#

Once you have identified the proper (user) window, look for the PATH variable, select it, then click the “Edit…” button. If the variable value is empty, you will probably see a window similar to that in the following figure; enter (paste) the path of the folder (directory) you wish to add to the path in the field “Variable value” then click “OK.” Note that you can browse for the file and folder of interest via the settings window if you did not already copy the path via the File Explorer or a CLI.

../../_images/environment_var_miniconda.png

Fig. 16 How to add a folder (directory) location to the PATH variable. The example here is for Miniconda.#

If there are already values set for the PATH variable then the “Edit…” button will probably show a window like that in the following figure. In this case, you can add a new path via the “New” button; paste the path in an open row of the list. Note that you can browse for the file and folder of interest via the settings window if you did not already copy the path via the File Explorer or a CLI.

../../_images/environment_var_PATH_examples.png

Fig. 17 Example showing folders (directories) that have already been added to the PATH variable. Note the “New” and “Edit” buttons.#

The following figure illustrates exactly where you should paste your desired folder (directory) path after clicking the “New” button:

../../_images/environment_var_PATH_new.png

Fig. 18 How to add a folder (directory) location to the PATH variable using the “New” button.#

Checking PATH Configuration#

To check that your PATH variable was properly configured you should use a CLI to see whether your program of interest is now findable. For example, if you added the location of conda.exe to PATH you should now be able to execute conda --version (note the two dashes, --, not one, -!), which will return the following:

C:\Users\YOUR_USERNAME>conda --version
conda 23.11.0

Tip

You usually need to restart a CLI for changes to the variables to take effect. Simply closing and reopening the CLI is usually enough. If you are completely sure that the setup was done properly, it may also be prudent to restart your computer.