title: Could not find or load main class when trying to format namenode; hadoop installation on MAC OS X 10.9.2
body: <p>I'm trying to get a development single-node cluster setup done on my MAC OS X 10.9.2 with hadoop. I've tried various online tutorials, with the most recent being <a href="http://www.alexjf.net/blog/distributed-systems/hadoop-yarn-installation-definitive-guide">this one</a>. To summarize what I did:</p>
  
  <pre><code>1) $ brew install hadoop
  </code></pre>
  
  <p>This installed hadoop 2.2.0 in /usr/local/Cellar/hadoop/2.2.0</p>
  
  <p>2) Configured Environment Variables. Here's what the relevant part of my .bash_profile looks like: </p>
  
  <pre><code>### Java_HOME 
  export JAVA_HOME="$(/usr/libexec/java_home)"
  
  ### HADOOP Environment variables
  export HADOOP_PREFIX="/usr/local/Cellar/hadoop/2.2.0"
  export HADOOP_HOME=$HADOOP_PREFIX
  export HADOOP_COMMON_HOME=$HADOOP_PREFIX
  export HADOOP_CONF_DIR=$HADOOP_PREFIX/libexec/etc/hadoop
  export HADOOP_HDFS_HOME=$HADOOP_PREFIX
  export HADOOP_MAPRED_HOME=$HADOOP_PREFIX
  export HADOOP_YARN_HOME=$HADOOP_PREFIX
  
  export CLASSPATH=$CLASSPATH:.
  export CLASSPATH=$CLASSPATH:$HADOOP_HOME/libexec/share/hadoop/common/hadoop-common-2.2.0.jar
  export CLASSPATH=$CLASSPATH:$HADOOP_HOME/libexec/share/hadoop/hdfs/hadoop-hdfs-2.2.0.jar
  </code></pre>
  
  <p>3) Configured HDFS</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;property&gt;
  &lt;name&gt;dfs.datanode.data.dir&lt;/name&gt;
  &lt;value&gt;file:///usr/local/Cellar/hadoop/2.2.0/hdfs/datanode&lt;/value&gt;
  &lt;description&gt;Comma separated list of paths on the local filesystem of a DataNode where it should store its blocks.&lt;/description&gt;
    &lt;/property&gt;
  
    &lt;property&gt;
      &lt;name&gt;dfs.namenode.name.dir&lt;/name&gt;
      &lt;value&gt;file:///usr/local/Cellar/hadoop/2.2.0/hdfs/namenode&lt;/value&gt;
      &lt;description&gt;Path on the local filesystem where the NameNode stores the namespace and transaction logs persistently.&lt;/description&gt;
    &lt;/property&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>3) Configured core-site.xml</p>
  
  <pre><code>&lt;!-- Let Hadoop modules know where the HDFS NameNode is at! --&gt;
    &lt;property&gt;
      &lt;name&gt;fs.defaultFS&lt;/name&gt;
      &lt;value&gt;hdfs://localhost/&lt;/value&gt;
      &lt;description&gt;NameNode URI&lt;/description&gt;
    &lt;/property&gt;
  </code></pre>
  
  <p>4) Configured yarn-site.xml</p>
  
  <pre><code>&lt;configuration&gt;
     &lt;property&gt;
      &lt;name&gt;yarn.scheduler.minimum-allocation-mb&lt;/name&gt;
      &lt;value&gt;128&lt;/value&gt;
      &lt;description&gt;Minimum limit of memory to allocate to each container request at the Resource Manager.&lt;/description&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;yarn.scheduler.maximum-allocation-mb&lt;/name&gt;
      &lt;value&gt;2048&lt;/value&gt;
      &lt;description&gt;Maximum limit of memory to allocate to each container request at the Resource Manager.&lt;/description&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;yarn.scheduler.minimum-allocation-vcores&lt;/name&gt;
      &lt;value&gt;1&lt;/value&gt;
      &lt;description&gt;The minimum allocation for every container request at the RM, in terms of virtual CPU cores. Requests lower than this won't take effect, and the specified value will get allocated the minimum.&lt;/description&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;yarn.scheduler.maximum-allocation-vcores&lt;/name&gt;
      &lt;value&gt;2&lt;/value&gt;
      &lt;description&gt;The maximum allocation for every container request at the RM, in terms of virtual CPU cores. Requests higher than this won't take effect, and will get capped to this value.     &lt;/description&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;yarn.nodemanager.resource.memory-mb&lt;/name&gt;
      &lt;value&gt;4096&lt;/value&gt;
      &lt;description&gt;Physical memory, in MB, to be made available to running containers&lt;/description&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;yarn.nodemanager.resource.cpu-vcores&lt;/name&gt;
      &lt;value&gt;2&lt;/value&gt;
      &lt;description&gt;Number of CPU cores that can be allocated for containers.&lt;/description&gt;
    &lt;/property&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>5) Then I tried to format the namenode using:</p>
  
  <pre><code>$HADOOP_PREFIX/bin/hdfs namenode -format
  </code></pre>
  
  <p>This gives me the error: Error: Could not find or load main class org.apache.hadoop.hdfs.server.namenode.NameNode. </p>
  
  <p>I looked at the hdfs code, and the line that runs it basically amounts to calling</p>
  
  <pre><code>$java org.apache.hadoop.hdfs.server.namenode.NameNode.
  </code></pre>
  
  <p>So thinking this was a classpath issue, I tried a few things</p>
  
  <p>a) adding hadoop-common-2.2.0.jar and hadoop-hdfs-2.2.0.jar to the classpath as you can see above in my .bash_profile script</p>
  
  <p>b) adding the line </p>
  
  <pre><code>export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
  </code></pre>
  
  <p>to my .bash_profile on the recommendation of <a href="http://www.sixplan.net/blogs/?p=51">this tutorial</a>.(I later removed it because it didn't seem to help anything)</p>
  
  <p>c) I also considered writing a shell script that adds every jar in $HADOOP_HOME/libexec/share/hadoop to the $HADOOP_CLASSPATH, but this just seemed unnecessary and prone to future problems. </p>
  
  <p>Any idea why I keep getting the Error: Could not find or load main class org.apache.hadoop.hdfs.server.namenode.NameNode ? Thanks in advance. </p>