Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Environment Variables

Direct answer

Environment variables are name=value pairs a process passes to its children, such as PATH, HOME, LANG and proxy settings. A variable set in a shell is only exported to child processes with export.

When to use this

Use it when a program behaves differently for another user, under sudo, in cron or as a service.

First 30 seconds

1. printenv <NAME> in your shell — set?

2. Set but not seen by the program → not exported (export NAME).

3. Service → systemctl show <svc> -p Environment; add Environment= in a drop-in.

4. sudo → sudo env | grep NAME; use sudo -E or env_keep.

5. Persist in the right file and start a new session.

Operational verification

variable set → exported → inherited by the child process → read by the program

Evidence · next step

For Linux Fundamentals → Environment Variables, continue with the first unproven Topic check: Inspect the effective variable in the exact process/session or service context that exhibits the behavior. If that boundary is healthy, advance to the adjacent check: Determine whether the value came from parent inheritance, shell startup, service manager, container/runtime or application configuration. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when a program behaves differently for another user, under sudo, in cron or as a service.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

authoritative config/launcher → parent process environment → export/injection → child process environment → application parsing/precedence → effective behavior

Healthy evidence: the target process's effective value is known, its provenance/inheritance path is attributable, and a controlled restart/reload demonstrates the intended consumer behavior.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Inspect the effective variable in the exact process/session or service context that exhibits the behavior.

  • Determine whether the value came from parent inheritance, shell startup, service manager, container/runtime or application configuration.
  • Separate shell-local variables from exported environment and current session from persistence mechanisms.
  • After changing the source, start/reload the intended consumer as required and verify its effective environment plus workload behavior.

Verification chain. authoritative config/launcher → parent process environment → export/injection → child process environment → application parsing/precedence → effective behavior

Step 3 Commands Verify boundary
env | sort
printenv PATH
export APP_ENV=prod
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: operators inspect a different shell than the failing service, assume file edits are live, conflate shell-local and exported variables, or expose secrets while collecting environment evidence.

Step 5 Common mistakes Narrow the fault
  • Expecting exported variables to persist after logout.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Each process has its own copy; changing it does not affect running processes. sudo resets most variables (see env_reset). systemd services get only the variables in their unit (Environment=, EnvironmentFile=). Persist user variables in ~/.profile or ~/.bashrc, system-wide in /etc/environment.

Key checks
  • env — current environment
  • printenv <NAME> — one variable
  • cat /proc/<pid>/environ | tr '\0' '\n' — environment of a running process
  • systemctl show <svc> -p Environment — variables set for a service
  • sudo env — environment under sudo
ReferenceWhat it is1 section · depth on demand

Core model

Start from the affected process, capture its effective environment safely, then trace each relevant variable back to its launcher/session/service configuration and inheritance chain. Separate shell variables from exported environment, current-process state from future sessions, and configuration files from values already loaded by long-running services.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

Seeing a variable in a file or shell shows neither inheritance into the target process nor that the application gives it precedence over other configuration.

In depth

Environment variables: how they're passed and where they come from

Every process has an environment: a list of NAME=value strings that it inherits from its parent. The environ(7) manual page describes the mechanism:

  • The environment is passed to a new program when it's executed.
  • A process can change its own environment, but that never changes the parent's. A child only gets a copy.
  • Names are conventionally upper case.

The manual also lists widely used variables:

  • HOME, LOGNAME and USER describe the user.
  • PATH is the command search path, and SHELL is the login shell.
  • TERM is the terminal type, and PWD is the current directory.
  • LANG and the LC_* variables are locale settings.
  • TZ is the time zone, and EDITOR or VISUAL is the preferred editor.

Shell variables versus environment variables

FormExported to children?
NAME=valueNo: a shell variable only
export NAME=valueYes
NAME=value commandOnly for that one command
unset NAMERemoved from the shell and from later children

Where the environment comes from

ContextSource
Login sessionsPAM (/etc/environment, pam_env), then the shell's profile files
systemd servicesOnly what the unit sets: Environment=, EnvironmentFile=, plus a few defaults
User servicessystemctl --user manager environment, ~/.config/environment.d/
cronA minimal environment, plus variables set at the top of the crontab
sudoA cleaned environment by default (env_reset), with an allow-list (env_keep)
ContainersThe image's ENV, plus -e and --env-file at run time

Inspecting environments

