How Do You set System-Wise Environment Variables?

Hey everyone. I just recently reinstalled openSUSE 11.3 last night with the GNOME desktop. Since I’m starting fresh again, I’d like to set up my System as flawless as possible.

So, my question is stated in the Title. How do you set System-Wide environment variables on OpenSUSE 11.3 // GNOME? I usually set them by adding an export to my ~/.bashrc, but I remember in Ubuntu that I could add them to /etc/environment. I checked that file out on my system, and it has a the default comment on it stating:

“This file is parsed by pam_env module…Syntax: simple “KEY=VAL” pairs on seperate lines”

This seems to be the spot to add my “export JAVA_HOME=/usr/java/…etc”, etc. but I wanted to clarify before I went ahead and made any changes. Like I said, I’m going for Flawless, lol.

So, if you know how to set System-Wide Environment Variables, please respond! All help is greatly appreciated.

sgrayjr289 wrote:

>
> Hey everyone. I just recently reinstalled openSUSE 11.3 last night with
> the GNOME desktop. Since I’m starting fresh again, I’d like to set up my
> System as flawless as possible.
>
> So, my question is stated in the Title. How do you set System-Wide
> environment variables on OpenSUSE 11.3 // GNOME? I usually set them by
> adding an export to my ~/.bashrc, but I remember in Ubuntu that I could
> add them to /etc/environment. I checked that file out on my system, and
> it has a the default comment on it stating:
>
> “This file is parsed by pam_env module…Syntax: simple “KEY=VAL” pairs
> on seperate lines”
>
> This seems to be the spot to add my “export JAVA_HOME=/usr/java/…etc”,
> etc. but I wanted to clarify before I went ahead and made any changes.
> Like I said, I’m going for Flawless, lol.
>
> So, if you know how to set System-Wide Environment Variables, please
> respond! All help is greatly appreciated.
>
>
In /etc/environment you don’t need the ‘export’ prefix, as it’s not really a
shell script - no commands or variable substitutions either.

And fix the typo in ‘separate’ while you’re editing it :wink:

1 Like

I think you would add it to /etc/profile.local

Like GeoBaltz says, do as you are told: “Syntax: simple “KEY=VAL” pairs on seperate lines”. Do not add the word export in front of it.

While this might do what you want to achieve, it is not what you asked for.

It will add the environment variable to the login shell of all users that log in. And thus the variable will be inherited by all the processes started from that login shell.
I hope you undestand that that is not system wide for all processes in the sytem as there are allready many processes running before any user gets the possibility to log in. And the eventual child processes of those processes will thus also not have them in their environment.

Okay so I set up my /etc/environment as I needed, but I have a question about it. I added the following line to the file: “PATH=$PATH:/usr/local/tomcat/bin:/usr/local/maven/bin:/usr/java/jdk1.6.0_21/bin:/usr/java/jdk1.6.0_21/jre/bin”.

After submitting the changes with “. /etc/environment”, I logged into the terminal as root and my current logged in name, root@linux-xxxx:~, for example, is no longer the color Red. I commented it out and added that same line with “export” preceding it to my ~/.bashrc, sourced it, and when I login as root, it was colored red like it’s supposed to be.

So my question is, why is adding stuff to my PATH in /etc/environment removing my colored root login, but my ~/.bashrc does not? I don’t think it’ll mess anything up, but it’s nice to know when I’m logged into root just by the color of my command line.

Do any of you know what I can do to fix my coloring due to this change? Also, what file contains the system default PATH? I would like to permanently remove the OpenJDK/bin and replace it with my java-sun/bin in my PATH.

Thanks for all the help guys! Also, good eye on the typo GeoBaltz, lol.

I am not understanding all you say.

Why “submitting the changes in /etc/environment” by sourcing it? As explained to you, it is a configuration file for pam_env module and does NOT contain shell statements (though it may look like them). I am not even sure that the “KEY=VAL” syntax includes that you can use shell variables (like the $PATH you use) in the VAL part with the desired (by you) result. For this I would like to know more about this file, maybe by reading PAM docs.

After you made the change it should work for the next login imho.

I can not explain why your colouring is gone, but on the other hand I do not know what the effect of the line in* /etc/environment *will be. May be it is better to first try to find a more detailed documentation about the usage of /etc/environment (I tried a quick search, but failed).

Also you say “I logged into the terminal as root”. I hope I misunderstand you and you in fact did something like

su -

to gain root status.

As I said before, your whish for “system wide” is not quite clear to me, but when you want this for everybody that logs in and starts using bash, then you could create the file /etc/bash.bashrc.local and put them there (yes, this time as bash command lines to be sourced during the login process). According to some lines in /etc/bash.bashrc:

# PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes
# will be lost during system upgrades.  Instead use /etc/bash.bashrc.local
# for your local settings, favourite global aliases, VISUAL and EDITOR
# variables, etc ...

HTH

hcvv wrote:

