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/
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:
export PATH=$PATH:$JAVA_HOME/bin
try:
case "$PATH" in
*java*) ;; ## nothing - already in path
*) export PATH=$PATH:$JAVA_HOME/bin ;; ## add to path
esac
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
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 …
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…
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 …
> 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:
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.
The reason you saw root in the $PATH because I was logged in as root at the time.
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.
I may be wrong, in which case I’m sure someone will correct me, but I
think if you put your custom $PATH in ~/.bash_profile it will only be
called once.
If I just used export PATH:etc wouldn’t it just write over the existing path? By appending I am not overwriting that’s in bash.bashrc. The reason I use bash.bashrc.local is because I found this message in 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.
I’m assuming I’m getting the first part of my PATH from this script.
I come from the Windows world so I don’t consider myself an expert on all this. I just can say that now I see no duplication in my PATH.
Appending to PATH, as you are doing, is correct. Putting that in the “bash.bashrc.local” file should be fine.
It is just the way that linux (and unix) works, that the script is effectively being run twice.
If the PATH were defined in “~/.bash_profile”, as one person suggested, that would not have helped.
The bash startup scripts are run at the start of your GUI session, because any environment definitions should apply to every process and not just to shell processes. And the startup scripts are run when starting a shell because you might have other shell settings that should apply to that particular shell.
As I understand it the ~/.bash_profile is only executed when you log in, whereas the ~/.bashrc is executed with every bash instance; therefore placing something in the ~/.bash_profile would at least reduce the number of times it is called, and in the case of users who login once and then use a terminal window the ~/.bash_profile would be executed only once.