To manage a Linux environment variable, first decide which process needs it. Use export NAME=value for the current shell and its future child processes, NAME=value command for a single command, login or shell startup configuration for a login environment, and systemd configuration for services. These scopes are separate: there is no single startup file that reliably reaches every shell, graphical application, and service.
What an environment variable does
An environment is a set of name-value pairs supplied to a process. A process can pass its environment to child processes when it launches them. Bash can hold shell variables that are not exported; those remain shell parameters and are not automatically included in child processes’ environments. In Bash, assignments before a simple command can instead become part of that command’s environment for the duration of its execution.
As an Amazon Associate I earn from qualifying purchases.
That inheritance explains a common surprise: changing a variable in one terminal does not alter the environment of its parent process or of unrelated applications that are already running. A newly launched program receives the environment supplied along its own launch path.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Choose the right scope
| Where the value is needed | Configuration | Who receives it | When it takes effect |
|---|---|---|---|
| One command | NAME=value command |
That command and processes it launches | For that invocation |
| Current shell and later commands | export NAME=value |
The shell and its subsequently launched child processes | Immediately for future launches from that shell |
| Login environment | System login configuration, such as PAM’s /etc/environment where applicable, or shell startup files |
Processes launched through the relevant login or shell path | Usually at the next applicable login or shell startup |
| systemd user services | Files in ~/.config/environment.d/ |
Services started by the systemd user instance | After the relevant manager or service launch picks up the configuration |
| One systemd service | That unit’s Environment= or EnvironmentFile= |
Processes launched by that unit | When the unit starts with the configuration |
These mechanisms do not automatically overlap. In particular, a shell startup file is not a universal setting for graphical applications and systemd services. Identify the program’s launcher first, then choose a configuration location for that path.
#1 Best Overall
Set a variable temporarily in Bash
For the current shell and its child processes
Use export to make a shell variable part of the environment supplied to subsequently executed commands:
export APP_MODE='development'
The value remains in that shell until it is changed, unset, or the shell exits. Bash’s environment documentation describes how exported values are passed to commands.
For one command only
Place the assignment immediately before the command when the setting should apply only to that invocation:
Recommended Free Tools
APP_MODE='test' ./run-tests
The assignment is in the environment of ./run-tests while it runs. It does not permanently set APP_MODE in the calling shell.
Remove a shell variable or inspect exports
Remove a value from the current shell with unset. To display exported names and values in Bash, run export -p:
unset APP_MODE
export -p
The POSIX export utility specification explains that exporting gives variables the export attribute so they are included in the environment of subsequently executed commands.
Rank #4
Make a value available at login
Linux systems can establish login environments through different mechanisms. On systems using PAM, /etc/environment may be processed at login. System-wide or per-user shell startup files may also set variables. Which file is read depends on the shell, distribution, and how the session starts; do not assume that a file used by an interactive terminal also affects a graphical login or non-interactive shell.
Before editing a startup file, check the documentation for the active shell and the login path you use. Then start a new applicable login or shell and verify the value there. A process already running does not acquire a later change to its launch environment.
Best Value
Set variables for systemd services
Services started by your systemd user instance
For services started by the systemd user instance, environment.d configuration files provide assignments. The default per-user directory is ~/.config/environment.d/. This configuration applies to services launched by that user manager; it does not rewrite the manager’s own environment or guarantee the value reaches processes launched by another route.
One specific systemd unit
When only one service needs a value, configure that unit with Environment= or EnvironmentFile=, as appropriate. Those settings apply to processes launched by the unit, not to the entire desktop session. After changing the unit configuration, have the relevant manager reload configuration as required and start or restart the unit so a new process is launched with the updated environment.
Troubleshoot a variable that is missing
- Check the target process’s launch path. Determine whether it starts from your terminal shell, a login session, a graphical application launcher, the systemd user instance, or a specific systemd unit.
- Inspect the value in the matching context. Checking a terminal does not prove that a service or graphical application received the same environment.
- Confirm the variable is exported when using a shell. A shell variable that was assigned without
exportmay not reach a child command. - Launch a new process through the configured mechanism. Existing applications keep the environment they received when they started; changing a shell or configuration file does not modify them retroactively.
- Check syntax and quoting. Quote values containing spaces or shell metacharacters, for example
export APP_LABEL='test environment'.
Handle sensitive values carefully
Environment variables are inherited by child processes, and systemd unit configuration can be part of the service’s configuration. Do not treat a broadly inherited environment as a secret store: consider who can inspect the relevant processes and configuration, and use a separate secret-handling policy for sensitive credentials.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




