Environment Variables#
Note
This is for Windows Operating Systems only. It is often required when installing command line tools, for example conda
.
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:
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.
Before you start, find your desired path!
These instructions assume that you have already identified the path of the folder (directory) which needs to be added to the PATH
variable. On windows, the easiest way to do this is to navigate to the folder using the File Explorer, then click in the address bar near the top and copy the text, which should look something like this:
C:\Users\<your user name>\miniconda3\Scripts
In this case, the folder (directory) contains the executable files conda.exe
, which is what makes the command conda
possible to use on the CLI. Thus, the full path to conda.exe
is this:
C:\Users\<your user name>\miniconda3\Scripts\conda.exe
Note also that depending on your system settings, or if you are copying the path from a CLI, you may need to adjust the separators from a forward slash /
to a backward slash \
; the PATH
variable on Windows requires a backward slash \
.
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:
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.
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.
The following figure illustrates exactly where you should paste your desired folder (directory) path after clicking 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.