Ever spent 30 minutes chasing a broken PATH because you didn’t know how to view environment variables?
View environment variables should be the first check when a script or app can’t find a binary.
This quick guide lists the exact commands for Windows (CMD, PowerShell, GUI), Linux, and macOS so you can inspect or filter variables in seconds.
I’ll point out the common gotchas—PATH separators, session vs system scope, and GUI vs terminal differences—so you don’t waste time.
Quick Ways to View Environment Variables Across Windows, Linux, and macOS

Environment variables store configuration data that programs and shells use to locate files, set language preferences, define user directories, and control application behavior. You’ll check them to troubleshoot missing paths, verify configuration, and make sure scripts run correctly across different machines.
Windows gives you three ways to do this. From Command Prompt, type set to list everything as name=value pairs, or use echo %VARIABLE_NAME% to inspect just one (like echo %PATH% to see all search directories). PowerShell users run Get-ChildItem Env: for a formatted table, or read a specific variable with $Env:VARIABLE_NAME (something like $Env:Path). The GUI approach opens System Properties by pressing Win+R, typing sysdm.cpl, hitting Enter, clicking the Advanced tab, then clicking Environment Variables to view user and system scopes side by side.
Linux and macOS users stick to terminal commands. Run printenv or env to list everything, or echo $VARIABLE_NAME to check a single value (try echo $PATH). Filtering large outputs is common: printenv | grep PATH narrows results to PATH-related variables. Both platforms use colon separators in PATH instead of Windows semicolons.
Variables worth checking across all systems:
- PATH – directories the shell searches for executables
- HOME – current user’s home directory (on Windows, see %USERPROFILE%)
- USER – username of the current session (USERNAME on Windows)
- TEMP or TMP – temporary file storage location
- SHELL – path to the active shell interpreter (Linux/macOS only)
Windows Methods to View Environment Variables (CMD, PowerShell, GUI)

Command Prompt displays variables in plain text when you type set. Each line shows NAME=VALUE with no table formatting. To check a specific variable, type echo %VARIABLE_NAME% (something like echo %USERPROFILE% prints your user folder). Variables set during a CMD session with set MY_VAR=TestValue are temporary. They disappear when the window closes. Filtering helps when you’re reviewing long lists: set | findstr PATH shows only lines containing “PATH.”
PowerShell gives you richer output. Type Get-ChildItem Env: to see a table with Name and Value columns. Shorter aliases like gci Env:, dir Env:, and ls Env: produce the same result. To read a single variable, use $Env:VARIABLE_NAME (try $Env:Path to display search directories). PowerShell also supports filtering: Get-ChildItem Env: | Where-Object { $_.Name -like '*PATH*' } narrows results. Session-only variables created with $Env:MY_VAR = "TestValue" vanish when the PowerShell window closes.
The GUI method works well when you want to inspect or edit variables without typing commands. To open it:
- Press Win+R, type
sysdm.cpl, and press Enter. - In System Properties, click the Advanced tab.
- Click the Environment Variables button near the bottom.
- Review the two sections: User variables for the current account and System variables for all users (editing system variables requires administrator rights).
User variables apply only to your account. System variables affect every user on the machine and often include PATH, TEMP, and OS-level settings. The GUI clearly separates these scopes, so it’s easy to see where a variable is defined. Changes made in the dialog take effect after clicking OK and sometimes require signing out or rebooting to apply fully. GUI editing is slower than CLI commands but reduces the risk of syntax errors when you’re modifying PATH or creating new variables.
Linux Commands to View and Filter Environment Variables

Linux shells expose environment variables through built-in commands that print name=value pairs to the terminal. Running printenv lists all variables, one per line. The env command produces identical output and you can swap them freely in most contexts. To check a single variable, use echo $VARIABLE_NAME (like echo $PATH to display directories the shell searches for executables).
| Command | Purpose |
|---|---|
| printenv | List all environment variables |
| env | List all environment variables (identical to printenv) |
| echo $VAR | Display value of a single variable |
Filtering large outputs is common when you’re hunting for specific settings. Pipe printenv or env to grep to narrow results: printenv | grep PATH shows only PATH-related variables. Linux uses colon separators in PATH, so /usr/bin:/usr/local/bin:/home/user/bin is typical. To create a temporary variable for the current session, run export MY_VAR="TestValue". It disappears when the terminal closes. Persistent variables go into shell startup files like ~/.bashrc, ~/.profile, or ~/.bash_profile, depending on the shell and login type.
macOS Techniques to Inspect Terminal and System-Level Environment Variables

macOS defaults to zsh as the system shell since macOS Catalina. Terminal users run printenv or echo $VARIABLE_NAME to view variables (try echo $HOME to print the user directory). Filtering works the same as Linux: printenv | grep PATH narrows output to PATH entries.
Persistent user-level variables live in ~/.zshrc or ~/.zprofile. To make a variable available in every terminal session, add export MY_VAR="TestValue" to one of these files, save, and restart the terminal or run source ~/.zshrc. System-wide PATH directories are defined in /etc/paths and individual files under /etc/paths.d, which the system reads at startup and merges into the PATH variable.
GUI applications launched from Finder or the Dock don’t inherit variables from terminal startup files. To inject environment variables into GUI processes, use launchctl setenv VARIABLE_NAME value in a terminal. This applies for the current login session but doesn’t persist after reboot. For permanent GUI variables, create a LaunchAgent plist file in ~/Library/LaunchAgents or /Library/LaunchAgents with the ProgramArguments key calling launchctl or setting EnvironmentVariables directly.
Viewing Environment Variables in Containers (Docker and Kubernetes)

