Skip to content
Advertisement

Issue with setting environment variables permanently in linux bash [closed]

I want to set up a global environment variable permanently into the shell, so i do not set it every time i open another shell or another log-in session.

I have set the variable using export as following:

$ export pass='my_pass'

However when i use another active shell to restore this variable using echo as following:

$ echo $pass

The variable does not exist, so it only exist in the local shell of setup.

I have tried putting it into the .bash_profile but this also did not work.

Advertisement

Answer

~/.bash_profile is only sourced on login (i.e. after you’ve typed your username & password) – ~/.bashrc is sourced for interactive non-login shells.

So I’d add the variables into ~/.bashrc (don’t forget to source it first if you’re running the python script afterwards from the same shell). This way, when you open a new shell, bashrc will be sourced and your environment variables will be available.

Edit: As others have said in comments .. running an export command in one shell, won’t make that variable availble in another shell – you need to add it to your ~/.bashrc to make it avaiable in other shells

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement