Question3r
Question3r

Reputation: 3742

Environment variable always reverts to old value

I'm using Linux and want to update an environment variable. I set a new entry with

export theKey=theOldValue

and checked with

printenv

Now I have a new value for this key and want to update it. I wasn't able to find any "update" commands so I run the export command again. This seems to update the entry when running printenv but whenever I try to read the value from my code I get the old entry value.

Whenever I change the value I reboot the machine.

Since this isn't working properly I tried the following

When checking the value this variable reverted back to the old value. Does someone know what I'm missing?

Upvotes: 1

Views: 1564

Answers (1)

G. Bai
G. Bai

Reputation: 513

The export command has the effect in the one terminal session you run it only. So you need to touch ~/.bashrc if you are using bash, and put your export entry in that file. Then to apply it in that session, do source ~/.bashrc. For future terminal sessions, this file will be loaded automatically.

See more info here.

Upvotes: 5

Related Questions