Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

Why does an environment-variable change in one terminal not appear in another?

Quick answer

A terminal session has its own process environment. In PowerShell, a process inherits environment variables from its parent, and a change in one PowerShell session affects that session; another terminal session can therefore have a different value. [S1] Think of a session’s environment as something passed to child processes, not as a live shared setting. Details can differ among shells and operating systems.

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I changed an environment variable in one terminal, but another terminal still shows the old value. Did the change fail?

Geez

Not necessarily. In PowerShell, the environment available to a session belongs to its process. A change made in that session affects that session, while another terminal session can have a different environment. [S1] The change is not automatically a live update to every terminal that is already open.

A useful picture is:

Parent process
├── PowerShell session A — its environment
│   └── Child process — inherits A's environment when started
└── PowerShell session B — its own environment

This is a simplified model: a child process inherits from its parent, but two separate terminal sessions do not thereby become one shared session. If terminals were started from different parents, their starting environments may differ too. This source describes PowerShell and Windows behavior; other shells and operating systems can have additional details. [S1]

Follow-up question

Can I compare the sessions without changing anything important?

Geez

Yes. In each of two PowerShell terminals, inspect the same variable name before making changes. Then set a clearly disposable name in the first terminal, inspect it there, and check that name in the second. For example, use GEEZ_SCOPE_TEST rather than the name of a setting your work depends on.

In PowerShell, these commands set, display, and remove that process environment variable:

$env:GEEZ_SCOPE_TEST = "session-A"
$env:GEEZ_SCOPE_TEST
Remove-Item Env:GEEZ_SCOPE_TEST

Run the set and display lines in the first terminal, then display the variable in the second. If it is absent there, that demonstrates the sessions have separate process environments for this variable. Clean up in the session where you set it. This test does not change a user-wide or machine-wide setting; it is a temporary example for the current PowerShell process. [S1]

Follow-up question

What should I expect if I start a child process from the terminal where I changed it?

Geez

A child process inherits environment variables from its parent. So, if PowerShell session A has the disposable variable set and starts a child process, that child receives the environment passed from A. [S1] That is different from a separate terminal session: the separate session does not become a child of A just because both are open on your screen.

The inheritance described here is from parent to child. The source does not specify how every application or shell displays variables, nor does it establish behavior for shells or operating systems beyond the stated PowerShell and Windows scope. [S1]

Follow-up question

If the second terminal needs the new value, what should I do?

Geez

For a session-only change, set the value in the second terminal too, or start the program that needs it from the session where you set it. If you intend a broader Windows setting rather than a temporary process value, distinguish process scope from user and machine scopes: Windows treats those scopes separately. [S1] This guide does not establish the exact steps for changing persistent settings, so check the documentation for your PowerShell and Windows version before doing that.

For the disposable comparison, the expected pattern is: set in A, see it in A, check B, then remove it from A. A difference is evidence that you were comparing distinct session environments—not, by itself, proof of a problem with the application or terminal.

A practical checklist

  • Confirm which shell and operating system each terminal is using.

  • Compare the same variable name in both sessions before changing anything.

  • Use a clearly disposable name such as GEEZ_SCOPE_TEST for the comparison.

  • Set and inspect the test value in one PowerShell session, then inspect it in the other.

  • Remove the test variable from the session where you set it.

  • For a lasting Windows setting, verify the relevant scope and version-specific instructions first.

A few more useful answers

Does opening another terminal copy changes from my current terminal?

Not as a live shared update. A new process inherits environment from its parent, while a separate terminal session can have a different environment. [S1]

Does a child process inherit its parent’s environment?

In the PowerShell behavior described here, environment variables are inherited by child processes. [S1] The source does not establish every shell’s or operating system’s details.

Is a PowerShell process variable the same as a Windows user or machine setting?

No. Windows distinguishes user and machine scopes from process scope. [S1] The comparison exercise uses a temporary process variable, not a persistent user or machine setting.

Sources

References used for this guide.

  1. [S1] PowerShell environment-variable scopes and child-process inheritance
    learn.microsoft.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work