Environment variables are dynamic values that affect the behavior of running processes on a computer. They are part of the environment in which a process runs, and they are used by the operating system to configure software, control the behavior of applications, and set up the environment for user sessions.
The concept of environment variables dates back to the early days of computing. They were introduced as a way to manage configurations in Unix-like operating systems. The earliest Unix systems from the 1970s used them to pass settings to programs, allowing for more flexible and dynamic system behavior without hardcoding settings into the applications themselves. Over time:
Environment variables serve several key functions:
HOME
or USER
help tailor the user experience and system behavior.Some commonly used environment variables include:
PATH
- Directories to search for executable files.HOME
- The home directory for the user.USER
- The current logged-in user's username.LD_LIBRARY_PATH
(on Unix-like systems) - Specifies directories to search for shared libraries.Environment variables can be set and accessed differently depending on the operating system:
export
command or set
in some shells to set variables, and echo $VARIABLE_NAME
to access them.set
or setx
for temporary or permanent settings, respectively. Accessing is done with %VARIABLE_NAME%
.os.environ
in Python.Sources: