To set a new environment variable in a Linux terminal, you can use the export command. Here’s how to do it:
- Open your terminal.
- Use the following syntax to set a new environment variable:
export VARIABLE_NAME="value"
For example, to set a variable named MY_VAR with the value HelloWorld, you would run:
export MY_VAR="HelloWorld"
- To verify that the variable has been set, you can use:
echo $MY_VAR
This should output:
HelloWorld
Making it Persistent
If you want the environment variable to persist across terminal sessions, add the export command to your shell's configuration file (e.g., ~/.bashrc or ~/.zshrc):
- Open the configuration file in a text editor:
nano ~/.zshrc # for zsh users
- Add the export command at the end of the file:
export MY_VAR="HelloWorld"
- Save and exit the editor.
- To apply the changes, run:
source ~/.zshrc
Now, MY_VAR will be available in future terminal sessions.
