Back to docs
Tools - ConfigurationUpdated: November 23, 2024

set

See, set, or remove Windows environment variables.

set

Command: set

Category: Configuration

Type: CMD

Purpose

Displays, sets, or removes environment variables in the current command prompt session. Environment variables store system configuration information like file paths, system settings, and application parameters.

Quick Summary

The set command gives you quick access to all environment variables in your session. View all variables with one command, check specific values, or temporarily set new variables for testing or scripting. Essential for troubleshooting path issues and understanding system configuration.

How to Use

View all environment variables:

set

View specific variable:

set PATH
set USERNAME
set TEMP

Set a new variable (temporary, current session only):

set MYVAR=value

Append to existing variable:

set PATH=%PATH%;C:\NewFolder

Remove a variable from current session:

set MYVAR=

Tips and Best Practices

  • Use set alone to see all variables at once.
  • Use set VAR to see all variables starting with "VAR" (case-insensitive partial match).
  • Variables set with set are temporary and only last for the current session.
  • To set permanent environment variables, use System Properties > Environment Variables.
  • Common variables: PATH, TEMP, TMP, USERNAME, USERPROFILE, COMPUTERNAME, OS.
  • Use echo %VARIABLENAME% to display a variable's value in scripts.

Common Use Cases

  • Path troubleshooting: Check if directories are in the PATH variable.
  • Script debugging: View variables that might affect script behavior.
  • Temporary testing: Set variables for testing without permanent changes.
  • System information: Quickly view system-related variables.
  • Configuration verification: Confirm environment variable values.

Prerequisites

  • Windows Command Prompt (not PowerShell - use $env: or Get-ChildItem Env: in PowerShell)
  • No administrator rights required
  • Available on all Windows versions

Important Environment Variables

  • PATH: Directories Windows searches for executable files
  • TEMP / TMP: Temporary file directories
  • USERNAME: Current logged-in username
  • USERPROFILE: Current user's profile folder (C:\Users\Username)
  • COMPUTERNAME: Name of the computer
  • SYSTEMROOT: Windows installation directory (usually C:\Windows)
  • PROGRAMFILES: Program Files directory
  • OS: Operating system name
  • PROCESSOR_ARCHITECTURE: CPU architecture (AMD64, x86, etc.)

Setting Permanent Variables

Via GUI (Permanent):

  1. Right-click "This PC" or "Computer" > Properties
  2. Click "Advanced system settings"
  3. Click "Environment Variables" button
  4. Add or edit variables in User or System sections

Via Command (Permanent):

setx MYVAR "value"  (User variable)
setx MYVAR "value" /M  (System variable - requires admin)

Note: Changes made with setx don't affect the current session - open a new Command Prompt to see them.

Troubleshooting

  • Variable doesn't persist - The set command only affects the current session; use setx or GUI for permanent changes.
  • PATH too long - Windows has a character limit for PATH (approx. 2048 characters); clean up unnecessary entries.
  • Spaces in values - Use quotes: set MYVAR="value with spaces"
  • Case sensitivity - Variable names are case-insensitive in Windows.
  • Variable not found - Variable names are case-insensitive, but ensure correct spelling.

Examples

Check PATH variable:

set PATH

Temporarily add to PATH for current session:

set PATH=%PATH%;C:\MyTools

Create a temporary variable:

set TEMP_DIR=C:\Temp\MyProject
echo %TEMP_DIR%

View all variables starting with "PROC":

set PROC
  • setx - Set permanent environment variables from command line
  • path - View or set the PATH variable specifically
  • echo %VARIABLE% - Display specific variable value
  • PowerShell: Get-ChildItem Env: - View all environment variables
  • PowerShell: $env:VARIABLENAME - Access specific variable