A detailed guide on how to create Environment Variables on Windows 11
You have probably just learned about Environment Variables and would like to know how to create one on your Windows device. This variable is one that your computer automatically produces and updates. It helps the computer easily locate programs, install files, and search for user and system settings.
Additionally, it can be accessible via command-line and graphical tools from any location on the computer. Setting up Environment Variables is necessary to let the system know which executable file to run when given a command, however, some users have encountered some errors using this tool. If you are finding it difficult to use this tool, this guide will teach you how to confidently use it.
Things to know about Environment Variables
There are two types of variables. These are:
- System Environment Variables – These are global variables that are accessible to everyone on the system. They are mainly used to define system-wide configuration settings.
- User Environment Variables – This variable can only be accessed by the individual who is presently logged into the system. This stops the system from automatically creating and maintaining the environment variable for each user. An example of user variables includes the location of a temporary file. Other user accounts are unable to change these variables, only the logged-in user account may.
1. Set up an Environment Variable using the Settings app
Setting up environment variables is just one of the many things you can do using your Windows computer’s Settings software. Although the System Properties dialog box and the Command Prompt can also be used to manipulate environment variables, the Settings program provides a more convenient and straightforward interface for this purpose. Follow the steps below to do this.
- Press Windows + I to open the Settings application.
- Go down and select About.
- Go to Device Specifications, and select Advanced system settings.
- In the next window, click the Environment Variables button.
- Choose either the System or User environmental variable, then click the New button.
- Give the variable a name. Ensure there are no spaces.
- Go to the Browse Directory or the Browse File buttons to assign the new variable to the desired location.
- Once the variable name and value have been set, click OK.
- With this, you have successfully created an Environment Variable.
2. Use the command prompt
The command prompt is another way to create an Environment Variable because it allows you to communicate directly with your computer. Follow the steps below to learn how to do this.
- Press Windows + R to open the Run dialogue, type cmd in the text field, then hold Ctrl + Shift + Enter to open the command prompt as an administrator.
- Input the command below to add a temporary variable to your computer and hit Enter. Replace VariableName & Variablevalue with the ones you want.
set VariableName = Variablevalue
- This is a temporary Environment Variable and will be deleted once the window is closed.
- If you want to set it permanently, enter the command below and hit Enter. Replace Variablename and Value with the ones you want.
setx Variablename Value /m
- Input the command below to list all the path variables, and hit Enter.
- To add another variable to the path directory, input the command below and hit Enter. Replace PATH Value with the path you want to add.
setx PATH "%PATH%; PATH Value
- Doing this will help you create a new Environment Variable.
3. Use the Windows PowerShell
PowerShell is a cross-platform scripting language and management shell designed by Microsoft. Its powerful command-line interface (CLI) lets you change settings, automate procedures, and administer systems. You can use this powerful tool to create an Environment Variable by following the steps below.
- Hit the Windows key, input PowerShell in the search bar, then click Run as Administrator.
- Input the command below, and hit Enter.
- To declare a path variable, enter the command below. Replace PATH with the required path, then hit Enter.
$Variable_Name = "PATH"
- To include this variable in the Path Variable list, input the command below and press Enter. Replace Folder PATH with the required path.
[Environment]::SetEnvironmentVariable(“Folder PATH”, “$PATH;$Variable_Name”)
- Finally, reboot your computer to implement the changes you just made.
How can I access my New Variable?
1. Use the Start menu method
This is by far the most straightforward way of accessing your new variable. Follow the steps below to know how to use this feature.
- Click the Start menu (Windows icon) on your computer.
- In the text field, input the code below. Replace variable with the name of the variable you want.
- Once you enter this command, you will be taken to your new variable.
2. Make use of the command prompt
With the command prompt which is a text-based interface, you may use commands to communicate directly with your computer. This tool also allows you to access your Environment Variable by using specific commands. See the steps below to learn how to use the command prompt to access your new variable.
- Press Windows + R to bring up the Run dialogue, type cmd in the text field, then hit Enter.
- Once you are in the command prompt, input the code below, and hit Enter. Replace variable name with the actual name of the variable.
- Once you enter this command, you will be taken to your variable.
3. Make use of PowerShell
Microsoft created PowerShell, a cross-platform, task-based management shell and scripting language. It has a robust command-line interface (CLI) that lets you manage systems, automate processes, and adjust settings. You can also use this tool to access your new variable by following the steps below.
- Hold Windows + S to launch the Search bar, type powershell in the text field, and choose the relevant option.
- Once PowerShell is opened, input the command below. Replace variable with the name of the newly created one you want to access.
- Once you run this command, it will open your new variable.
Edit Environment variables
Editing your Environment variables provides you with an easier way to use and access your variables. The steps below will show you how to achieve this.
- Press Windows + S to bring up the Search bar, input edit ENV, then choose the required option.
- Select the variable you would like to edit, then click the Edit button.
- In the next window that comes up, modify your variable by changing either the name or value.
- Once you are done, click OK.
- If you would also like to delete a variable, simply click on the Delete button.
Wrapping things up
We have successfully gone through 3 effective ways to create Environment Variables on Windows 11. Follow these steps carefully to get a positive result and remember to reach out to us via the comment section if you have further questions.