title: sudo: java: command not found after exiting from root user
body: <p>I have installed jdk but when I tried to use the java command it said "command not found".</p>
  
  <p>So I then set the environment variable for my account in .bashrc and it works okay.</p>
  
  <pre><code>export JAVA_HOME=/usr/java/jdk1.7.0_03
  export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/l\
  ib/tools.jar
  export PATH=$PATH:$JAVA_HOME/bin
  </code></pre>
  
  <p>However when I try to use sudo to execute java it says that again. So I used <code>sudo -s</code> to switch to root, put those into /etc/profile, and executed <code>source /etc/profile</code></p>
  
  <p>This works if I keep logged in as root but after I return to my own account and use <code>sudo java</code> it still says sudo: java: command not found and those environment variables become blank.  </p>
  
  <p>What should I do to solve the problem? I guess it should be easy to solve.</p>