>
> Like GeoBaltz says, do as you are told: “Syntax: simple “KEY=VAL” pairs
> on seperate lines”. Do not add the word export in front of it.
>
> While this might do what you want to achieve, it is not what you asked
> for.
>
> It will add the environment variable to the login shell of all users
> that log in. And thus the variable will be inherited by all the
> processes started from that login shell.
> I hope you undestand that that is not system wide for all processes in
> the sytem as there are allready many processes running before any user
> gets the possibility to log in. And the eventual child processes of
> those processes will thus also not have them in their environment.
>
>

Hmmmmm. Maybe we have a slight difference here…

I haven’t tried this in openSUSE, but in AIX(and I believe other Unices),
/etc/environment is for ALL processes, even those started outside of normal
logins; i.e., daemons, xdm/kdm/gdm, (x)inetd, etc. So in AIX it does
exactly what the OP asked for.

I must admit, though, that the comment that it is read by part of PAM has me
confused. Guess it’s time for some experiments…

sgrayjr289 wrote:

>
> Okay so I set up my /etc/environment as I needed, but I have a question
> about it. I added the following line to the file:
>
“PATH=$PATH:/usr/local/tomcat/bin:/usr/local/maven/bin:/usr/java/jdk1.6.0_21/bin:/usr/java/jdk1.6.0_21/jre/bin”.
>
>
Note where I said that /etc/environment is NOT a shell script - no shell
variables (i.e. $PATH) allowed. For something like this you’ll have to
enter the full path or use one of the files that really are executed by the
shell.

Aight I appreciate all your guys’ help. I just ended up exporting the environment variables I needed in my ~/.bashrc. I did learn a good bit about a lot of the other system configuration files and whatnot in the process though, so i appreciate all of your help!

Well, I’m fairly sure the correct place is /etc/profile.local for global environment variables, and ~/.profile for users.

From /etc/profile


# /etc/profile for SuSE Linux
#
# PLEASE DO NOT CHANGE /etc/profile. There are chances that your changes
# will be lost during system upgrades. Instead use /etc/profile.local for
# your local settings, favourite global aliases, VISUAL and EDITOR
# variables, etc ...

#
# Check which shell is reading this file
#

@GeoBaltz
It seems that we are commenting here asyncronous lol!

You comment about what /etc/environment does is interesting.
Your AIX experience tells you that it is added to all processes, that would mean imho that init would read it and spread it it all over the processes. Then why does it talk here in Linux (not AIX) about pam_env?

Not that I know the answer, but it adds to my suspicion that we are looking at a file where we lack docuumentation. We have only the word (no prove) that the OP “remembers in Ubuntu that I could add them to /etc/environment”, which is very vague (and brought the OP to completely wrong ideas about what should go there).

Maybe when the OP can confirm that he in factdoes NOT want system wide, but “login wide” environment variables, we then have the solution as in /etc/bash.bashrc.local (or the profile variant).

Thinking about it, I admit that that is where I would put it. It would btw also work with a lot of other shells while bashrc works only for bash.
Looking in the bash man page will imho tell you wich (the profile group and/or the bashrc group) is used in which circumstances (there is a difference).

hcvv wrote:

>
> @GeoBaltz
> It seems that we are commenting here asyncronous lol!
>
Yes, that’s one problem with having both HTTP and NNTP access to the forums.

> You comment about what /etc/environment does is interesting.
> Your AIX experience tells you that it is added to all processes, that
> would mean imho that -init- would read it and spread it it all over the
> processes. Then why does it talk here in Linux (not AIX) about pam_env?
>

Yes, I do think ‘init’ (PID=1) got involved in AIX, but its startup
structure was very different from openSUSE. It did allow for adding
environment settings for services started via inetd. The only other choice
we had was to add a wrapper script around the various servers, but that was
a mess to maintain.

> Not that I know the answer, but it adds to my suspicion that we are
> looking at a file where we lack docuumentation. We have only the word
> (no prove) that the OP “remembers in Ubuntu that I could add them to
> /etc/environment”, which is very vague (and brought the OP to completely
> wrong ideas about what should go there).
>
> Maybe when the OP can confirm that he in factdoes NOT want system wide,
> but “login wide” environment variables, we then have the solution as in
> /etc/bash.bashrc.local (or the profile variant).
>

Yes, there are enough variables being bandied about here that we really need
a real set of requirements. (AAAARRRGGGHHHHH I can’t believe I just said
that!! :slight_smile: )

Your post about the /etc/bash.bashrc.local went over my head. I knew there could be a /etc/profile.local but didn’t know about a /etc/bash.bashrc.local. It looks like the /etc/bash.bashrc also handles the other shells, csh, ksh, etc.

No, about face. /etc/profile.local is likely to be used by most of the shells (I am a bit crefull hre, but yyou could say “all” shells to be practical). Forget about the bash.bashrc.local and cocentrate at using /etc/profile.local.

When you want all the details, read he bash man page about this subject (as suggested earlier and as I in fact assume you did after rading post #13 above).