How to Set Environment Variables in Linux (export)
export makes a shell variable available to any programs launched from that shell, not just the shell itself.
Published October 1, 2026
export marks a shell variable as an environment variable so child processes inherit it. Variables set without export are local to the shell.
How it works
Set for one command with VAR=value command. Make permanent by adding export lines to ~/.bashrc, ~/.profile or /etc/environment.
env and printenv list the current environment.
Try it
export API_URL=https://api.example.com
printenv API_URL
https://api.example.com
node -e 'console.log(process.env.API_URL)'
Practical examples
Set and export
export NODE_ENV=productionOne-off for a command
PORT=4000 node server.jsPersist
echo 'export EDITOR=vim' >> ~/.bashrcRemove
unset API_URLCommon mistakes
- Forgetting export so child processes do not see the variable.
- Committing .env files with secrets.
- Spaces around = (invalid in shell).
Key takeaways
- export shares variables with child processes.
- Persist in rc files.
- No spaces around =.
FAQ
Where do systemd services get env?
From Environment= or EnvironmentFile= in the unit.
Difference from shell variables?
Shell variables are not inherited unless exported.