Developer Tools

What is an environment variable?

Updated 2026-08-14

✓

Quick answer

An environment variable is a dynamic value that can affect the way running processes will behave on a computer. They are often used to store configuration settings and system paths.

Environment variables are key-value pairs that provide information about the environment in which a process runs, allowing for flexible configuration of applications.

Steps

  1. 1

    Viewing Environment Variables on Windows

    Open Command Prompt and type 'set' to display all environment variables.

  2. 2

    Viewing Environment Variables on macOS/Linux

    Open Terminal and type 'printenv' to list all environment variables.

  3. 3

    Setting an Environment Variable on Windows

    Use the command 'set VAR_NAME=value' in Command Prompt to create or modify an environment variable for the session.

  4. 4

    Setting an Environment Variable on macOS/Linux

    Use the command 'export VAR_NAME=value' in Terminal to create or modify an environment variable for the session.

Definition

Environment variables are part of the environment in which a process runs. They can include system paths, user preferences, and other configuration settings that can be accessed by applications.

Usage

Developers use environment variables to manage application settings without hardcoding values. This practice enhances security and flexibility, especially in different environments like development, testing, and production.

Platform-Specific Variables

Different operating systems have their own sets of environment variables. For example, on Windows, variables like %PATH% are commonly used, while on Unix-based systems, variables such as $HOME are prevalent.

Watch out for

  • Environment variables can be overwritten by other processes or scripts, which may lead to unexpected behavior.

FAQ

How do I make an environment variable permanent?

On Windows, you can set environment variables permanently through System Properties > Environment Variables. On macOS/Linux, add the export command to your shell's configuration file (e.g., .bashrc or .zshrc).

Can environment variables be accessed by all applications?

Environment variables set in a terminal session are only accessible to processes spawned from that session. To make them globally accessible, set them in the system settings.

What is the difference between user and system environment variables?

User environment variables are specific to a user account, while system environment variables apply to all users on the system.