Environment variables
Environment variables
March 21, 2024
Linux environment variables
Arch Wiki: environment variables
System-wide
/etc/profileis sourced by all POSIX-compatible shells upon login.- Files inside the
/etc/profile.d/directory will also be read.
Bash
~/.profileor~/.bash_profilefor login bash instances.~/.bashrcfor every interactive bash instance.
Zsh
~/.zshenvfor environment variables in all zsh instances.~/.zprofilefor every login zsh instance.~/.zshrcfor every interactive zsh instance.
Note
zsh does not source ~/.profile by default because of the difference between bash and zsh syntaxes. You can add this line to ~/.zprofile or ~/.zshenv to make zsh shells read `~/.profile correctly.
~/.zshenv
skip_global_compinit=1
test -r ${HOME}/.profile && emulate sh -c 'source ${HOME}/.profile'X Window
~/.xinitrcis sourced bystartx.~/.xprofileis sourced by display managers (e.g., GDM, SDDM)
Systemd and Wayland
~/.config/environment.d/*.conf: sourced bysystemd. Also, they are used in Wayland sessions wherexinitrcandxprofilefiles are not available.
Windows environment variables
Environment variables in Powershell
Session variables
Variables created by set are bound to the current session and not persistent.
$Env:FOO = "example"
$Env:FOOPersistent variables
- GUI: Windows Settings -> Advanced system settings -> Set Environment Variables.
- Powershell:
[Environment]::SetEnvironmentVariable('KEY', 'VAL', 'Machine') - Cmd:
SETX KEY VAL
Last updated on