Back to list
Lv.2

Environment Variable

Environment Variable

A value made available to a program's execution environment, used to pass configuration settings from outside the code.

In Simple Terms

An environment variable is a piece of configuration information set up in the environment (process) where a program runs. For example, it can specify whether a program runs in "development" or "production" mode, or whether detailed error messages should be shown. Because a program inherits this configuration from the environment it runs in, its behavior can be adjusted for different environments without rewriting the program's code.

Behind the Name

The name combines "environment" — the runtime context (process) a program executes in — with "variable" — a named value that program can read. Put together, it names a variable that lives inside a program's execution environment, ready for the running code to look up.

Take a Closer Look!

An environment variable is a "variable" that the environment (process) starting a program holds, used to store configuration values.
It's a mechanism for passing configuration information that changes depending on the environment a program runs in, from outside the program itself.

Think of it like a handoff note prepared for each "room" (process) a program runs in. When a new program starts inside that room, the contents of the note carry straight over to it.
For example, the location of the folder containing executable files (PATH) or the location of a temporary working folder might be written on this note.
A program can find the information it needs just by checking these environment variables, without having to read a complicated configuration file itself.

Environment variables also serve to separate a program's code from its configuration.
Writing things like connection details directly into a program's source code makes it inconvenient to run in a different environment, and risks leaking that information if the code is ever made public.
That's why environment variables are used as a way to pass configuration in from outside the program.
This is especially true for sensitive information like passwords: instead of writing it into the source code, the common approach is to combine a dedicated secrets management tool with environment variables, so the value is only passed in temporarily at the moment the program runs.