To make a shell variable permanent, you need to add it to a shell configuration file that is executed whenever a new shell session starts. Here are the steps to do this:
Open the Shell Configuration File: Depending on the shell you are using, you can add the variable to one of the following files:
- For
bash, use~/.bashrcor~/.bash_profile. - For
zsh, use~/.zshrc.
You can open the file using a text editor, for example:
nano ~/.bashrc- For
Add the Variable: Add the variable definition at the end of the file. For example:
export MY_VAR="Hello, Permanent Variable"Save and Exit: Save the changes and exit the text editor.
Apply the Changes: To apply the changes without restarting the terminal, run:
source ~/.bashrcor
source ~/.bash_profileVerify the Variable: You can verify that the variable is set by running:
echo $MY_VAROutput:
Hello, Permanent Variable
Now, the variable will be available in all new terminal sessions.
