To make shell variables persistent across terminal sessions, you can define them in your shell's configuration file. Here’s how to do it for different shells:
For Bash:
- Open the
.bashrcfile in your home directory:nano ~/.bashrc - Add your variable at the end of the file:
export MY_VARIABLE="my_value" - Save the file and exit the editor.
- To apply the changes, run:
source ~/.bashrc
For Zsh:
- Open the
.zshrcfile in your home directory:nano ~/.zshrc - Add your variable at the end of the file:
export MY_VARIABLE="my_value" - Save the file and exit the editor.
- To apply the changes, run:
source ~/.zshrc
For System-wide Variables:
- Edit the
/etc/profilefile or create a new file in/etc/profile.d/:sudo nano /etc/profile.d/my_variables.sh - Add your variable:
export MY_VARIABLE="my_value" - Save the file and exit the editor.
- The changes will take effect for all users after a restart or by sourcing the profile.
By following these steps, your variables will be available in new terminal sessions.
