Of course! Here is a comprehensive, step-by-step guide on how to install Apache Hive on a Red Hat Enterprise Linux (RHEL) system.
This guide is designed for a single-node setup, which is perfect for learning, development, and testing. It assumes you are using a recent version of RHEL (like 8 or 9).
Core Concepts
Before we begin, understand the key components involved:
- Java: Hive and Hadoop are Java-based applications.
- Hadoop (HDFS & YARN): Hive runs on top of Hadoop. It uses HDFS for distributed storage and YARN for resource management. A working Hadoop installation is the most critical prerequisite.
- Metastore Database: Hive stores its metadata (table definitions, schemas, partitions, etc.) in a relational database. We'll cover two options:
- Embedded Derby: Very simple, good for a quick test, but only allows one user session at a time.
- PostgreSQL: A robust, production-grade database. This is the recommended approach.
- Apache Hive: The data warehousing software itself.
Prerequisites
- A running RHEL 8/9 system.
sudo or root access.
- A working, single-node Hadoop installation (HDFS and YARN services must be running).
- An internet connection to download software.
Let's begin the installation.
Step 1: System Setup and Prerequisites
1. Create a Dedicated User (Recommended)
It's good practice to run Hadoop and Hive under a dedicated user. If you haven't already done this for your Hadoop setup, do it now.
# Create the user
sudo useradd hadoop
sudo passwd hadoop
# Give the hadoop user sudo privileges (optional, but helpful)
sudo usermod -aG wheel hadoop
# Switch to the new user
su - hadoop
From this point on, all commands should be run as the hadoop user unless specified with sudo.
2. Install Java and wget
Hive requires Java. Hadoop 3.x typically works well with Java 8 or 11.
# Install wget to download files and Java 8
sudo dnf install wget java-1.8.0-openjdk-devel -y
# Verify the installation
java -version
3. Verify Hadoop Installation
This is the most important check. Ensure your Hadoop daemons are running.
# The jps command should show NameNode, DataNode, ResourceManager, etc.
jps
You should see output similar to this:
12345 NameNode
12367 DataNode
12589 SecondaryNameNode
12890 ResourceManager
13012 NodeManager
14567 Jps
If these services aren't running, you must start Hadoop first:
# Navigate to your hadoop sbin directory and start all services
start-all.sh
Step 2: Download and Extract Apache Hive
-
Go to the official Apache Hive Downloads page to find the latest stable version. We'll use version 3.1.3 as a stable example.
-
Download the binary tarball using wget.
# Download Apache Hive 3.1.3
wget https://dlcdn.apache.org/hive/hive-3.1.3/apache-hive-3.1.3-bin.tar.gz
- Extract the archive and move it to a standard location like
/usr/local/hive.
# Extract the file
tar -xzf apache-hive-3.1.3-bin.tar.gz
# Move and rename the directory for simplicity
sudo mv apache-hive-3.1.3-bin /usr/local/hive
# Change ownership of the directory to the hadoop user
sudo chown -R hadoop:hadoop /usr/local/hive
Step 3: Configure Environment Variables
Edit the .bashrc file for your hadoop user to set the HIVE_HOME and add Hive's bin directory to your PATH.
# Open the .bashrc file
nano ~/.bashrc
Add the following lines at the end of the file. Make sure your HADOOP_HOME is already set correctly from your Hadoop installation.
# HADOOP
export HADOOP_HOME=/usr/local/hadoop # <-- IMPORTANT: Change this to your actual Hadoop path
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
# HIVE
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
Save the file (Ctrl+X, then Y, then Enter) and apply the changes:
source ~/.bashrc
Step 4: Configure Hadoop for Hive
Hive needs to be able to impersonate other users to access HDFS. You need to add proxy user settings to your Hadoop core-site.xml file.
- Edit
core-site.xml:
nano $HADOOP_HOME/etc/hadoop/core-site.xml
- Add the following properties inside the
<configuration> tags. The user hadoop is the user running the HiveServer2 process.
<property>
<name>hadoop.proxyuser.hadoop.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.hadoop.groups</name>
<value>*</value>
</property>
- Restart Hadoop for these changes to take effect.
stop-all.sh
start-all.sh
Step 5: Configure Apache Hive
This is the core configuration step. We'll create the necessary HDFS directories and then configure Hive to use them and connect to a metastore.
1. Create HDFS Directories for Hive
# Create the warehouse directory where Hive tables will be stored
hdfs dfs -mkdir -p /user/hive/warehouse
# Create a temporary directory for Hive's intermediate data
hdfs dfs -mkdir /tmp
# Grant permissions to all users (for a simple dev setup)
hdfs dfs -chmod g+w /user/hive/warehouse
hdfs dfs -chmod g+w /tmp
2. Create Hive Configuration Files
Navigate to Hive's configuration directory.
cd $HIVE_HOME/conf
Create hive-env.sh from the template:
cp hive-env.sh.template hive-env.sh
Now, edit hive-env.sh and tell Hive where to find Hadoop.
nano hive-env.sh
Add the following line to the file:
export HADOOP_HOME=/usr/local/hadoop # <-- Change this to your actual Hadoop path
3. Create hive-site.xml and Configure the Metastore
This is where you choose your metastore database.
Option A: Using PostgreSQL (Recommended)
This is the robust, production-ready choice.
a. Install and Configure PostgreSQL
# Install the PostgreSQL server and contrib packages
sudo dnf install postgresql-server postgresql-contrib -y
# Initialize the database
sudo postgresql-setup --initdb
# Start and enable the PostgreSQL service
sudo systemctl start postgresql
sudo systemctl enable postgresql
b. Create a Hive User and Database in PostgreSQL
# Switch to the postgres user and open the psql shell
sudo -u postgres psql
Inside the psql shell, run these commands:
-- Create a user for Hive
CREATE USER hiveuser WITH PASSWORD 'hivepassword';
-- Create a database for the metastore
CREATE DATABASE metastore;
-- Grant privileges to the user on the database
GRANT ALL PRIVILEGES ON DATABASE metastore TO hiveuser;
-- Exit the psql shell
\q
c. Download the PostgreSQL JDBC Driver
Hive needs a JDBC driver to connect to PostgreSQL.
# Download the driver (check for the latest version if needed)
wget https://jdbc.postgresql.org/download/postgresql-42.5.1.jar
# Move the driver to Hive's lib directory
sudo mv postgresql-42.5.1.jar $HIVE_HOME/lib/
d. Configure hive-site.xml for PostgreSQL
Create and edit the hive-site.xml file:
cd $HIVE_HOME/conf
nano hive-site.xml
Paste the following configuration. This is a minimal but functional configuration.
<configuration>
<!-- JDBC Connection settings for PostgreSQL Metastore -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:postgresql://localhost/metastore</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.postgresql.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveuser</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hivepassword</value>
<description>Password to use against metastore database</description>
</property>
<!-- HDFS Directories -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>Location of the Hive warehouse directory</description>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>/tmp</value>
<description>HDFS scratch dir for Hive jobs</description>
</property>
</configuration>
Option B: Using Embedded Derby (Simple Test Only)
Use this only if you want a quick test. It's not suitable for multi-user access.
Create and edit the hive-site.xml file:
cd $HIVE_HOME/conf
nano hive-site.xml
Paste this minimal configuration:
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=metastore_db;create=true</value>
<description>JDBC connect string for a Derby metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>Location of the Hive warehouse directory</description>
</property>
</configuration>
Step 6: Initialize the Hive Metastore Schema
This is a one-time step that creates all the necessary tables in your metastore database (PostgreSQL or Derby).
# Navigate to hive's bin directory
cd $HIVE_HOME/bin
# Initialize the schema. Use 'postgres' for PostgreSQL, 'derby' for Derby.
schematool -dbType postgres -initSchema
You should see log messages, ending with: Schema initialization complete. If you see errors, check your hive-site.xml connection settings.
Step 7: Start and Verify Hive
1. Start HiveServer2
HiveServer2 is the service that allows clients (like DBeaver, Tableau, or the Beeline CLI) to connect to Hive. It's best to run it as a background service.
# Start HiveServer2 in the background
nohup hive --service hiveserver2 &
You can check its status with jps. You should now see a RunJar process, which is HiveServer2.
2. Connect with Beeline CLI
Beeline is the modern, recommended command-line interface for Hive.
# Connect to HiveServer2 using Beeline
beeline -u jdbc:hive2://localhost:10000
When prompted for a username and password, enter your Linux username (hadoop) and any password (it's not validated in this simple setup).
You should see a successful connection and a 0: jdbc:hive2://localhost:10000> prompt.
3. Run Some Test Queries
Let's verify everything works end-to-end.
-- See the default database
SHOW DATABASES;
-- Create a new table
CREATE TABLE test_table (id INT, name STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';
-- Show the tables in the current database
SHOW TABLES;
-- Describe the table to see its schema
DESCRIBE test_table;
-- Load some data into the table (create a sample file first)
-- Exit beeline with !quit and create the file
In your regular shell (not Beeline), create a sample CSV file:
echo "1,first_row" > /home/hadoop/sample_data.csv
echo "2,second_row" >> /home/hadoop/sample_data.csv
Now go back into Beeline and load the data:
-- Load data from the local file into the Hive table
LOAD DATA LOCAL INPATH '/home/hadoop/sample_data.csv' INTO TABLE test_table;
-- Query the data to see if it was loaded correctly
SELECT * FROM test_table;
You should see:
+-----------------+--------------------+
| test_table.id | test_table.name |
+-----------------+--------------------+
| 1 | first_row |
| 2 | second_row |
+-----------------+--------------------+
Congratulations! You have successfully installed and configured Apache Hive on your Red Hat system.