How Do You Get Hadoop Commands to Work from Any Directory without Using the Full Path?

Problem scenario
Hadoop is installed on Linux. But hadoop version and other hadoop commands are not working. What should you do?

Solution
Find the hadoop executable in a directory named bin. It is often "/usr/local/hadoop/bin/hadoop". Ultimately you need to find the directory that houses this "bin." has a subdirectory with "bin" and "hadoop" inside, run these two commands:

sudo find / -name hadoop -type f
whereis hadoop

Run these commands interactively where "/usr/local/hadoop" is the directory that is the parent of the subdirectory named "bin" that is the parent of the hadoop executable.

export HADOOP_PREFIX=/usr/local/hadoop
export HADOOP_MAPRED_HOME=$HADOOP_PREFIX
export HADOOP_COMMON_HOME=$HADOOP_PREFIX
export HADOOP_HDFS_HOME=$HADOOP_PREFIX
export YARN_HOME=$HADOOP_PREFIX
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_PREFIX/lib/native
export PATH=$PATH:$HADOOP_PREFIX/sbin:$HADOOP_PREFIX/bin
source ~/.bashrc

Test it. Run this hadoop version

Now to ensure this persists through a reboot, run this: sudo vi ~/.bashrc Append the lines below to the file (and then save the file):

export HADOOP_PREFIX=/usr/local/hadoop
export HADOOP_MAPRED_HOME=$HADOOP_PREFIX
export HADOOP_COMMON_HOME=$HADOOP_PREFIX
export HADOOP_HDFS_HOME=$HADOOP_PREFIX
export YARN_HOME=$HADOOP_PREFIX
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_PREFIX/lib/native
export PATH=$PATH:$HADOOP_PREFIX/sbin:$HADOOP_PREFIX/bin

Leave a comment

Your email address will not be published. Required fields are marked *