title: run hadoop command as sudo
body: <p>I am trying to run "sudo hadoop namenode -format". I need to run it as sudo, so I cannot change that. But doing so gives the error:</p>
  
  <pre><code>sudo: hadoop: command not found
  </code></pre>
  
  <p>I entered the variables in /etc/environment:</p>
  
  <pre><code>PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/cloud-user/hadoop-2.2.0/bin:/home/cloud-user/hadoop-2.2.0/sbin"
  JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
  HADOOP_INSTALL="/home/cloud-user/hadoop-2.2.0"
  HADOOP_MAPRED_HOME="/home/cloud-user/hadoop-2.2.0"
  HADOOP_COMMON_HOME="/home/cloud-user/hadoop-2.2.0"
  HADOOP_HDFS_HOME="/home/cloud-user/hadoop-2.2.0"
  YARN_HOME="/home/cloud-user/hadoop-2.2.0"
  HADOOP_COMMON_LIB_NATIVE_DIR="/home/cloud-user/hadoop-2.2.0/lib/native"
  </code></pre>
  
  <p>I then created a file under /etc/profile.d,called myenvvars.sh, with the contents:</p>
  
  <pre><code>export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  export HADOOP_INSTALL=/home/cloud-user/hadoop-2.2.0
  export PATH=$PATH:$HADOOP_INSTALL/bin
  export PATH=$PATH:$HADOOP_INSTALL/sbin
  export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
  export HADOOP_COMMON_HOME=$HADOOP_INSTALL
  export HADOOP_HDFS_HOME=$HADOOP_INSTALL
  export YARN_HOME=$HADOOP_INSTALL
  export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
  export HADOOP_OPTS=-Djava.library.path=/lib
  </code></pre>
  
  <p>Finally, I wrote the same thing in /etc/bash.bashrc.</p>
  
  <pre><code>export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  export HADOOP_INSTALL=/home/cloud-user/hadoop-2.2.0
  export PATH=$PATH:$HADOOP_INSTALL/bin
  export PATH=$PATH:$HADOOP_INSTALL/sbin
  export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
  export HADOOP_COMMON_HOME=$HADOOP_INSTALL
  export HADOOP_HDFS_HOME=$HADOOP_INSTALL
  export YARN_HOME=$HADOOP_INSTALL
  export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
  export HADOOP_OPTS=-Djava.library.path=/lib
  </code></pre>
  
  <p>None of them has worked. Please help!!</p>