TaskCommand
The current shell's environmentenv, printenv NAME
A running process's environmenttr '\0' '\n' < /proc/<pid>/environ
A service's configured environmentsystemctl show <unit> -p Environment
Run with an empty environmentenv -i command
host$ GREETING=hello; bash -c 'echo "child sees: ${GREETING:-nothing}"'
child sees: nothing
host$ export GREETING; bash -c 'echo "child sees: $GREETING"'
child sees: hello
host$ TZ=America/New_York date +%H:%M; date +%H:%M
host$ sudo tr '\0' '\n' < /proc/$(pgrep -o report-api)/environ | grep -E "^(DATABASE_URL|LANG)="
LANG=C.UTF-8
host$ systemctl show report-api -p Environment
Environment=LANG=C.UTF-8
host$ sudo systemctl edit report-api
host$ sudo systemctl restart report-api

Reading the example

The service runs without DATABASE_URL, even though the administrator's shell has it. A service never inherits a login shell's environment. The variable must be set in the unit, for example with EnvironmentFile= pointing at a root-only file. That's better than Environment= for secrets, because the unit itself is world-readable.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Environment Variables is part of Linux Fundamentals → Environment Variables. Environment Variables are per-process key/value strings inherited at process creation and optionally modified by the process or its launcher; persistent shell, user, service or system configuration only matters when it actually feeds the target process environment.

Topic-specific state model. Environment Variables are per-process key/value strings inherited at process creation and optionally modified by the process or its launcher; persistent shell, user, service or system configuration only matters when it actually feeds the target process environment.

Interpretation rule. - Variable set in one shell ≠ exported to child processes.

  • Exported variable in one session ≠ persistent for future sessions or services.
  • Persistent configuration changed ≠ already-running process environment changed.
  • Environment variable exists ≠ its value is trustworthy or safe to log as a secret.

Quick reference

Environment variables are inherited by child processes. Shell variables are not, unless exported.

env | sort | head
echo $HOME $USER $LANG
export APP_ENV=prod
APP_ENV=test ./run.sh            # only for this command
sudo -E cmd                      # preserve environment (subject to sudoers)
cat /proc/<pid>/environ | tr '\0' '\n'

Persistent locations: /etc/environment (system, simple KEY=value), /etc/profile.d/*.sh (login shells), ~/.bashrc/~/.profile, and Environment=/EnvironmentFile= in systemd units (services do not read shell profiles).

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Seeing a variable in a file or shell shows neither inheritance into the target process nor that the application gives it precedence over other configuration.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Environment Variables owns process-environment semantics. Shell startup files, systemd service environment, containers and application-specific precedence are expanded in their respective branches.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Linux Fundamentals → Environment Variables. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.kernel.org/ · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
linux env varsenvironment variables linuxprocess environment linux
Embedded reference data

Quick lookup tables

Environment Variables operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Environment Variables.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateEnvironment Variables are per-process key/value strings inherited at process creation and optionally modified by the process or its launcher; persistent shell, user, service or system configuration only matters when it actually feeds the target process environment.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin distribution/release + CPU architecture + running kernel → identify the exact process/session and kernel-versus-user-space boundary → capture shell/TTY mode and effective environment where relevant → resolve the real executable/consumer → correlate requested action with observed runtime state → verify the original workload result before changing persistent configuration.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainauthoritative config/launcher → parent process environment → export/injection → child process environment → application parsing/precedence → effective behaviorTrace requested/configured state through effective state to the observed workload result.
Failure boundarySeeing a variable in a file or shell proves neither inheritance into the target process nor that the application gives it precedence over other configuration.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated host, process/session and runtime evidence can establish this Linux Fundamentals proof path: authoritative config/launcher → parent process environment → export/injection → child process environment → application parsing/precedence → effective behaviorUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured host, kernel, process/session, environment or workload scope. Seeing a variable in a file or shell proves neither inheritance into the target process nor that the application gives it precedence over other configuration.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven Linux layer: preserve platform identity and the running kernel, inspect the exact process/session and effective configuration/environment, resolve the actual consumer/executable, then verify the original workload before moving into the owning Linux subsystem branch.Continue to the next unresolved boundary while preserving the original test condition.

Environment Variables · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryEnvironment Variables
Topic pathLinux Fundamentals → Environment Variables
Runtime stateEnvironment Variables are per-process key/value strings inherited at process creation and optionally modified by the process or its launcher; persistent shell, user, service or system configuration only matters when it actually feeds the target process environment.
Fast checks- Inspect the effective variable in the exact process/session or service context that exhibits the behavior. - Determine whether the value came from parent inheritance, shell startup, service manager, container/runtime or application configuration. - Separate shell-local variables from exported environment and current session from persistence mechanisms. - After changing the source, start/reload the intended consumer as required and verify its effective environment plus workload behavior.
Verification chainauthoritative config/launcher → parent process environment → export/injection → child process environment → application parsing/precedence → effective behavior Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundarySeeing a variable in a file or shell proves neither inheritance into the target process nor that the application gives it precedence over other configuration. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?