Every now and then, you need to edit the Windows system PATH or add an Environment variable. This is especially so if you want to use applications without installing them. This post shows how you can do that.
Changing the PATH or adding a new system environment variable permanently is done in very much the same way. You also have a choice to add it only for your User or for all users on the system. In my case, both options are very similar, so I follow this guide:
- If it relates to using applications without installation, I would likely want it to be available to any user I log in as – I add them to the SYSTEM then.
- If it related to my user directly, I would add them to the User variables. This is often the case when it refers to my user paths, etc.
Changing the PATH
1. You can edit the PATH using the GUI. Open up the Settings App and search for ‘environment’ and select the option to Edit the system environment variables
2. At the bottom of the window, click on Environment Variables
3. This brings you to the interface for the environment variables. The top half is to change the user settings and the lower half changes the system settings (i.e., for all users).
4. To update the PATH for all users, click on PATH in the lower list and click on Edit which brings up this display.
5. To add a path, click on New and add it in. If you want to change its position, you can click on Move Up (increase its priority – used first) or Move Down (reduce its priority).
6. Once done, click on OK and then click on OK on the previous screen.
The next time you open a console window, it will be used.
Set Environment Variables From the GUI
We use the same panel but click on New just below the user variables or the system variables to add a new environment variable.
Once you click on it, you get a window like the one below – add the variable name and its value and click OK. You can click on Browse Directory… or Browse File… if the variable is meant to be a directory or a file.
Set Environment Variables From the Command Line
You can add or edit Environment Variable from the command line by using setx
(for the current user) or setx /M
(for all users).
So, if you want to set an environment variable called THREAD_COUNT
and set it to 10, we could do:
$ setx /M THREAD_COUNT 10
It will then be set for all users. This will take effect from the next time you open the console. We use this approach for setting a more verbose prompt in the Windows console. You can read more about setx online since it has a lot of options.
That’s all there is. If you have any other thoughts or questions, feel free to comment below, or connect with onghu@x or @onghu@ruby.social on Mastodon or @onghu.com on Bluesky to discuss more.