Skip to content

View Environment Variables in Windows CMD and PowerShell (PATH, JAVA_HOME)

  • by

Windows environment variables store values that programs use for configuration, such as the current username, temporary-file location, and folders searched when you run commands. To view the value of one environment variable in Command Prompt (CMD), type echo %VARIABLE_NAME%. For example, echo %PATH% shows the effective PATH available to your current CMD process.

Quick answer: Display one variable in CMD

  1. Press Windows + R, enter cmd, and press Enter. You can also open Command Prompt through Windows Search.
  2. To display your current user name, type echo %USERNAME% and press Enter.
  3. For a different variable, replace USERNAME with the variable name, keeping the % signs around it.
echo %USERNAME%
echo %USERPROFILE%
echo %TEMP%
echo %PATH%

In CMD, environment variable names are not case-sensitive. Thus %PATH% and %path% refer to the same variable in a normal Windows environment. The values above are examples of the current process environment, so they can differ by user account or Command Prompt window.

Display all environment variables with SET

Use set without arguments to print the environment variables visible to the current Command Prompt process. This can be helpful when debugging an application’s configuration, but the output may contain private paths, account identifiers, or credentials. Do not paste the unredacted result into a public forum or ticket.

set

To view variables whose names begin with a prefix, use the prefix as an argument:

set USER
set JAVA
set PATH

For example, set JAVA can display JAVA_HOME if it exists. It can also show multiple matching names or report that no variable starts with that prefix. Microsoft’s SET command reference describes both listing and setting variables.

Check whether a variable is defined

If echo %VARIABLE_NAME% prints the literal percent-sign expression, the variable is usually undefined in that CMD session. Use set VARIABLE_NAME to check. Unlike echo, the set command can report that the variable is not defined; a prefix search can also return similarly named variables. Do not assume that a variable saved in Windows settings has propagated into an already-open terminal.

set JAVA_HOME

If you are troubleshooting Java or another development tool, remember that setting JAVA_HOME is not the same as adding its executable folder to PATH. One can be correct while the other is missing.

CMD vs PowerShell: the syntax is different

In Windows PowerShell or PowerShell 7, environment variables use env:NAME</code> rather than CMD's <code class="" data-line="">%NAME%</code>. A command copied from CMD often will not work when pasted unchanged into PowerShell. <!-- /wp:paragraph -->  <!-- wp:code --> <pre class="wp-block-code"><code class="" data-line="">env:USERNAME env:USERPROFILEenv:PATH Get-ChildItem Env:

The last command lists environment variables accessible through PowerShell’s Env: drive. For more details, see Microsoft Learn: PowerShell environment variables.

Display PATH in a readable way

Windows PATH usually contains several directories separated by semicolons. To inspect them individually in PowerShell, split the current PATH on semicolons:

env:PATH -split ';'</code></pre> <!-- /wp:code -->  <!-- wp:paragraph --> If you are staying in CMD, you can still use <code class="" data-line="">echo %PATH%</code>. Do not assume a path displayed in one window has already been picked up by every running application. <!-- /wp:paragraph -->  <!-- wp:heading --> <h2 class="wp-block-heading">Why a variable may look different in a new Command Prompt</h2> <!-- /wp:heading -->  <!-- wp:list --> <ul class="wp-block-list"><!-- wp:list-item --> <li><strong>Process scope:</strong> a program inherits a copy of environment variables when it starts. Changing a variable after the program is open does not automatically refresh its environment.</li> <!-- /wp:list-item --> <!-- wp:list-item --> <li><strong>SET is temporary:</strong> <code class="" data-line="">set "MYVAR=Hello"</code> changes the current CMD process and typically its child processes; it does not create a permanent user/system variable.</li> <!-- /wp:list-item --> <!-- wp:list-item --> <li><strong>New windows can inherit a different environment:</strong> restart the application or open a new session from an updated parent process after making a persistent setting change.</li> <!-- /wp:list-item --> <!-- wp:list-item --> <li><strong>Different accounts:</strong> user-level variables can differ between your normal account, an administrator session, and a scheduled task.</li> <!-- /wp:list-item --></ul> <!-- /wp:list -->  <!-- wp:heading --> <h2 class="wp-block-heading">Viewing is safer than changing: SET vs SETX</h2> <!-- /wp:heading -->  <!-- wp:paragraph --> The command <code class="" data-line="">set</code> can list variables, but it also changes the current CMD environment when used as <code class="" data-line="">set "NAME=value"</code>. The separate <code class="" data-line="">setx</code> command writes persistent variables for future sessions; it does not change the environment of the current window. It can also cause problems when used carelessly with <code class="" data-line="">PATH</code> or long values, so do not run <code class="" data-line="">setx PATH ...</code> just to inspect a setting. This guide is about reading values, not modifying them. <!-- /wp:paragraph -->  <!-- wp:paragraph --> For reference, Microsoft documents the behavior of <a href="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/setx">SETX</a> and <a href="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd">CMD environment substitution</a>. <!-- /wp:paragraph -->  <!-- wp:heading --> <h2 class="wp-block-heading">Troubleshooting and frequently asked questions</h2> <!-- /wp:heading -->  <!-- wp:paragraph --> <strong>What does %VARIABLE_NAME% mean?</strong> In CMD, the percent signs tell the command processor to substitute the environment variable's current value. In PowerShell, the equivalent syntax is <code class="" data-line="">env:VARIABLE_NAME.

Why does the value differ from Environment Variables in Settings? CMD reads its process environment, which may include temporary changes and may not reflect a registry change made after that window opened.

Why are my Java or Python commands not recognized? Check both the related installation path and the PATH variable. A correct environment variable alone does not guarantee that every program has restarted or can find the executable.

Can I display variables in a batch file? Yes. A .bat or .cmd script can use echo %PATH% and set. Be aware that percent expansion in loops and parenthesized blocks has additional timing rules; use delayed expansion intentionally if needed.

Summary

Use echo %NAME% to see one value in CMD, set to list the current environment, and $env:NAME in PowerShell. When troubleshooting, open the right shell, verify which user or process you are in, and avoid sharing sensitive environment-variable values.

For more Windows command-line context, read our article on Windows drive letters.

Leave a Reply

Your email address will not be published. Required fields are marked *