Sobes.tech
Junior — Middle

How can you set or change the value of an environment variable in the Linux operating system?

sobes.tech AI

Answer from AI

Variables in Linux can be set or modified using several methods:

  • In the current terminal session:
export VARIABLE_NAME=value

For example:

export PATH=$PATH:/new/path
  • To make a variable available in all new sessions, add it to the shell configuration file, such as ~/.bashrc, ~/.bash_profile, or /etc/environment (for system variables).

Example of adding to ~/.bashrc:

export MY_VAR="my_value"

After editing the file, run source ~/.bashrc or restart the terminal to apply changes.

Thus, temporarily — via export in the terminal, permanently — through shell configuration files.