Environment & Configuration
The problem
Programs need machine- and user-specific settings (where to find executables, which mode to run in, secret credentials) without hardcoding them into source code — environment variables and configuration files give every process a way to receive that context from outside itself.
Why now
Variables and state already established that a name can be bound to a value that changes; an environment variable is that exact idea, scoped to a whole process (or shell session) instead of a single function, letting configuration flow from the shell into every program it launches.
Mental model
An environment variable is a global variable for a process and everything it spawns — set it in the shell, and every child process inherits a copy. PATH is the clearest example: a list of directories the shell searches, in order, whenever you type a command name instead of a full path.
Requires
- Variables & StateProgramming Fundamentals
An environment variable is a name-to-value binding exactly like a programming variable, just scoped to a process and its children instead of a single function call.
- The Shell & Filesystem NavigationLinux
Environment variables are set and inspected from the shell, and configuration files live on the filesystem tree already covered — both are the concrete substrate this topic operates on.
Unlocks
Used in
- PATH resolving which program runs when you type a bare command name
- Twelve-factor app configuration (storing config in environment variables, not code)
- Secrets management — API keys and credentials passed via environment rather than hardcoded
- Dotfiles (.bashrc, .env) configuring a shell or application's startup behavior
Projects
- Inspect your PATH variable, then deliberately add a directory to it and confirm a script in that directory becomes runnable by name
- Move a hardcoded API key out of a script and into an environment variable, loaded via a .env file
Examples
- Typing node runs whichever node executable is found first by searching each directory in PATH, in order
- A Node.js app reading process.env.DATABASE_URL lets the same code run against different databases in development and production
Resources
Mastery checklist
- I can view, set, and export an environment variable in the shell
- I can explain how PATH determines which executable runs for a given command name
- I can explain why secrets belong in environment variables rather than source code
- I can explain the difference between a shell-session variable and one exported to child processes