S1. Update the System
Before installing Hadoop, update your system packages.
sudo apt update
sudo apt upgrade -y
S2. Install and Configure Java 21
Apache Hadoop is written in Java and requires a compatible Java Runtime Environment (JRE) and Java Development Kit (JDK).
This guide uses OpenJDK 21 (LTS).
Java Compatibility
| Installed Java Version | Action |
|---|---|
| Java 21 | Continue with the installation |
| Java 17 | May work with some Hadoop versions, but this guide uses Java 21 |
| Java 22–25 | Install Java 21 and switch to it |
| Java Not Installed | Install OpenJDK 21 |
S2.1 Check if Java is Installed
java -version
javac -version
If Java is NOT Installed
Install OpenJDK 21.
sudo apt update
sudo apt install openjdk-21-jdk -y
Verify the installation.
java -version
javac -version
If Java is Already Installed
Check the installed version.
java -version
javac -version
Compare the output with the compatibility table above.
If Java 21 is already active, continue to the next step.
Otherwise, switch to Java 21.
S2.2 List All Installed Java Versions
update-java-alternatives -l
Example:
java-1.17.0-openjdk-amd64
java-1.21.0-openjdk-amd64
S2.3 Switch to Java 21
sudo update-alternatives --config java
sudo update-alternatives --config javac
Select the option corresponding to Java 21.
S2.4 Verify the Active Java Version
java -version
javac -version
Both commands should display Java 21.
S2.5 Find the Correct JAVA_HOME
Different Linux distributions may install Java in different directories.
Instead of copying someone else's path, determine it automatically.
readlink -f $(which java)
Example:
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
Therefore,
JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
Note: Never blindly copy the
JAVA_HOMEpath from a tutorial. Always determine it using the command above.
S3. Download Apache Hadoop 3.4.2
Move to the directory where you want to download Hadoop.
cd ~/Downloads
Download Hadoop from the official Apache Archive.
wget https://archive.apache.org/dist/hadoop/common/hadoop-3.4.2/hadoop-3.4.2.tar.gz
Verify the download.
ls -lh hadoop-3.4.2.tar.gz
Expected output:
-rw-r--r-- 1 user user 734M hadoop-3.4.2.tar.gz
S4. Extract and Install Hadoop
After downloading the Hadoop archive, the next step is to extract it and install Hadoop on your system.
In this guide, Hadoop will be installed under /opt/hadoop, which is the standard location for optional third-party software on Linux.
S4.1 Extract the Archive
Move to the directory where the archive was downloaded.
cd ~/Downloads
Extract the archive.
tar -xvzf hadoop-3.4.2.tar.gz
This will create a directory named:
hadoop-3.4.2
Verify the extraction.
ls
Expected output:
hadoop-3.4.2
hadoop-3.4.2.tar.gz
S4.2 Move Hadoop to /opt
Move the extracted directory to /opt.
sudo mv hadoop-3.4.2 /opt/hadoop
S4.3 Verify the Installation Directory
Check that Hadoop has been moved successfully.
ls /opt
Expected output:
hadoop
View the contents of the Hadoop directory.
ls /opt/hadoop
Expected output:
bin
etc
include
lib
libexec
licenses
sbin
share
NOTICE.txt
README.txt
...
S4.4 Change Ownership
By default, the Hadoop directory is owned by the root user because it was moved using sudo.
Change the ownership so your user can modify the configuration files without requiring root privileges every time.
sudo chown -R $USER:$USER /opt/hadoop
Verify the ownership.
ls -ld /opt/hadoop
Example output:
drwxr-xr-x <username> <username> ...
S4.5 Verify the Hadoop Version
Run the Hadoop executable directly.
/opt/hadoop/bin/hadoop version
Expected output:
Hadoop 3.4.2
Source code repository ...
Compiled by ...
At this point, Hadoop has been successfully installed on the system. However, it cannot yet be executed from any directory because its binaries have not been added to the system's PATH.
Note: We are intentionally using the full path (
/opt/hadoop/bin/hadoop) for now. In the next section, we will configure environment variables so that thehadoop,hdfs, andyarncommands can be run from anywhere in the terminal.
S5. Configure Environment Variables
After installing Hadoop, we need to configure environment variables. These variables tell the operating system where Hadoop and Java are installed, allowing Hadoop commands to be executed from any directory.
The main environment variables are:
| Variable | Purpose |
|---|---|
JAVA_HOME |
Points to the Java installation directory |
HADOOP_HOME |
Points to the Hadoop installation directory |
HADOOP_CONF_DIR |
Specifies the Hadoop configuration directory |
PATH |
Allows Hadoop commands to be executed from anywhere |
S5.1 Check Your Default Shell
Before editing your shell configuration, determine which shell you are using.
echo $SHELL
Possible outputs:
/bin/bash
or
/bin/zsh
S5.2 Open the Shell Configuration File
If you are using Bash
nano ~/.bashrc
If you are using Zsh
nano ~/.zshrc
S5.3 Add the Hadoop Environment Variables
Append the following lines to the end of the file.
# Java
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
# Hadoop
export HADOOP_HOME=/opt/hadoop
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
# Hadoop Components
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
# Native Libraries
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
# PATH
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
Why use $(dirname $(dirname $(readlink -f $(which java))))?
Instead of hardcoding the Java installation path, this command automatically determines the correct JAVA_HOME directory. This makes the guide more portable across different Linux distributions and Java installation methods.
S5.4 Save the File
For Nano:
- Press Ctrl + O
- Press Enter
- Press Ctrl + X
S5.5 Reload the Configuration
Bash
source ~/.bashrc
Zsh
source ~/.zshrc
S5.6 Verify the Environment Variables
Check that Hadoop is configured correctly.
echo $JAVA_HOME
Example:
/usr/lib/jvm/java-21-openjdk-amd64
Check the Hadoop installation directory.
echo $HADOOP_HOME
Expected output:
/opt/hadoop
Check the configuration directory.
echo $HADOOP_CONF_DIR
Expected output:
/opt/hadoop/etc/hadoop
S5.7 Verify Hadoop Commands
You should now be able to run Hadoop commands from any directory.
Check the Hadoop version.
hadoop version
Check the HDFS version.
hdfs version
Check the YARN version.
yarn version
Each command should report Hadoop 3.4.2.
Note: If any of these commands return
command not found, ensure that the shell configuration file has been reloaded using thesourcecommand or open a new terminal session.
S6. Configure Passwordless SSH
Apache Hadoop uses SSH to start and stop its daemons. Even in a single-node cluster, passwordless SSH is required for Hadoop scripts such as start-dfs.sh and start-yarn.sh.
S6.1 Check if OpenSSH is Installed
Run the following command:
ssh -V
If OpenSSH is installed, you will see output similar to:
OpenSSH_10.x
If the command is not found, install the OpenSSH server.
sudo apt update
sudo apt install openssh-server -y
S6.2 Start and Enable the SSH Service
Start the SSH service.
sudo systemctl start ssh
Enable it to start automatically on boot.
sudo systemctl enable ssh
Check the service status.
sudo systemctl status ssh
The status should show active (running).
Exit the status screen by pressing Q.
S6.3 Generate an SSH Key Pair
If you do not already have an SSH key, generate one.
ssh-keygen -t rsa -b 4096
When prompted for the file location, simply press Enter to accept the default location.
When prompted for a passphrase, press Enter twice to leave it empty.
Example:
Enter file in which to save the key:
/home/<username>/.ssh/id_rsa
S6.4 Enable Passwordless SSH
Append the public key to the authorized keys file.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Set the correct permissions.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
S6.5 Test the SSH Connection
Run:
ssh localhost
The first time you connect, you may see:
Are you sure you want to continue connecting (yes/no)?
Type:
yes
If everything is configured correctly, you will be logged into your own machine without entering a password.
Exit the SSH session.
exit
Why is Passwordless SSH Required?
Hadoop's management scripts use SSH to launch and stop services such as the NameNode, DataNode, ResourceManager, and NodeManager. Without passwordless SSH, these scripts will repeatedly prompt for a password, making automated startup impossible.
S7. Create Hadoop Data Directories
Hadoop requires a few directories to store its metadata and temporary files. These directories are referenced by the Hadoop configuration files.
Create the required directories by running the following commands:
mkdir -p ~/hadoopdata/namenode
mkdir -p ~/hadoopdata/datanode
mkdir -p ~/hadooptmp
You can verify that the directories were created successfully using:
tree -L 2 ~
If the tree command is not installed, install it using:
sudo apt install tree -y
Expected output:
/home/<username>
├── hadoopdata
│ ├── datanode
│ └── namenode
└── hadooptmp
Note: The directory names must match the paths specified in the Hadoop configuration files (
core-site.xmlandhdfs-site.xml). If you changed those paths, create the directories accordingly.
S8. Install the Hadoop Configuration Files
Instead of manually editing multiple Hadoop configuration files, use the installation script provided in the GitHub repository. The script downloads and installs all the required configuration files automatically.
Download the installation script.
wget https://raw.githubusercontent.com/itsadityapidurkar/hadoop-installation-guide/main/linux/install-configs.sh
Make the script executable.
chmod +x install-configs.sh
Run the script.
./install-configs.sh
The script downloads and installs the following configuration files:
core-site.xmlhdfs-site.xmlmapred-site.xmlyarn-site.xmlworkers
These files are automatically copied to:
/opt/hadoop/etc/hadoop
If the script completes successfully, you should see:
========================================
Apache Hadoop Configuration Installer
========================================
[+] Downloading configuration files...
[✓] Download complete.
[+] Installing configuration files...
[✓] Configuration files installed successfully!
Installed to:
/opt/hadoop/etc/hadoop
Note: The provided configuration files are intended for a Single Node Hadoop 3.4.2 installation. If you modified the directory paths while following this guide, update the configuration files accordingly before installing them.
S9. Configure hadoop-env.sh
The hadoop-env.sh file is used to configure environment variables required by Hadoop. The only change required for this guide is to set the JAVA_HOME variable.
Open the file using a text editor.
nano /opt/hadoop/etc/hadoop/hadoop-env.sh
Search for the line containing:
export JAVA_HOME=
or
# export JAVA_HOME=
Replace it with:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
Save the file and exit.
For Nano:
- Press Ctrl + O
- Press Enter to save the file.
- Press Ctrl + X to exit.
You can verify that the JAVA_HOME path is detected correctly by running:
echo $(dirname $(dirname $(readlink -f $(which java))))
Example output:
/usr/lib/jvm/java-21-openjdk-amd64
Note: This command automatically detects the Java installation directory, making the configuration portable across different Linux distributions and Java installation paths.
S10. Format the NameNode
Before starting Hadoop for the first time, the NameNode must be formatted. This initializes the Hadoop Distributed File System (HDFS) and creates the required metadata.
Run the following command:
hdfs namenode -format
During the formatting process, you may be prompted with the following message if the NameNode directory already contains data:
Re-format filesystem in Storage Directory root=... ? (Y or N)
Type:
Y
and press Enter.
If the formatting is successful, the last few lines of the output should look similar to:
...
INFO common.Storage: Storage directory ... has been successfully formatted.
INFO namenode.FSImageFormatProtobuf: Saving image file ...
INFO namenode.NameNode: SHUTDOWN_MSG:
Important: Formatting the NameNode permanently removes all existing HDFS metadata and data stored in the configured NameNode and DataNode directories. This command should only be executed during the initial setup or when you intentionally want to reset the Hadoop cluster. Do not run this command every time you start Hadoop.
S11. Start HDFS
Now that the NameNode has been formatted, you can start the Hadoop Distributed File System (HDFS).
Run the following command:
start-dfs.sh
If HDFS starts successfully, you should see output similar to:
Starting namenodes on [localhost]
Starting datanodes
Starting secondary namenodes [<hostname>]
To verify that all HDFS daemons are running, execute:
jps
Expected output:
NameNode
DataNode
SecondaryNameNode
Jps
Note: The order of the processes may vary depending on your system.
You can also verify that the NameNode is running by opening the following URL in your web browser:
http://localhost:9870
If HDFS has started successfully, the NameNode web interface will be displayed, showing information about the cluster, storage usage, live DataNodes, and the HDFS filesystem.
S12. Start YARN
After starting HDFS, the next step is to start YARN (Yet Another Resource Negotiator), which is responsible for resource management and job scheduling in the Hadoop cluster.
Run the following command:
start-yarn.sh
If YARN starts successfully, you should see output similar to:
Starting resourcemanager
Starting nodemanagers
To verify that the YARN daemons are running, execute:
jps
Expected output:
NameNode
DataNode
SecondaryNameNode
ResourceManager
NodeManager
Jps
Note: The order of the processes may vary depending on your system.
You can also verify that YARN is running by opening the following URL in your web browser:
http://localhost:8088
If YARN has started successfully, the ResourceManager web interface will open, displaying information about the cluster, available resources, running applications, and node status.
At this point, your Hadoop Single Node Cluster is up and running.
S13. Verify the Hadoop Installation
After starting both HDFS and YARN, verify that all Hadoop services are running correctly.
Check the running Hadoop daemons.
jps
Expected output:
NameNode
DataNode
SecondaryNameNode
ResourceManager
NodeManager
Jps
View the HDFS cluster report.
hdfs dfsadmin -report
If the cluster is running correctly, the report will display information about the configured capacity, remaining storage, live DataNodes, and other cluster details.
Next, open the NameNode Web UI in your browser.
http://localhost:9870
The NameNode dashboard should display information such as:
- Cluster Summary
- Live DataNodes
- Storage Information
- HDFS Overview
Then open the ResourceManager Web UI.
http://localhost:8088
The ResourceManager dashboard should display:
- Cluster Metrics
- Node Status
- Running Applications
- Available Resources
If all the above commands and web interfaces are accessible, your Hadoop Single Node Cluster has been installed and configured successfully.
Hadoop Web UI Port Quick-Reference
| Service | Web UI URL | Default Port | Description |
|---|---|---|---|
| HDFS NameNode | http://localhost:9870 |
9870 | File system status, capacity, browser directories |
| YARN ResourceManager | http://localhost:8088 |
8088 | Job executions, node resource allocation |
| HDFS DataNode | http://localhost:9864 |
9864 | Individual DataNode status & blocks |
S14. Shut Down the Hadoop Cluster
To stop the Hadoop daemons and release system resources safely, stop the YARN resource manager and HDFS services in order.
Run the following commands:
stop-yarn.sh
stop-dfs.sh
To verify that all Hadoop services have been stopped successfully, run:
jps
Expected output:
Jps
Only the Jps process itself should be running, confirming that HDFS and YARN have successfully shut down.
Top comments (0)