How To

How to Create Environment Variables on Windows 11: Top 3 Ways

A detailed guide on how to create Environment Variables on Windows 11

38views

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.

  1. Press Windows + I to open the Settings application.
  2. Go down and select About.
    create Environment Variables on Windows 11
  3. Go to Device Specifications, and select Advanced system settings.
    create Environment Variables on Windows 11
  4. In the next window, click the Environment Variables button.
  5. Choose either the System or User environmental variable, then click the New button.
    create Environment Variables on Windows 11
  6. Give the variable a name. Ensure there are no spaces.
  7. Go to the Browse Directory or the Browse File buttons to assign the new variable to the desired location.
    create Environment Variables on Windows 11
  8. Once the variable name and value have been set, click OK.
  9. 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.

  1. 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.
    create Environment Variables on Windows 11
  2. 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

  3. This is a temporary Environment Variable and will be deleted once the window is closed.
  4. 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
    create Environment Variables on Windows 11
  5. Input the command below to list all the path variables, and hit Enter.
    echo %PATH%
  6. 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
  7. 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.

  1. Hit the Windows key, input PowerShell in the search bar, then click Run as Administrator.
  2. Input the command below, and hit Enter.
    [Environment]::GetEnvironmentVariable(“PATH”)
  3. To declare a path variable, enter the command below. Replace PATH  with the required path, then hit Enter.
    $Variable_Name = "PATH"
    create Environment Variables on Windows 11
  4. 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”)
  5. 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.

  1. Click the Start menu (Windows icon) on your computer.
  2. In the text field, input the code below. Replace variable with the name of the variable you want.
    %variable%
  3. 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.

  1. Press Windows + R to bring up the Run dialogue, type cmd in the text field, then hit Enter.
    create Environment Variables on Windows 11
  2. Once you are in the command prompt, input the code below, and hit Enter. Replace variable name with the actual name of the variable.
    echo %variablename%
  3. 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.

  1. Hold Windows + S to launch the Search bar, type powershell in the text field, and choose the relevant option.
    create Environment Variables on Windows 11
  2. Once PowerShell is opened, input the command below. Replace variable with the name of the newly created one you want to access.
    Write-Output $env.variable
  3. 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.

  1. Press Windows + S to bring up the Search bar, input edit ENV, then choose the required option.
    create Environment Variables on Windows 11
  2. Select the variable you would like to edit, then click the Edit button.
  3. In the next window that comes up, modify your variable by changing either the name or value.
    create Environment Variables on Windows 11
  4. Once you are done, click OK.
  5. If you would also like to delete a variable, simply click on the Delete button.
    create Environment Variables on Windows 11

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.

Leave a Response

David Ogbor
David is a tech guru with extensive knowledge in technical articles. He is passionate about writing and presents technical articles in an easy-to-understand format for easy comprehension. He aims to present easy solutions for day-to-day problems encountered while using PC. In his spare time, he likes traveling, playing sports, and singing.