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

Thread: JAVA_HOME environment variable showing twice

  1. #1
    Join Date
    Apr 2009
    Location
    Annapolis, MD
    Posts
    204

    Default JAVA_HOME environment variable showing twice

    I set up my JAVA_HOME environment variable in /etc/bash.bashrc.local

    JAVA_HOME=/usr/lib64/jvm/java-1.6.0-openjdk
    export PATH=$PATH:$JAVA_HOME/bin

    echo $PATH
    /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib64/jvm/java-1.6.0-openjdk/bin:/usr/lib64/jvm/java-1.6.0-openjdk/bin

    However, when I call $PATH I see it displayed twice. How do I get rid of this duplication and only show it once in PATH?

  2. #2

    Default Re: JAVA_HOME environment variable showing twice

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    The JAVA_HOME path that you specified was already in the PATH variable it
    would seem... there's no reason to concatenate it in there again. Having
    duplicates doesn't hurt things really.

    Good luck.





    On 04/15/2011 08:36 PM, imterpsfan2 wrote:
    >
    > I set up my JAVA_HOME environment variable in /etc/bash.bashrc.local
    >
    > JAVA_HOME=/usr/lib64/jvm/java-1.6.0-openjdk
    > export PATH=$PATH:$JAVA_HOME/bin
    >
    > echo $PATH
    > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib64/jvm/java-1.6.0-openjdk/bin:/usr/lib64/jvm/java-1.6.0-openjdk/bin
    >
    > However, when I call $PATH I see it displayed twice. How do I get rid
    > of this duplication and only show it once in PATH?
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.15 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iQIcBAEBAgAGBQJNqRYkAAoJEF+XTK08PnB5O0cQAIsb4GfD88BKIT3CXud2UyRj
    dOEcjLQRWQShXWdRw8ZTTJIcGClkA77ydnGu+HWIXUnv9pLapEpkGspDx4S0/Tph
    qgG/1Y/0pX6sEr+j701v9fiQnJk/fNSv/EZcTLcSWIr+XUJek/EjKN3nO0wJlL33
    97uuHZ6IkQ8xfidXq/VKxZS/r0vY+dkumU7HzY9Ik3EMgHiSsbjT7O8FEXo3g709
    ccGvkmhO3Zs+y7CjxjIUQzM+UOwZ8/LLUH6wZ1cGeJJB+k7U2OMqN0rZ1WQK/DUf
    PifFhLABcybZ/6E7sUt3lwSAPv09+0A0qE+KB5Nd/i2hNg1TeC8nKqHE0nrqzk1i
    U+8y1z2oDhivt1K5v4jUT1190GzjsdBdK/0RHknNHQVe7ncorH/gnzBRrIZAzO3t
    aUB2W4x+/E24IKSxb/wCxNOQUEPIWaUQSR6YlvIE8NxdKpdELTdlHjudxOjxMEXD
    XVNmJoFSzOYZhjxLY4tmZxabJ4/R9mWEX4fEVeSHZTPaM/zLddnFxguJDszhF5MY
    EHbOMF8S6CczdCIADz5VpyagcwdGtNvSwFAyoWA6kJeKWxYoHh1WuvE1OO3mLgQA
    mxLX65M2VpsGjoxa0TKyz5I4i42vBCJzPGsTs8DROWksRqRyzjgb2iYsh0QoGX7b
    CL9PB/o/2MJ0CA5uI2A/
    =2GRy
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    15,681
    Blog Entries
    3

    Default Re: JAVA_HOME environment variable showing twice

    bash.bashrc.local is probably being called twice - once when starting your desktop, and then again when you start a shell. So the particular path element is being added twice.

    Instead of:
    Code:
    export PATH=$PATH:$JAVA_HOME/bin
    try:
    Code:
    case "$PATH" in
      *java*) ;; ## nothing - already in path
      *) export PATH=$PATH:$JAVA_HOME/bin ;; ## add to path
    esac
    Note: I did not test this.
    openSUSE Leap 15.3; KDE Plasma 5.18.6;

  4. #4
    Join Date
    Apr 2009
    Location
    Annapolis, MD
    Posts
    204

    Default Re: JAVA_HOME environment variable showing twice

    Thanks nrickert, this was able to point me in the right direction. I modified your syntax to add multiple paths. Your solution really worked for me. You're right, it seems that bashrc.local gets called when you login as well as when you open a terminal session.

    JAVA_HOME=/usr/lib64/jvm/java-1.6.0-openjdk
    JRUBY_HOME=/home/charles/netbeans-6.7.1/ruby2/jruby-1.2.0
    case "$PATH" in
    *java*);; ## java already in path -- don't add it
    *) export PATH=$PATH:$JAVA_HOME/bin;; ## add to path
    esac
    case "$PATH" in
    *jruby*);; ## jruby already in path -- don't add it
    *) export PATH=$PATH:$JRUBY_HOME/bin;; ## add jruby to path
    esac

  5. #5

    Default Re: JAVA_HOME environment variable showing twice

    imterpsfan2 wrote:
    > I set up my JAVA_HOME environment variable in /etc/bash.bashrc.local
    >
    > JAVA_HOME=/usr/lib64/jvm/java-1.6.0-openjdk
    > export PATH=$PATH:$JAVA_HOME/bin
    >
    > echo $PATH
    > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib64/jvm/java-1.6.0-openjdk/bin:/usr/lib64/jvm/java-1.6.0-openjdk/bin
    >
    > However, when I call $PATH I see it displayed twice. How do I get rid
    > of this duplication and only show it once in PATH?


    Nothing to do with your question, but that's a lousy set of paths!

    The first three are meant to be restricted to root (or other privileged
    user). They're intended be used only in an environment that does NOT
    include other paths that may have weak security.

    The root user should have a strictly limited environment, and other
    users shouldn't see the commands in the sbin directories, or root's
    private bin come to that.

    Of course, it's up to you haow you set up your machine ...

  6. #6
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

    Default Re: JAVA_HOME environment variable showing twice

    On 04/18/2011 12:07 PM, Dave Howorth wrote:
    > Nothing to do with your question, but that's a lousy set of paths!
    >
    > The first three are meant to be restricted to root


    maybe that *is* root's pass...
    perhaps he is logged in as root ;-)

    many do, you know(?)

    i mean, they did/do it all the time in their other dual boot system, so
    why not here they ask....and, listen to the answer and follow advice, or
    not..

    --
    CAVEAT: http://is.gd/bpoMD
    [openSUSE 11.3 + KDE4.5.5 + Thunderbird3.1.8 via NNTP]
    A Penguin Being Tickled - http://www.youtube.com/watch?v=0GILA0rrR6w

  7. #7

    Default Re: JAVA_HOME environment variable showing twice

    DenverD wrote:
    > On 04/18/2011 12:07 PM, Dave Howorth wrote:
    >> Nothing to do with your question, but that's a lousy set of paths!
    >>
    >> The first three are meant to be restricted to root

    >
    > maybe that *is* root's pass...
    > perhaps he is logged in as root ;-)
    >
    > many do, you know(?)
    >
    > i mean, they did/do it all the time in their other dual boot system, so
    > why not here they ask....and, listen to the answer and follow advice, or
    > not..
    >


    Yes, it could be root's path but then it shouldn't include /usr/local/*
    or /usr/games or ...

  8. #8
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

    Default Re: JAVA_HOME environment variable showing twice

    On 04/18/2011 12:27 PM, Dave Howorth wrote:

    > Yes, it could be root's path but then it shouldn't include /usr/local/*
    > or /usr/games or ...


    ah, but there is more than one way to skin a cat and more than one
    openSUSE image being distributed...my 11.3 KDE from a Linux Magazine
    (october 2010) DVD and my root path this moment is:

    openSUSE11-3:~ # echo $PATH
    /usr/lib/mpi/gcc/openmpi/bin:/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin

    and, i can promise you that i didn't add /usr/local /usr/games or ...

    i wouldn't know how to get the mag's dvd builder (in the UK) to stop
    messin' with the man!

    --
    CAVEAT: http://is.gd/bpoMD
    [openSUSE 11.3 + KDE4.5.5 + Thunderbird3.1.8 via NNTP]
    A Penguin Being Tickled - http://www.youtube.com/watch?v=0GILA0rrR6w

  9. #9
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: JAVA_HOME environment variable showing twice

    Quote Originally Posted by djh-novell View Post
    > echo $PATH
    > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib64/jvm/java-1.6.0-openjdk/bin:/usr/lib64/jvm/java-1.6.0-openjdk/bin
    >
    > However, when I call $PATH I see it displayed twice. How do I get rid
    > of this duplication and only show it once in PATH?[/color]

    Nothing to do with your question, but that's a lousy set of paths!

    The first three are meant to be restricted to root (or other privileged
    user). They're intended be used only in an environment that does NOT
    include other paths that may have weak security.
    Any Linux/Unix OS that depends on those directories not being in a user's path for security has broken programs. Having /sbin:/usr/sbin:/usr/local/sbin in a user's $PATH may trip up the user, but it should not cause any breach of security. It's up to each program to check what the uid of the invoker is and do the right thing. There are some programs in there that are useful to non-root users, e.g. ifconfig, route, modinfo, etc. None of those will allow privileged operations if you are not root.

    I do not however have them on my $PATH. I create symlinks to the useful programs from ~/bin. There are however well-known distros that do put these directories in users' $PATH and don't suffer security problems on that account.

  10. #10
    Join Date
    Apr 2009
    Location
    Annapolis, MD
    Posts
    204

    Default Re: JAVA_HOME environment variable showing twice

    1) The reason you saw root in the $PATH because I was logged in as root at the time.

    2) No, JAVA_HOME wasn't already in the $PATH. The reason why it was duplicated was because as the first respondent mentioned...bash.bashrc.local gets called twice, once when you login and another time when you open the console.

Page 1 of 2 12 LastLast

Similar Threads

  1. Environment Variable Question
    By brianebruce in forum Applications
    Replies: 3
    Last Post: 24-Jun-2009, 08:47
  2. PATH environment variable
    By aecordoba in forum Install/Boot/Login
    Replies: 2
    Last Post: 25-Jul-2008, 16:41

Posting Permissions

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