Environment Variables
What are environment variables and how do you use them in Linux? How do you make them persistent?
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?
More Linux interview questions
Also worth your time on this topic
Shell Scripting Fundamentals
What are the essential components of a shell script? Explain variables, conditionals, and loops.
junior
How to Permanently Set $PATH on Linux and Unix
Learn how to permanently modify your PATH environment variable on Linux and Unix systems so your custom directories persist across shell sessions and reboots.
Creating and Connecting to Your First Linux Server
Spin up an Ubuntu 24.04 Linux server in the cloud, configure SSH key authentication, and learn to navigate your new server. This exercise uses DigitalOcean but the steps work with any cloud provider.
30 minutes