Global environment variables are available to all processes and they are named in uppercase, with words joined by underscore _
, e.g., JAVA_HOME
.
Local variables aka locals are available to the current process only and they are in lowercase.
Command | Description |
---|---|
env | List all environment variables. env is an independent executable; it only sees the variables that the shell passes to it, or environment variables |
set | List all environment varialbes + local viarables (locals). set is a built-in shell command |
a=1 | Set local variable a |
unset a | Unset local variable a |
export a=1 | Set environment variable a |
echo $varname | Print value of varname environment variable |
Environment variables set like this are only stored temporally. When you exit the running instance of bash by exiting the terminal, they get discarded. To save them permanently, open the file:
cd
vim .zprofile
source .zprofile
The source .zprofile
command loads new values immediately without having to reboot system.
cd
sudo vim /etc/environment
Example of environment file:
export ADMIN_USERNAME=admin
export ADMIN_PASSWORD=password123
Load new values without having to reboot:
source /etc/environment
env