environment variable

A named setting such as PORT=8000 that a program reads from its surroundings when it starts.

In more detail

Environment variables let you change a program's behaviour without editing its code. Each process passes a copy of its environment to the programs it starts.

Examples

PYTHONHASHSEED is read by Python at startup to seed string hashing.
ANSIBLE_CONFIG=./ansible.cfg ansible-playbook site.yml chooses which Ansible configuration file is used.
docker run -e POSTGRES_PASSWORD=secret postgres:16-alpine
process.env.NODE_ENV is the environment variable JavaScript build tools use to strip development-only code.
Factor III of the twelve-factor app stores config in environment variables because every language and operating system supports them and they can be set independently per deploy. Grouping them into named environments does not scale.
docker run -e PORT=9000 taskapi:0.1
PORT: z.coerce.number().default(3000), DB_URL: z.string().url()
os.Getenv("PROBE_TIMEOUT")
Spring Boot maps SERVICE_NAME to the property service.name.
Each process inherits a copy of its parent's environment, so a variable set in your shell reaches the programs it starts. Systemd units can load variables from a separate environment file, which keeps application settings out of the unit itself. The PATH variable tells the shell where to look for commands.
Next.js loads .env files and inlines NEXT_PUBLIC_ variables into client bundles at build time.
LOG_LEVEL=ERROR python3 levels.py
SERVICE_NAME sets the service field on every log record.
import os
os.environ.get("HOME")
API_TOKEN=sk-live-4d1f-demo python3 app.py
In Terraform: Terraform reads several: TF_VAR_ variables supply input values, TF_INPUT turns off prompts, and providers read credentials from their own variables. Keeping credentials in the environment keeps them out of committed files.

Related terms

Taught in

References

Certification courses