How to Set Environment Variables in Bash on Linux

Setting environment variables in Bash is essential when working with scripts, development tools, or system settings. These variables help define behavior for applications and shell sessions.


To create a temporary environment variable, you can define it directly in the terminal using export. For a permanent setup, you’ll need to add it to configuration files like .bashrc or .bash_profile. After updating the file, run source ~/.bashrc to apply the changes without restarting the terminal.


Be cautious when modifying system files, and use clear, descriptive variable names to avoid future confusion or conflicts.


For a complete walkthrough with examples, check the Vultr documentation:

https://docs.vultr.com/how-to-set-environment-variables-in-bash-on-linux