Docker containers inherit environment variables from the image, Dockerfile ENV directives, docker run flags, and docker-compose configuration. To inspect variables in a running container, use docker exec <container_name> printenv. This lists all name=value pairs inside the container. The docker inspect <container_name> command outputs JSON metadata including the Config.Env array, which holds environment variables set during container creation.
Docker Compose supports an env_file directive that loads variables from a file and injects them into the container. Multiple env files can be specified, and variables defined in the compose YAML under environment: take precedence over envfile entries. When you’re debugging missing configuration, compare docker exec output to the expected envfile contents and verify that the compose service definition includes the correct environment block.
Kubernetes pods expose environment variables through container specs in manifests. To view variables inside a running pod, run kubectl exec <pod_name> -- printenv or kubectl exec <pod_name> -- env. If the pod has multiple containers, specify the container name with -c <container_name>. Pod manifests define variables in spec.containers[].env, and ConfigMaps or Secrets can be mounted as environment variables using envFrom. The downward API lets you automatically inject pod metadata (like pod name, namespace, or resource limits) into environment variables by referencing fieldRef or resourceFieldRef in the env definition.
Common commands for container environment inspection:
docker exec <container> printenv– list all variables in a running Docker containerdocker inspect <container>– view container metadata including Config.Env arrayenv_file:directive in docker-compose.yml – load variables from a filekubectl exec <pod> -- printenv– list all variables in a Kubernetes pod- Downward API in pod spec – inject pod metadata as environment variables automatically
Viewing and Accessing Environment Variables in Popular Programming Languages

Node.js
Node.js exposes environment variables through the global process.env object. Read a variable by accessing process.env.VARIABLE_NAME (something like const dbHost = process.env.DB_HOST;). All values are strings. If a variable is undefined, accessing it returns undefined rather than throwing an error. Node.js reads variables from the parent process environment at startup, so any variable set in the shell before running node app.js appears in process.env.
Python
Python’s os module provides the os.environ dictionary for environment variable access. Read a variable with os.environ.get('VARIABLE_NAME') or os.environ['VARIABLE_NAME']. Using get returns None if the variable doesn’t exist, while bracket notation raises a KeyError. To list all variables, iterate over os.environ.items() (like for key, value in os.environ.items(): print(f"{key}={value}")).
Java
Java applications access environment variables via System.getenv(). Call System.getenv("VARIABLE_NAME") to retrieve a single variable or System.getenv() without arguments to get a Map<String, String> of all variables. For example, String path = System.getenv("PATH"); reads the PATH variable. If a variable isn’t set, getenv returns null.
Additional language equivalents for reading environment variables:
- PHP:
getenv('VARIABLE_NAME')or access the$_ENVsuperglobal ifvariables_orderincludes “E” - Ruby:
ENV['VARIABLE_NAME']orENV.fetch('VARIABLE_NAME')to raise an error if missing - Go:
os.Getenv("VARIABLE_NAME")returns an empty string if undefined;os.LookupEnvreturns a boolean indicating presence - C#:
Environment.GetEnvironmentVariable("VARIABLE_NAME")orEnvironment.GetEnvironmentVariables()for all - Rust:
std::env::var("VARIABLE_NAME")returns aResult<String, VarError> - Bash scripts:
$VARIABLE_NAMEor${VARIABLE_NAME}to reference variables inline
Tools and Techniques for Filtering, Comparing, and Debugging Environment Variables

Filtering large environment variable lists saves time when you’re hunting for specific settings. On Windows Command Prompt, pipe set to findstr (try set | findstr JAVA to show variables containing “JAVA”). PowerShell users combine Get-ChildItem Env: with Where-Object to match patterns: Get-ChildItem Env: | Where-Object { $_.Name -like '*PATH*' }. Linux and macOS rely on grep and sort for filtering: printenv | grep -i user finds user-related variables case-insensitively, and env | sort alphabetizes output for easier scanning.
| Command | Platform | Purpose |
|---|---|---|
| set | findstr PATH | Windows CMD | Filter variables containing “PATH” |
| Get-ChildItem Env: | Where-Object { $_.Name -like ‘*PATH*’ } | Windows PowerShell | Filter variables matching pattern |
| printenv | grep PATH | Linux / macOS | Filter variables containing “PATH” |
Comparing environment variables between sessions helps debug configuration drift. Open two terminal windows, run printenv > session1.txt in the first and printenv > session2.txt in the second, then use diff session1.txt session2.txt to spot differences. On Windows, use set > session1.txt and fc session1.txt session2.txt to compare. Missing variables often appear when switching between interactive and login shells, since shells like bash read different startup files (~/.bashrc vs. ~/.profile). Check that variables expected in scripts are exported, not just assigned, and verify that PATH modifications in startup files actually run by sourcing the file manually and re-checking echo $PATH.
Final Words
We ran through the fastest, command-line-first ways to inspect OS and container environments: CMD and PowerShell on Windows, printenv/env and echo on Linux, and zsh/printenv plus launchctl on macOS.
You also saw how to check variables inside Docker and Kubernetes, and how common languages expose env values (process.env, os.environ, System.getenv). Filtering and GUI tips were included for quick triage.
Now you can view environment variables quickly and confidently during debugging or setup. Happy debugging — you’ve got this.
FAQ
Q: How to view the environment variables and get a list of all environment variables?
A: To view environment variables and list them, run: Linux/macOS: printenv or env (or echo $VAR); Windows CMD: set; PowerShell: Get-ChildItem Env:; filter with grep or findstr.
Q: How do I see all environment variables in Windows and Windows 11?
A: To see all environment variables in Windows or Windows 11, use CMD: set or echo %VAR%; PowerShell: Get-ChildItem Env:; or open System Properties → Advanced → Environment Variables to view user and system scopes. Use findstr to filter.
