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-alpineprocess.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.1PORT: 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.pySERVICE_NAME sets the service field on every log record.import os
os.environ.get("HOME")API_TOKEN=sk-live-4d1f-demo python3 app.pyIn 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
- PYTHONHASHSEED — The environment variable that controls the seed Python uses to randomise str, bytes and datetime hashes.
- ansible.cfg — Ansible's INI-format settings file; a copy in the project directory sets options such as the inventory location and forks for everyone who runs there.
- URL — A web address, such as https://example.com/docs, made of a scheme, a host, an optional port and a path.
- access key — A long-lived cloud credential made of a key ID and a secret key that works until someone deletes it.
- region — A separate geographic area where a cloud provider runs data centres, such as eu-west-2 for London in AWS.
- shell — The program that reads the commands you type, runs them and shows the results; sh and bash are common ones.
- export builtin — The builtin that marks a shell variable so child processes receive a copy of it in their environment.
- env — A command that prints the environment, or runs another program with a changed environment or found through PATH.
- PATH — An environment variable holding a list of folders the shell searches, in order, to find the program for a command you type.
- shell variable — A named value stored in the current shell, set with name=value and read back with $name.
- env key — The workflow key that sets environment variables for every step of a workflow, a job, or a single step.
- default environment variables — Variables such as GITHUB_SHA, GITHUB_REF and RUNNER_OS that the runner sets for every step before your commands run.
- command-line argument — A word given to a command after its name, such as the file names in cp a.txt b.txt.
- PostgreSQL — A widely used open source relational database server with strict typing, rich data types and extensions.
- NODE_ENV — An environment variable, usually set to production or development, that libraries, frameworks and build tools read to switch behaviour.
- production — The live environment where real users use the service, as opposed to development or testing.
- config — Everything about an application that varies between deploys, such as database addresses, credentials and hostnames.
- environment — One place where a copy of the application runs with its own config, such as development, staging or production.
- ENV — The Dockerfile instruction that sets an environment variable in the image, visible during the build and in every container.
- secret — Any value that grants access, such as a password, access token or private key, and must be kept out of code and version control.
- Compose file — The YAML file, usually compose.yaml, that lists the services, networks and volumes of an application.
- NEXT_PUBLIC_ prefix — The naming rule in Next.js where only environment variables starting with NEXT_PUBLIC_ are copied into browser code.
- type coercion — Converting a value from one type to another, such as the text "8080" into the number 8080.
- fail-fast — Stopping immediately with a clear error as soon as something is wrong, rather than limping on and failing later in a confusing way.
- application properties — Settings a Spring Boot application reads at startup from files such as application.properties, environment variables and command-line arguments.
- environment file — A file of name=value lines that a systemd service loads into its process environment with EnvironmentFile=.
- process — A program that is currently running, with its own memory and a numeric identifier.
- bin directory — A directory that holds executable programs, such as /usr/bin for everyday commands and /usr/sbin for administration tools.
- NEXT_RUNTIME — An environment variable Next.js sets to nodejs or edge so code can tell which runtime it is running in.
- log level — A label on each log message saying how serious it is, from debug and info up to error, critical and emergency.
- os module — The standard library module for talking to the operating system: environment variables, the current directory, files and processes.
- VIRTUAL_ENV — An environment variable set by the activate script to the folder of the active virtual environment.
- child process — A process started by another process, its parent, from which it inherits a copy of the environment and current directory.
- AWS Secrets Manager — An AWS service that stores passwords, keys and other secrets encrypted and hands them to programs that are allowed to read them.
- TF_VAR_ environment variable — An environment variable named TF_VAR_ followed by a variable name, which Terraform reads as that variable's value.
- process.env — The object in Node.js that holds the process's environment variables, with every value stored as a string.
Taught in
- What A Hash Function Promises — Algorithms & Data Structures for Working Engineers
- Performance, Forks And Best Practices — Ansible Configuration Management at Scale
- Cookies And CORS — Modern API Architecture: REST, GraphQL & gRPC
- CodeBuild: The Build That Passed With Failing Tests — AWS Certified DevOps Engineer – Professional (DOP-C02) Exam Prep
- Shell Variables, The Environment And export — Bash Scripting & Command Line Automation
- Shebangs, Permissions And Three Ways To Run — Bash Scripting & Command Line Automation
- Script Input And Output: read, Heredocs, printf — Bash Scripting & Command Line Automation
- eval, And What To Use Instead — Bash Scripting & Command Line Automation
- Scheduling, Monitoring And A Script That Reports — Bash Scripting & Command Line Automation
- Runners: Where Code Executes — Continuous Integration & Continuous Delivery Pipelines
- Triggers and the Event Model — Continuous Integration & Continuous Delivery Pipelines
- Securing Pipelines: Secrets Management — Continuous Integration & Continuous Delivery Pipelines
- Generators Write The YAML, You Decide — Certified Kubernetes Administrator (CKA) Exam Prep
- The Name That Will Not Resolve — Certified Kubernetes Administrator (CKA) Exam Prep
- Rolling Updates And Rollbacks — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Deployment: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Debugging Applications In Kubernetes — Certified Kubernetes Application Developer (CKAD) Exam Prep
- ConfigMaps And Secrets — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Configuration And Security: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Encryption At Rest: What etcd Really Holds — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Secrets In Use: Leaks Through Env, Specs And Images — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Allowed Registries: Admission That Refuses Images — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Mock Exam: Seventeen Security Tasks Against The Clock — Certified Kubernetes Security Specialist (CKS) Exam Prep
- The Danger of Long-Lived Keys — Cloud Infrastructure & Hyperscaler Architecture
- Works On A Laptop, Fails In Production — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- The Certificate That Expired On A Sunday — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Forty Minutes To Start — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- System Governance: Changesets, Semantic Versioning & Deprecation — Design Systems & Component Engineering
- Config And Backing Services — DevOps & Site Reliability Engineering
- Build, Release, Run And Processes — DevOps & Site Reliability Engineering
- Build Context, Dockerignore And Your First Dockerfile — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- ARG, ENV, LABEL, EXPOSE And VOLUME — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers
- Minimal Bases, Non Root Users And Smaller Images — Docker Architecture & Production Containers
- Environment, Secret Files And Runtime Restrictions — Docker Architecture & Production Containers
- Define The Service And Database With Compose — Docker Architecture & Production Containers
- Development Overrides, Hot Reloading And Debuggers — Docker Architecture & Production Containers
- Diagnose Crashes, Resource Limits And Unhealthy Containers — Docker Architecture & Production Containers
- Build, Test And Promote The Same Image In CI — Docker Architecture & Production Containers
- Harden And Deliver The Complete Service Stack — Docker Architecture & Production Containers
- From Local Containers To Kubernetes — Docker Architecture & Production Containers
- Environment Layering and User Secrets — Modern .NET Core, C# & Enterprise Microservices
- Unified Build Pipelines: Caching & Dependency Graphs — Production Full-Stack Engineering
- Environment Configuration: Secrets & Multi-Stage — Production Full-Stack Engineering
- What Go Is and Why It Matters — Concurrent Systems Programming with Go
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go
- Configuration And Profiles — Modern Java: Virtual Threads & High-Throughput Services
- Packaging Into A Container — Modern Java: Virtual Threads & High-Throughput Services
- Dual Writes And Why They Lose Data — Apache Kafka & Event Streaming
- Same Name, Wrong Namespace: Objects, Namespaces And Labels — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Not As Root, Not In Plain Sight: Pod Security And Secrets — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Two Versions Of The Truth: GitOps, Helm And Kustomize — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Running, Green And Still Broken: Debugging Applications — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- The Image Nobody Tested: Cloud Native Principles — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Architecture Sprint: The Refunds Review — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Control Plane: etcd, API Server, Scheduler, Controllers — Kubernetes: Production-Grade Container Orchestration
- Bootstrap A Local Cluster And Check Your Context — Kubernetes: Production-Grade Container Orchestration
- ConfigMaps, Secrets And Configuration Updates — Kubernetes: Production-Grade Container Orchestration
- What A Process Is — Linux Fundamentals & Systems Administration
- Your Own Unit, And Reading journald — Linux Fundamentals & Systems Administration
- Script Optimization: next/script & Lazy Third Parties — Next.js 15 & Modern App Router Architecture
- libuv Architecture: Event Demultiplexer & Thread Pool — Node.js Internals & Backend Services
- Runtime Configuration: CLI Flags & Native --env-file — Node.js Internals & Backend Services
- Production Hardening: Graceful Shutdown & Docker — Node.js Internals & Backend Services
- Log Levels Done Properly — Full-Stack Observability: Metrics, Tracing & Logging
- Six Minutes Nobody Saw: Prometheus In One Outage — Prometheus Certified Associate (PCA) Exam Prep
- A Week Without A Scrape: Configuration And Relabelling — Prometheus Certified Associate (PCA) Exam Prep
- Cart Versus cart: The Data Model And What A Scrape Returns — Prometheus Certified Associate (PCA) Exam Prep
- Off By Five: What Prometheus Is Not For — Prometheus Certified Associate (PCA) Exam Prep
- Fundamentals Sprint: Nine Calls On The Server — Prometheus Certified Associate (PCA) Exam Prep
- The Server That Would Not Die: Selecting Data — Prometheus Certified Associate (PCA) Exam Prep
- Four Thousand Requests Vanished: Rates And Derivatives — Prometheus Certified Associate (PCA) Exam Prep
- Fifteen Requests Nobody Saw: Aggregating Over Time — Prometheus Certified Associate (PCA) Exam Prep
- Fifteen Lines And No Answer: Aggregating Over Labels — Prometheus Certified Associate (PCA) Exam Prep
- Is The New Version Worse? Binary Operators And Matching — Prometheus Certified Associate (PCA) Exam Prep
- Under A Second, On Average: Histograms — Prometheus Certified Associate (PCA) Exam Prep
- The Export That Failed Quietly: Timestamp Metrics — Prometheus Certified Associate (PCA) Exam Prep
- PromQL Sprint: Ten Queries At Minute Twenty Two — Prometheus Certified Associate (PCA) Exam Prep
- Paged Three Minutes Late: Alerting Rules — Prometheus Certified Associate (PCA) Exam Prep
- Alerting Sprint: Eleven Calls In Three Rounds — Prometheus Certified Associate (PCA) Exam Prep
- Seventy Seven Percent, Book Now? The Full Mock — Prometheus Certified Associate (PCA) Exam Prep
- One Week, Three Objectives: Final Review — Prometheus Certified Associate (PCA) Exam Prep
- Installing Python On Windows — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- First Run, And Fixing A Broken Install — Hands-on Python: Complete Video Course & Book
- Windows And Mac Specifics — Hands-on Python: Complete Video Course & Book
- The Environment Variable Trap — Application Security & Threat Modeling for Engineers
- Secret Scanning — Application Security & Threat Modeling for Engineers
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Installing Terraform And Meeting The CLI — Infrastructure as Code with Terraform
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript
- The Plan That Wanted To Destroy Production — HashiCorp Terraform Associate (004) Exam Prep
- Infrastructure As Code, And One Workflow For Every Platform — HashiCorp Terraform Associate (004) Exam Prep
- Providers: How Terraform Reaches Every API — HashiCorp Terraform Associate (004) Exam Prep
- Versions, The Lock File And Provider Aliases — HashiCorp Terraform Associate (004) Exam Prep
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Write, Plan, Apply, And What Init Prepares — HashiCorp Terraform Associate (004) Exam Prep
- Reading A Plan, Saving It, Applying It — HashiCorp Terraform Associate (004) Exam Prep
- Validate, Format, Destroy, And The Flags That Bend A Plan — HashiCorp Terraform Associate (004) Exam Prep
- Down Until Morning: Unit Files, Drop-ins, Masks And systemd's Helpers — CompTIA Linux+ (XK0-006) Exam Prep
- Works On My Laptop: Images, Containers, Volumes And Networks — CompTIA Linux+ (XK0-006) Exam Prep
- When awk Runs Out: Python Data Types, Modules And Virtual Environments For Admins — CompTIA Linux+ (XK0-006) Exam Prep
- The Release Tag That Never Left The Laptop: Git Branches, Remotes, Tags And History — CompTIA Linux+ (XK0-006) Exam Prep
- A New Depot By Friday: OpenTofu, Cloud-init, Pipelines And Kubernetes — CompTIA Linux+ (XK0-006) Exam Prep
- ansible.cfg: Which File Wins, And The Settings That Matter — RHCE in Ansible (EX294): Automate Red Hat Systems
- ansible-navigator: The Settings File The Exam Reads — RHCE in Ansible (EX294): Automate Red Hat Systems
References
- man7: environ(7)
- Python command line: environment variables
- Ansible configuration settings
- Python docs: os.environ
- AWS CLI: environment variables
- Bash Reference Manual: Environment
- GitHub Docs: Variables reference
- Node.js: process.env
- Set environment variables in Compose
- The Twelve-Factor App: Config
- Next.js: Environment variables
- Spring Boot: Externalized Configuration
- POSIX: environment variables
- Next.js 15 docs: Environment Variables
- Python logging module
- CWE-526: Cleartext Storage of Sensitive Information in an Environment Variable
- Terraform environment variables
- Node.js: process
Certification courses
- AWS DevOps Engineer Professional course and practice exam: DOP-C02
- CKA course and practice exam: Certified Kubernetes Administrator
- CKAD course and practice exam: Certified Kubernetes Application Developer
- CKS course and practice exam: Certified Kubernetes Security Specialist
- CCDAK and CCAAK course and practice exams: Confluent Apache Kafka certifications
- KCNA course and practice exam: Kubernetes and Cloud Native Associate
- PCA course and practice exam: Prometheus Certified Associate
- Terraform Associate course and practice exam: HashiCorp Terraform Associate (004)
- CompTIA Linux+ course and practice exam: XK0-006
- RHCE course and practice exam: Red Hat Certified Engineer in Ansible (EX294)