Export enviroment variable in linux

For User & Application

There are actully three files from the linux reads the enviroment variable

  1. /etc/enviromet 
  2. ~/.profile :
  3. ~/.bashrc 

If your app depened on the enviroment variable then you have to store that variable inside this files otherwise those variable lost as soon as the terminal exits.

To export enviroment variable permanatly in linux follow this commands :

$ echo export variablename='path/value' >> ~/.profile
This will store the variable in the ~./profile


$ echo export variablename='path/value' >> ~/.bashrc
This will store the variable in the ~./bashrc

Now to make this change working you have to run this commands

$ source ~/.profile 
This will evaluate ~/.profile file

$ source ~/.bashrc
This will evaluate ~/.bashrc file


You can locate this files in you users Home folder

Enviroment variable storage files
bashrc and profile files

If you want to go GUI way you can find this files in your /home/[user] folder

bashrc file
bashrc file


For CronJob


This will not work if you have to use the enviroment variable in the cron job

If you want to set the enviroment variable for cron job. Then you have to define that variable in the crontab as well

$crontab -e

This will open the crontab. Here define the variable in this file as i have defined the GOOGLE_APPLICATION_CREDENTAILS in image
Define Enviroment variable fron cron job
Define Enviroment variable for cron job



Comments

Popular Posts