Linux Blog

Making Environment Variables Stick

Filed under: General Linux — at 5:00 am on Sunday, October 3, 2010

So, setting environment variables is a pretty easy task right? I thought so too but recently I was unable to read a variable I set from within a Tomcat application no matter what I tried. The problem turns out was easy to fix.

All I needed was to set an environment variable, I didn’t care who had access to it since it was just a path but whatever I did, it just wouldn’t stick. I quickly found out from a co-worker about a magical command that would have been a solution. Problem now was he couldn’t remember what it was. Well it turns out that it is a bash built in called source. Using this with the /etc/profile file as follows: “source /etc/profile” fixed the problem without a reboot.

Random Man Pages:


Comment by Michael Schemer

October 4, 2010 @ 4:30 pm

You also have a .bashrc and .bash_profile for updating your path variables on a user-basis. Only use /etc/profile for environment variables that EVERY user should have.

Comment by Michael Cheselka

October 14, 2010 @ 11:59 pm

Many linuxes have a /etc/profile.d/ directory.
Put and in there and chmod a+x the file.
Logout and test to see if it’s working.
If you change /etc/profile, then updates won’t take and you’ll have to hand edit each time there’s an update.
Also, “$ . /etc/profile” and “$ source /etc/profile” are the same thing.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>