Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

# User specific environment and startup programs


export PATH
export JAVA_HOME="/usr/java/jdk1.6.0_22"
share|improve this question
up vote 3 down vote accepted

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

which java
echo $PATH

with and without root.

share|improve this answer
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 Jul 20 '11 at 1:57
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. – Jul 20 '11 at 2:08

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.

share|improve this answer
/etc ‽‽‽‽‽‽ – Hello71 Jul 20 '11 at 2:06
I didn't know where to put it, and /etc/ was the only directory I could think of... hence the "?" – Windos Jul 20 '11 at 2:20
FHS: "/etc : Host-specific system configuration" – Hello71 Jul 20 '11 at 2:21
@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 Jul 20 '11 at 4:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.