How to set environment variable in ubuntu?

Member

by johann , in category: General Help , 7 months ago

How to set environment variable in ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jewel , a month ago

@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.