Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Manage Linux Environment Variables: Set, Persist, and Troubleshoot Them

Set Linux environment variables for one command, a shell, a login session, or systemd service. Learn which processes inherit each setting and how to troubleshoot missing values.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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

  1. 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.
  2. Inspect the value in the matching context. Checking a terminal does not prove that a service or graphical application received the same environment.
  3. Confirm the variable is exported when using a shell. A shell variable that was assigned without export may not reach a child command.
  4. 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.
  5. 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.