Checking environment variables is a fundamental task for understanding system configurations, troubleshooting applications, and verifying development setups. These variables store crucial information that processes and programs use to function correctly.
Checking Environment Variables on Windows
On Windows, there are several straightforward ways to inspect environment variables, depending on whether you want to view a specific variable or list all of them.
1. Using Command Prompt (CMD)
This method is quick and effective for both specific and general checks.
-
To check a specific environment variable:
- Open the Command Prompt. You can do this by typing
cmd
in the Start menu search bar and pressing Enter. - In the command window, type
echo %VARIABLE_NAME%
and press Enter. ReplaceVARIABLE_NAME
with the actual name of the environment variable you want to check (e.g.,echo %PATH%
orecho %NUKE_DISK_CACHE%
). - The value of the variable, if set, will be displayed. If it's not set, it will typically echo the variable name itself (e.g.,
%NUKE_DISK_CACHE%
) or nothing, depending on the shell configuration.
- Open the Command Prompt. You can do this by typing
-
To list all environment variables:
- Open the Command Prompt.
- Type
set
and press Enter. - This command will display a comprehensive list of all environment variables currently set for your user session, including both user-specific and system-wide variables.
2. Using PowerShell
PowerShell offers similar functionality to CMD, with some object-oriented advantages.
-
To check a specific environment variable:
- Open PowerShell (search for
PowerShell
in the Start menu). - Type
$env:VARIABLE_NAME
and press Enter (e.g.,$env:PATH
or$env:TEMP
). - The value of the variable will be displayed.
- Open PowerShell (search for
-
To list all environment variables:
- Open PowerShell.
- Type
Get-ChildItem Env:
orGet-Item Env:
and press Enter. - This will list all environment variables along with their values. You can pipe this to
Format-Table
orFormat-List
for better readability.
3. Using the Graphical User Interface (GUI)
The System Properties window allows you to view and modify environment variables through a user-friendly interface.
- Right-click on the Start button and select System (or search for "Environment Variables" in the Start menu).
- In the System window, click on Advanced system settings on the right or bottom.
- In the System Properties dialog, navigate to the Advanced tab and click the Environment Variables... button.
- Here, you will see two sections: User variables for [Your Username] and System variables. You can select any variable from these lists to view or edit its value.
Checking Environment Variables on Linux and macOS
Unix-like systems (Linux, macOS) provide powerful command-line tools for managing environment variables.
1. To check a specific environment variable:
- Open a terminal window.
- Type
echo $VARIABLE_NAME
and press Enter (e.g.,echo $PATH
orecho $HOME
). - The value of the variable will be printed to the console. If the variable is not set, this command will typically output an empty line.
2. To list all environment variables:
Multiple commands can be used, each with slight differences in scope:
-
env
:- This command lists all environment variables that are set for the current shell session. It typically shows variables that are inherited by child processes.
- Usage:
env
-
printenv
:- Similar to
env
,printenv
displays all environment variables. You can also use it to check a specific variable by providing its name (e.g.,printenv PATH
). - Usage:
printenv
- Similar to
-
declare -x
(Bash/Zsh):- This command, specific to Bash and Zsh shells, lists all exported shell variables, which include environment variables. It also shows shell functions that are exported.
- Usage:
declare -x
-
set
:- The
set
command (without arguments) lists all shell variables, including environment variables, local variables, and shell functions. This can be a very long list. - Usage:
set
- The
Summary Table
Operating System | Action | Command/Method | Description |
---|---|---|---|
Windows | Check specific variable | echo %VARIABLE_NAME% (CMD) / $env:VARIABLE_NAME (PowerShell) |
Displays the value of a single environment variable. |
Windows | List all variables | set (CMD) / Get-ChildItem Env: (PowerShell) |
Shows all environment variables for the current session. |
Windows | GUI Method | System Properties > Environment Variables | View and modify variables through a graphical interface. |
Linux/macOS | Check specific variable | echo $VARIABLE_NAME |
Displays the value of a single environment variable. |
Linux/macOS | List all variables | env / printenv / declare -x |
Shows all environment variables for the current session. |
Understanding how to check environment variables is crucial for debugging application issues, configuring software, and ensuring your system behaves as expected.