Use it when a program behaves differently for another user, under sudo, in cron or as a service.
Environment Variables
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.
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.
variable set → exported → inherited by the child process → read by the program
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
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
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.
env— current environmentprintenv <NAME>— one variablecat /proc/<pid>/environ | tr '\0' '\n'— environment of a running processsystemctl show <svc> -p Environment— variables set for a servicesudo 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,LOGNAMEandUSERdescribe the user.PATHis the command search path, andSHELLis the login shell.TERMis the terminal type, andPWDis the current directory.LANGand theLC_*variables are locale settings.TZis the time zone, andEDITORorVISUALis the preferred editor.
Shell variables versus environment variables
| Form | Exported to children? |
|---|---|
NAME=value | No: a shell variable only |
export NAME=value | Yes |
NAME=value command | Only for that one command |
unset NAME | Removed from the shell and from later children |
Where the environment comes from
| Context | Source |
|---|---|
| Login sessions | PAM (/etc/environment, pam_env), then the shell's profile files |
| systemd services | Only what the unit sets: Environment=, EnvironmentFile=, plus a few defaults |
| User services | systemctl --user manager environment, ~/.config/environment.d/ |
| cron | A minimal environment, plus variables set at the top of the crontab |
| sudo | A cleaned environment by default (env_reset), with an allow-list (env_keep) |
| Containers | The image's ENV, plus -e and --env-file at run time |
Inspecting environments
| Task | Command |
|---|---|
| The current shell's environment | env, printenv NAME |
| A running process's environment | tr '\0' '\n' < /proc/<pid>/environ |
| A service's configured environment | systemctl show <unit> -p Environment |
| Run with an empty environment | env -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.
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).
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%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.
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.
Quick lookup tables
Environment Variables operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Environment Variables.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | 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. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin 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 chain | authoritative config/launcher → parent process environment → export/injection → child process environment → application parsing/precedence → effective behavior | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | 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. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated 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 behavior | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It 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 check | Continue 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 boundary | Environment Variables |
|---|---|
| Topic path | Linux Fundamentals → Environment Variables |
| Runtime state | 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. |
| 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 chain | authoritative 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 boundary | 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. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |