In Linux, environment variables can be set either temporarily (for the current session) or permanently (by modifying shell configuration files).
To set a temporary environment variable open a terminal and use the following syntax
export VARIABLE_NAME=value
This variable will remain active only in the current terminal session. Once you close the terminal, it will no longer be available.
To set environment variables permanently, you can add them to your shell's configuration file. Most commonly, this is the .bashrc file (for Bash users) or .zshrc file (for Zsh users).
Use a text editor like nano or vim to open the .bashrc file. The .bashrc file is a hidden file in your user directory. If you are unsure where to find it, use the following command in a terminal:
nano ~/.bashrc
Scroll to the end of the file and add the variable via the export command
export VARIABLE_NAME=value
Save the file and restart the terminal.
If you wish to confirm that a variable is active (temporary or persistent) you can use the echo command:
echo $MY_VAR