Results 1 to 8 of 8

Thread: HOWTO: Environment Variables

  1. #1
    Join Date
    Oct 2004
    Location
    Sydney
    Beans
    20

    HOWTO: Environment Variables

    This thread is now closed. The information can be found on the wiki here

    https://help.ubuntu.com/community/EnvironmentVariables




    Environment Variables

    Environment variables for a specific command
    To set a variable for just a one off you can specify the variable on the command line itself as follows...

    NAME=VALUE COMMAND PARAMETERS

    Example
    http_proxy=http://localhost:8080/ apt-get update

    NB: You can have multiple name=value pairs seperated by spaces.

    Environment Variables for the shell/command line
    To permanently add an environment variable you add the following lines to the relevant rc file. Th rc file is read whenever a terminal is opened from the ubuntu desktop. For a program that runs as a specific user you need to add them to the /home/username/.bashrc file. For programs that require sudo access you add these lines to the /root/.bashrc file.

    NAME=VALUE
    export NAME

    Example

    http_proxy=http://localhost:8080
    export http_proxy

    Environment variables for the gnome desktop
    To permanently add variables for the Gnome desktop, you add lines to the ??? file. Please add this information.

    Contribute!
    If you find more information on environment variables then please add them as a reply to this post. Corrections should be sent to the author of his or her post.

    Gecko
    Last edited by nothingspecial; September 13th, 2012 at 02:25 PM.

  2. #2
    Join Date
    Oct 2004
    Location
    Oshawa, Ontario
    Beans
    1

    Re: HOWTO: Environment Variables

    Environment variables for gnome desktop:

    This worked for me:

    edit file: /etc/gdm/gdm.conf
    add your path to the "DefaultPath" line

    example of adding Java /bin to path:
    Code:
    # Default path to set.  The profile scripts will likely override this
    DefaultPath=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin

  3. #3
    Join Date
    Oct 2004
    Location
    Montreal, Canada
    Beans
    Hidden!

    Re: HOWTO: Environment Variables

    Quote Originally Posted by adamw523
    Environment variables for gnome desktop:

    This worked for me:

    edit file: /etc/gdm/gdm.conf
    add your path to the "DefaultPath" line

    example of adding Java /bin to path:
    Code:
    # Default path to set.  The profile scripts will likely override this
    DefaultPath=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin

    Well, it's not working for me. My java is in /usr/local/j2re1.4.2_05/bin. So, I just added this in /etc/gdm/gdm.conf as you said but when I log back and I type "which java" I see nothing! I also tried to add this line in my ~/.bash_profile:

    export PATH=$PATH:/usr/local/j2re1.4.2_05/bin

    But it's still loosing it when I reboot. What I'm doing wrong??

    Thanks.

  4. #4
    Join Date
    Oct 2004
    Location
    Sydney
    Beans
    20

    Re: HOWTO: Environment Variables

    Try your ~/.bashrc file.

    Please turn on private messaging so I can privmsg replies to your questions.

    Gecko

  5. #5
    Join Date
    Dec 2004
    Beans
    36

    Re: HOWTO: Environment Variables

    More effective (Apparently) is adding them to /etc/environment.

    exporting is not required there.

  6. #6
    Join Date
    Jun 2007
    Location
    Silicon Valley
    Beans
    12
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: HOWTO: Environment Variables

    Is this a catch all situation for most Linux distributions? I tried editing a PATH variable in /etc/profile and wound up unable to ls or sudo (silly me, I forgot the /bin directory, let alone /sbin).

    In these scripts, would just declaring the variable work or do I have to use export keyword?

    e.g is it this

    export PATH=" ... "

    or this

    PATH = " ... "

    I've seen some scripts do this as well in /etc/profile. Any comments on it?

    PATH=" ... "
    export PATH

  7. #7
    Join Date
    Mar 2010
    Beans
    11

    Wink Re: HOWTO: Environment Variables

    Quote Originally Posted by gecko View Post
    Environment Variables

    Environment variables for a specific command
    To set a variable for just a one off you can specify the variable on the command line itself as follows...

    NAME=VALUE COMMAND PARAMETERS

    Example
    http_proxy=http://localhost:8080/ apt-get update

    NB: You can have multiple name=value pairs seperated by spaces.

    Environment Variables for the shell/command line
    To permanently add an environment variable you add the following lines to the relevant rc file. Th rc file is read whenever a terminal is opened from the ubuntu desktop. For a program that runs as a specific user you need to add them to the /home/username/.bashrc file. For programs that require sudo access you add these lines to the /root/.bashrc file.

    NAME=VALUE
    export NAME

    Example

    http_proxy=http://localhost:8080
    export http_proxy

    Environment variables for the gnome desktop
    To permanently add variables for the Gnome desktop, you add lines to the ??? file. Please add this information.

    Contribute!
    If you find more information on environment variables then please add them as a reply to this post. Corrections should be sent to the author of his or her post.

    Gecko

    Ohhh!!! Thanks!! this help me a lot!!!

  8. #8
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

Bookmarks

Posting Permissions

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