Environment variables
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.
X Window¶
- ~/.xinitrcis sourced by- startx.
- ~/.xprofileis sourced by display managers (e.g., GDM, SDDM)
Systemd and Wayland¶
- ~/.config/environment.d/*.conf: sourced by- systemd. Also, they are used in Wayland sessions where- xinitrcand- xprofilefiles 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.
Persistent variables¶
- GUI: Windows Settings -> Advanced system settings -> Set Environment Variables.
- Powershell: [Environment]::SetEnvironmentVariable('KEY', 'VAL', 'Machine')
- Cmd: SETX KEY VAL