what is enviroment variable?
- User
what is enviroment variable?
Assistant
what is enviroment variable?
An environment variable is a dynamic, named value stored in the operating system that affects how processes and programs behave. These variables provide information about the system environment, such as paths to executables, user preferences, and system configurations.
PATH, HOME).| Variable | Purpose | Example |
|---|---|---|
PATH | Lists directories where executable programs are located. | /usr/bin:/bin:/usr/local/bin |
HOME | Specifies the current user’s home directory. | /home/username |
USER | Stores the current username. | john |
PWD | Shows the current working directory. | /home/username/projects |
LANG | Defines the system language and locale. | en_US.UTF-8 |
SHELL | Indicates the default shell. | /bin/bash |
printenv
or
env
echo $PATH
set
echo %PATH%
export VAR_NAME="value"
set VAR_NAME=value
~/.bashrc, ~/.bash_profile, or /etc/environment:
export VAR_NAME="value"
source ~/.bashrc
[System.Environment]::SetEnvironmentVariable("VAR_NAME", "value", "User")
PATH allows running executables from anywhere..env files are often better for this).JAVA_HOMEexport JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
export PATH="$JAVA_HOME/bin:$PATH"
This allows Java-based programs to find the correct Java installation.
.env files for project-specific variables (common in Node.js, Python, etc.).Environment variables are essential for system administration, software development, and automation. 🚀