Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: How Do You set System-Wise Environment Variables?

  1. #1
    Join Date
    Sep 2010
    Location
    Woodstock, GA
    Posts
    13

    Default 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.

  2. #2
    Join Date
    Jun 2009
    Location
    Pennsylvania, USA
    Posts
    233

    Default Re: How Do You set System-Wise Environment Variables?

    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 ;-)


  3. #3

    Default Re: How Do You set System-Wise Environment Variables?

    I think you would add it to /etc/profile.local
    Box 1: OpenSuse 11.1/Win7 | Linux 2.6.27 Gnome | AMD 64 X2 6000+ | nVidia 8600GT | 2GB RAM
    Box 2: OpenSuse 11.2 | Linux 2.6.31 Gnome | AMD 64 3000+ | ATI X800 Pro | 1GB RAM
    Box 3: Win7 Premium Home | Intel P4 3.0Gz | ATI AIW 2006 | 2GB RAM

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,972

    Default Re: How Do You set System-Wise Environment Variables?

    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.
    Henk van Velden

  5. #5
    Join Date
    Sep 2010
    Location
    Woodstock, GA
    Posts
    13

    Default Re: How Do You set System-Wise Environment Variables?

    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.

  6. #6
    Join Date
    Jun 2009
    Location
    Pennsylvania, USA
    Posts
    233

    Default Re: How Do You set System-Wise Environment Variables?

    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...


  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,972

    Default Re: How Do You set System-Wise Environment Variables?

    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
    Code:
    su -
    to gain root status.
    Henk van Velden

  8. #8
    Join Date
    Jun 2009
    Location
    Pennsylvania, USA
    Posts
    233

    Default Re: How Do You set System-Wise Environment Variables?

    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.


  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,972

    Default Re: How Do You set System-Wise Environment Variables?

    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:
    Code:
    # 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
    Henk van Velden

  10. #10
    Join Date
    Sep 2010
    Location
    Woodstock, GA
    Posts
    13

    Default Re: How Do You set System-Wise Environment Variables?

    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!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •