Environment Variables
What are environment variables and how do you use them in Linux? How do you make them persistent?
Environment Variables
What are environment variables and how do you use them in Linux? How do you make them persistent?
Environment variables are dynamic values that affect processes and programs. Set temporarily with export VAR=value, view with echo $VAR or printenv. For persistence: add to ~/.bashrc (user-specific) or /etc/environment (system-wide). Common vars include PATH, HOME, USER, and custom app configs.
Environment variables are crucial for configuring applications without hardcoding values. They're the standard way to pass configuration to containers, manage secrets (though not ideal for sensitive data), and customize behavior across environments like dev, staging, and production.
Setting and viewing variables
Making variables persistent
- Forgetting to export variables (they won't be available to child processes)
- Putting spaces around the = sign (VAR = value won't work)
- Storing secrets in plain text environment variables in production
- What's the difference between setting a variable with and without export?
- How do environment variables work with Docker containers?
- Why shouldn't you store sensitive secrets in environment variables?