why can I invoke java from one user, but not root?

2

I think this sequence of commands explains my whole question:

[Ramy@Moonface Downloads]$ java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Server VM (build 17.1-b03, mixed mode)
[Ramy@Moonface Downloads]$ su -
Password: 
[root@Moonface ~]# java -version
bash: java: command not found

Running fedora 13

I suppose it's worth explicitly asking: what steps do I need to take to be able to invoke java as root?

more info:

[Ramy@Moonface ~]$ which java
/usr/java/jdk1.6.0_22/bin/java
[Ramy@Moonface ~]$ echo $PATH
/usr/java/jdk1.6.0_12/bin:/usr/java/jdk1.6.0_12/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/  sbin:/usr/sbin:/sbin:/home/Ramy/bin:/usr/java/jdk1.6.0_22/bin
[Ramy@Moonface ~]$ su -
Password: 
[root@Moonface ~]# which java
/usr/bin/which: no java in     (/usr/java/jdk1.6.0_12/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/roo  t/bin)
[root@Moonface ~]# echo $PATH
/usr/java/jdk1.6.0_12/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

UPDATE: so obviously "/usr/java/jdk1.6.0_22/bin" is missing from the path for root. How can I add it to the path for root?? here is my ~/bash_profile:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export JAVA_HOME="/usr/java/jdk1.6.0_22"

Ramy

Posted 2011-07-20T01:04:21.543

Reputation: 1 005

Answers

3

Check if java is on your path, e.g. by using the commands

which java
echo $PATH

with and without root.

billc.cn

Posted 2011-07-20T01:04:21.543

Reputation: 6 821

i've updated my question but I need some further help. I'm not sure how to modify my path or what way to modify it. – Ramy – 2011-07-20T01:57:36.660

Hi, you can change the PATH environment variable in shell configuration files. The location varies from distribution to distribution, but you can generally find it in /etc (e.g. /etc/bash.bashrc, /etc/profile, /etc/profile.d/*). You can find details by googling "[distribution name] change path". You may also need to set JAVA_HOME to make sure java finds the correct libraries. – billc.cn – 2011-07-20T02:08:43.753

2

n.b. the following is from a Windows user with only a few weeks worth of linux experience, so if I use some Windowsy terms I'm sorry.

The files needed to invoke Java could be in your user's home directory or the Downloads one. These locations may not be looked in when you're root (similar to when something isn't in the Windows path variable) so under root the OS looks in common areas (and root's home dir) and can't find it, under the user it looks in the common areas and it's home directory and find it in there.

Try finding the Java files and moving them to a common area.

Windos

Posted 2011-07-20T01:04:21.543

Reputation: 10 080

1/etc ‽‽‽‽‽‽ – Hello71 – 2011-07-20T02:06:46.670

I didn't know where to put it, and /etc/ was the only directory I could think of... hence the "?" – Windos – 2011-07-20T02:20:40.500

FHS: "/etc : Host-specific system configuration" – Hello71 – 2011-07-20T02:21:53.597

@Josh King: if you don't know the unix-file system you should just drop that part of the answer. especially for a "windows user with only a few weeks worth of linux experience", they will take your /etc suggestions as a valid answer... – akira – 2011-07-20T04:18:24.250