Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Set Up and Manage Environment Variables in Windows

Environment variables are essential components in the Windows operating system that store configuration values. These variables can influence the behavior of running processes and applications. In this article, we will explore how to create, modify, and manage environment variables using both the graphical user interface (GUI) and command-line tools like Command Prompt (CMD) and PowerShell.

Understanding Environment Variables

Environment variables are key-value pairs that can be used to configure the operating system and applications. Common environment variables include PATH, TEMP, and USERPROFILE.

Using the Graphical User Interface (GUI)

  1. Open System Properties:

    • Right-click on "This PC" or "Computer" on the desktop or in File Explorer.
    • Select "Properties."
    • Click on "Advanced system settings" on the left panel.
    • In the System Properties window, click the "Environment Variables" button.
  2. Add or Edit Environment Variables:

    • In the Environment Variables window, you will see two sections: "User variables" and "System variables."
    • To add a new variable, click "New" under the appropriate section.
    • To edit an existing variable, select it and click "Edit."
  3. Example: Adding a New Variable:

    • Click "New" under "User variables."
    • Enter the variable name, e.g., MY_CUSTOM_VAR.
    • Enter the variable value, e.g., C:\MyCustomPath.
    • Click "OK" to save.

Using Command Prompt (CMD)

  1. View Environment Variables:

    • Open CMD by typing cmd in the search bar and hitting Enter.
    • Type set and press Enter to display all environment variables.
  2. Set a New Environment Variable:

    • To set a new environment variable for the current session, use the set command:
      set MY_CUSTOM_VAR=C:\MyCustomPath
    • To make this change permanent, use the setx command:
      setx MY_CUSTOM_VAR "C:\MyCustomPath"
  3. Example: Adding a Path to the PATH Variable:

    • To add a new path to the PATH environment variable for the current session:
      set PATH=%PATH%;C:\NewPath
    • To make this change permanent:
      setx PATH "%PATH%;C:\NewPath"

Using PowerShell

  1. View Environment Variables:

    • Open PowerShell by typing powershell in the search bar and hitting Enter.
    • Use the Get-ChildItem cmdlet to list all environment variables:
      Get-ChildItem Env:
  2. Set a New Environment Variable:

    • To set a new environment variable for the current session:
      $env:MY_CUSTOM_VAR = "C:\MyCustomPath"
    • To make this change permanent, you can modify the registry:
  3. Example: Adding a Path to the PATH Variable:

    • To add a new path to the PATH environment variable for the current session:
      $env:PATH += ";C:\NewPath"
    • To make this change permanent:
      $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "User")
      $newPath = $currentPath + ";C:\NewPath"
      [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "User")

Conclusion

Managing environment variables in Windows is a fundamental skill for any systems engineer. Whether you prefer using the GUI, CMD, or PowerShell, Windows provides multiple ways to set and manage these critical settings.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.