Add environment variables in Windows

Often, when I write about command line-based software or scripting I will tell you to “add a software to PATH“.

But what does exactly that mean?

PATH is one of Windows environment variables. If you want to run scripts or applications that don’t come with an installer, you will need to “add the application location to PATH“.

But hold on a second before we get to that…

What are environment variables?

Environment Variables are variables in Windows that contain specific information. You might already know about some of them.

For example, if you enter %windir% in Windows Explorer, you will be taken to the Windows installation directory, which is usually C:\Windows.

Illustration of the %windir% environment variable in Windows 10

Likewise, in Command Prompt you can enter echo %NUMBER_OF_PROCESSORS% to see how many cores your processor have.

Illustration of NUMBER_OF_PROCESSORS environment Variable in Windows 10

These commands are what we call environment variables.

PATH is a different type of variable. If you add a location on your computer containing a software or script to the PATH variable, you can use that software or script in Windows without having to enter the absolute path every time. So in the command prompt, instead of entering C:\application\myapp.exe everytime you can just write myapp.

Add a software or script to the PATH variable

If you want a portable/standalone software or script to be available for command prompt or PowerShell, you can add the location for the software or script to the PATH variable in Windows.

Click on Start and start typing environment to search for the setting. Click on Edit the system environment variables.

Click on Environment Variables…

Now you have two options…

You can either add a user variable or a system variable.

User variables will only work for the currently logged-in user. System variables will be available for all users in Windows.

Depending on your choice, double click on one of the lines that say Path.

Click on Browse… to add a Windows location to the Path variable.

Select the folder in which your application resides. This should be the parent folder of an EXE file or a script file. Note that we are adding the path for the file, not the file itself. Click on OK.

Click on OK again on the windows behind to close the settings and apply the changes.

You have now added your application to PATH and you may now use the application in command prompt, PowerShell, or Windows Terminal.

List all environment variables in Windows

You can find a list of all default Windows variables here.

You can list all environment variables easily by opening command prompt and type set.

For the PATH variables specifically, you can type set PATH.

Editing Environment Variables in the registry

The Environment Variables for the system is stored in the Registry under:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

You should not try to add new values to PATH by adding reg-files because this will overwrite the existing values and possibly corrupt Windows completely.

Leave a Reply

Your email address will not be published. Required fields are marked *