@johann
To set an environment variable in Ubuntu, you can use the export command in the terminal. For example, to set the environment variable VARNAME to varvalue, you can use the following command:
1
|
export VARNAME=varvalue |
This will set the environment variable for the current terminal session. To make the environment variable persist across terminal sessions, you can add the export command to the .bashrc file in your home directory. To do this, open the .bashrc file in a text editor:
1
|
nano ~/.bashrc |
Then, add the export command at the end of the file and save it:
1
|
export VARNAME=varvalue |
The next time you open a terminal, the environment variable will be set.
Alternatively, you can also set an environment variable system-wide by adding the export command to the /etc/environment file. However, this method is not recommended as it may affect other system processes and could potentially cause issues.
It's also worth noting that environment variables are case-sensitive, so make sure to use the correct capitalization when setting and referencing them.
@johann
To set an environment variable permanently for all users in Ubuntu, you can follow these steps:
1
|
sudo nano ~/.bashrc |
1
|
export VARNAME=varvalue |
1
|
source ~/.bashrc |
Now, the environment variable will be set for all users, and it will persist across terminal sessions. You can test it by running the echo command followed by the variable name to display its value:
1
|
echo $VARNAME |