Linux Environment Variables - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux Environment Variables Guide
Complete beginner-friendly guide to environment variables on Linux, covering Arch Linux, CachyOS, and other distributions including setting variables, PATH configuration, and environment management.
Table of Contents
- Understanding Environment Variables
- Setting Variables
- PATH Configuration
- Common Variables
- Troubleshooting
Understanding Environment Variables
What are Environment Variables?
Environment variables store system configuration.
Common variables:
PATH: Command search pathHOME: User home directorySHELL: Default shellLANG: Language settingEDITOR: Default editor
Setting Variables
Temporary Setting
Set for session:
# Set variable
export VARIABLE_NAME=value
# Check
echo $VARIABLE_NAME
Permanent Setting
Set in shell config:
# Bash
vim ~/.bashrc
export VARIABLE_NAME=value
# Zsh
vim ~/.zshrc
export VARIABLE_NAME=value
System-wide
Set for all users:
# Edit profile
sudo vim /etc/profile
# Or environment
sudo vim /etc/environment
PATH Configuration
Add to PATH
Add directory:
# Add to PATH
export PATH=$PATH:/path/to/directory
# Make permanent
echo 'export PATH=$PATH:/path/to/directory' >> ~/.bashrc
Check PATH
View PATH:
# View PATH
echo $PATH
# List directories
echo $PATH | tr ':' '\n'
Common Variables
Editor
Set editor:
# Set editor
export EDITOR=vim
# Or nano
export EDITOR=nano
Language
Set language:
# Set language
export LANG=en_US.UTF-8
# Set locale
export LC_ALL=en_US.UTF-8
Troubleshooting
Variable Not Set
Check variable:
# Check variable
echo $VARIABLE_NAME
# Check all variables
env
# Check in config
cat ~/.bashrc | grep VARIABLE_NAME
Summary
This guide covered environment variables for Arch Linux, CachyOS, and other distributions, including setting, PATH, and common variables.
Next Steps
- Shell Configuration - Shell setup
- Locale and Language - Locale setup
- System Configuration - System setup
- ArchWiki Environment Variables: https://wiki.archlinux.org/title/Environment_variables
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.