Skip to content
IT glossary
DevOps and cloudUpdated December 3, 2026

Environment variables

Переменные окружения

These are named text values available to a running program. They let you set options such as a server’s port or log level without changing the program’s code.

Also known as: env, .env

What they’re for

Suppose a web service uses port 8000 on a developer’s laptop and port 8080 in staging. If the service reads PORT from its environment, you can run the same build in both places and supply a different value at launch. The same approach works for service URLs, log levels, and other settings that vary between deployments.

How a program gets its environment

Each process has its own environment: a set of names and string values. A child process normally starts with a copy of its parent’s environment, although the launcher can supply a different set. Changes in the child don’t flow back to the parent, and changes in the parent don’t update children that are already running. A terminal, a CI runner, and a container runtime can therefore launch the same executable with different settings.

Example: pass a setting from Bash to Python

PORT=8080 python -c 'import os; print(os.environ["PORT"])'

This prints 8080. The assignment applies to that command without changing PORT in your shell afterward. To make a value available to future child processes from the same shell, use export PORT=8080. A plain assignment on its own doesn’t export a variable that wasn’t already marked for export.

Applications see strings, not numbers or booleans. Convert PORT to an integer and check its range before starting the server. Watch for the difference between an unset variable and an empty one: os.getenv('PORT', '8000') returns '8000' when the variable is absent, but returns '' when PORT is set to an empty string. Likewise, a nonempty string such as 'false' is truthy in Python, so a Boolean setting needs explicit parsing.

A .env file is not the environment

A .env file is a text file that typically contains lines such as PORT=8080. Nothing happens just because the file exists. A framework, a loader, or a launch tool must read it, and that tool determines whether a value in the file overrides one already set. Docker Compose, for instance, can read .env to substitute values into its configuration without injecting every entry into the container’s environment.

Deployment and secrets

Set deployment-specific values in the system that actually launches the application. If the application reads its configuration at startup, changing those settings generally means starting a new process with the updated environment. For credentials, use a secret store rather than treating environment variables as secure storage. Even when a secret is injected at launch, it can leak if the application dumps its environment into logs. Check in a .env.example with safe sample values, not a .env file containing real credentials.

What interviewers ask

A common debugging prompt is: “Why does echo "$PORT" show the right value, but the app can’t see it?” The shell can expand a variable that it hasn’t exported. First check whether the app was launched from that shell. If it was started by a service manager or container runtime, inspect that launcher’s configuration instead.