Environment variables are pairs of key- values which helps in programming system behavior of the PC. They are used in scripts and on command line and are useful for locating custom directories which varies indifferent PCs. There exists two categories of environment variables, such as – user environment variables (for present user) and system (machine) environment variables (for all users). Hence, it is very essential to learn creating new environment variables in Windows 11.
Page Contents
How to create new environment variables in Windows 11
There exists various ways for creating new environment variables in Windows 11. Let us delve into all the methods in detail.
Method 1: Creating new user environment variables in PowerShell
Now, let us check the steps to create new user environment variables in PowerShell-
Step 1- Firstly, go to Windows Terminal > Windows PowerShell.
Step 2- Next, copy and paste the command prompt given below and click Enter. Moreover, in place of [variable name] write the variable name wanting to use as an environment variable and in place of [variable value] write the variable value wanting the environment variable to refer to.
[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","User")
Step 3- Lastly, close the Windows PowerShell window.
Method 2: Creating new user environment variables in Environment Variables
The following steps will allow us to create new user environment variables in Environment Variables-
Step 1- At first go to Control Panel > User Accounts (View by icon) > Change my environment variables.
Step 2- This will open the window given below-
rundll32.exe sysdm.cpl,EditEnvironmentVariables
Step 3- Now, below the top User variables <present username> section, select New option.
Step 4- Further, type a Variable name and then a Variable value. Here, the variable name must be the name the user wants to use as an environment variable and the variable value must be the value the user wants the environment variable to refer.
Step 5- Also, to search and locate a directory and a file for the required variable name and value, select Browse Directory and Browse File.
Step 6- Lastly, select OK.
Method 3: Creating new user environment variables in PowerShell
The steps given below will help in creating new user environment variables in PowerShell.
Step 1- First of all, go to Windows Terminal and Run it as an administrator.
Step 2- Secondly, go to Windows PowerShell and copy and paste the prompt given below. Thereafter, select Enter.
[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","Machine")
Here, the [variable name] must be the name the user wants to use as an environment variable and the [variable value] must be the value the user wants the environment variable to refer to.
Step 3- Now, shut the window of Windows Terminal.
Method 4: Creating new user environment variables using “setx” Command
To create new user environment variables using setx command, follow the instructions below-
Step 1- Primarily, go to Windows Terminal and choose Windows PowerShell/Command Prompt.
Step 2- Now, copy and paste the command prompt below and click Enter. Here, the [variable name] must be the name the user wants to use as an environment variable and the [variable value] must be the value the user wants the environment variable to refer.
setx [variable name] "[variable value]"
Step 3- Finally close the Windows Terminal.
Method 5: Creating new user environment variables in Environment Variables
The steps for creating new user environment variables in Environment Variables as an administrator are as follows-
Step 1- At first, make sure to be signed in as an administrator and then go to Advanced System Properties.
Step 2- Now, select Environment Variables. Thereafter, below the section of System variables, select New.
Step 3- Again, enter a Variable name and value. Moreover, to search and locate a directory and a file for the required variable name and value, select Browse Directory and Browse File.
Step 4- Lastly, select OK.
Method 6: Creating new user environment variables using “setx” Command
For creating new user environment variables using setx command, follow the steps given below-
Step 1- Firstly, sign-in as an administrator.
Step 2- Next, go to Windows Terminal and run it as an administrator. Now, press Windows PowerShell.
Step 3- Further, copy and paste the prompt given below and press Enter.
setx [variable name] "[variable value]" /m
Here, the [variable name] must be the name the user wants to use as an environment variable and the [variable value] must be the value the user wants the environment variable to refer.
Step 4- Now, close the Windows Terminal.
Leave a Reply