Environment variables contain useful information about operating systems, user sessions etc. Every operating system has environment variables like Mac OS, Linux and Windows. In Windows sometimes a user needs to set the value of an environment variable. In that case, the following procedure is used:
- Open Control Panel from Start Menu and navigate to System.
- Click Advanced System Settings > Environment Variables. You’ll come across a list of already added environment variables. You can edit, add or remove System as well as User variables. It’s obvious that System variables are available everywhere, whereas User variables are specific, available only for the current user.
- There are different environment variables in Windows like %WINDIR%, %SystemRoot%, %USERPROFILE% and %APPDATA%.
- After adding variable, make sure you restart your computer for it to take effect.
How to set environment variables using CMD on Windows 10?
The above method used GUI for setting new environment variables and changing the value of old ones. In case, you want to use CMD for setting up environment variables, then use the following procedure:
- Run Command Prompt from the Start Menu of Windows 10.
- Type following command: set TalkOfWeb=%USERPROFILE%\Pictures\ and hit enter. This will add a new environment variable named %TalkOfWeb%
- Type following command: echo %TalkOfWeb% and the result will be C:\Users\yourusername\Pictures, which means that TalkOfWeb will open Pictures folder inside your user directory.
- If you want to set a permanent environment variable, which may be available even when you close shell/CMD, then use: setx TalkOfWeb “C:\Users\yourusername\Pictures” and hit enter. This setx commands creates permanent variables inside CMD.
How to set environment variables using PowerShell in Windows 10?
If unfortunately, CMD is not available in your Windows 10 installation. Then you can also use PowerShell to set an environment variable.
- Run PowerShell from the Start Menu.
- Use the following command: $env:TalkOfWeb = ‘C:\Users\yourusername\Pictures’ and hit enter. It will create an environment variable named TalkOfWeb with the value as shown in the commas.
Conclusion:
Setting and changing environment variables on Windows 10 is an easy job. You can either use GUI to change variables as shown earlier, or you can use the command prompt. If you want to set permanent variables then in some Windows versions you might need to use setx command. Other than that, changing, editing and adding new environment variables in Windows is doable using CMD, PowerShell and System Properties.