To make environment variables permanent in most modern Linux systems, you typically edit the ~/.bashrc or ~/.bash_profile file for user-specific variables. For system-wide environment variables, you can edit the /etc/environment file or create a new file in the /etc/profile.d/ directory.
User-Specific:
-
~/.bashrc: Commonly used for interactive non-login shells. Add your variable like this:export MY_VAR="value" -
~/.bash_profile: Used for login shells. You can also add your variables here.
System-Wide:
/etc/environment: A simple file for setting environment variables globally./etc/profile.d/: You can create a new script file (e.g.,my_vars.sh) in this directory to set environment variables.
After editing these files, remember to run source ~/.bashrc or source ~/.bash_profile to apply the changes immediately, or log out and back in.
