There is a new version of this tutorial available for CentOS 8.

How to Install Apache Cassandra on CentOS 7

This tutorial exists for these OS versions

On this page

  1. Step 1 - Install JAVA
  2. Step 2 - Installing Cassandra
  3. Conclusion

Apache Cassandra is a free and open source distributed NoSQL database management system. It is used to store large data in decentralized highly available clusters. Data is distributed across many servers providing high availability and no single point of failure. NoSQL database servers stores data in other methods than the traditional tabular methods used by RDBMS softwares such as MySQL, PostgreSQL.

In this tutorial, we will be installing Apache Cassandra on CentOS 7 server.

Step 1 - Install JAVA

Before installing any package it is recommended that you update the packages and repository using the following command.

yum -y update

Once your system is updated, we will install the latest version of Oracle Java into the server. Run the following command to download the RPM package.

wget --no-cookies --no-check-certificate --header "Cookie:oraclelicense=accept-securebackup-cookie" ""

If you do not have wget installed, you can run the yum -y install wget to install wget. Now install the downloaded RPM using the following command.

yum -y localinstall jdk-8u131-linux-x64.rpm

You can now check the Java version using the following command.

java -version

You will get the following output.

[root@liptan-pc ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

You will also need to check if JAVA_HOME environment variable is set. Run the following command for same.


If you get a null or blank output, you will need to manually set the JAVA_HOME variable. Edit the .bash_profile file using your favourite editor. In this tutorial, we will use nano editor. Run the following command to edit .bash_profile using nano.

nano ~/.bash_profile

Now add the following lines at the at the end of the file.

export JAVA_HOME=/usr/java/jdk1.8.0_131/
export JRE_HOME=/usr/java/jdk1.8.0_131/jre

Now source the file using the following command.

source ~/.bash_profile

Now you can run the echo $JAVA_HOME command again to check if the environment variable is set or not.

[root@liptan-pc ~]# echo $JAVA_HOME 

Step 2 - Installing Cassandra

Now add Apache Cassandra repository into your repository list by creating a new repository file.

nano /etc/yum.repos.d/cassandra.repo

Now add the following content into the file.

name=Apache Cassandra

You can now install Apache Cassandra by running the following command.

yum -y install cassandra

Reload your system daemons by running:

systemctl daemon-reload

You can now start Cassandra by typing;

systemctl start cassandra

To enable Cassandra to automatically start at boot time, run:

systemctl enable cassandra

You can verify that Cassandra is running by typing the following command.

nodetool status

You should see similar output if Cassandra is running.

[root@ip-172-31-7-136 ~]# nodetool status
Datacenter: datacenter1
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns (effective)  Host ID                               Rack
UN  136.29 KiB  256          100.0%            b3d26649-9e10-4bee-9b3c-8e81c4394b2e  rack1

Instead of the output shown above, if you get something similar to the output below, then you will need to configure cassandra environment configuration file.

nodetool: Failed to connect to '' - ConnectException: 'Connection refused (Connection refused)'.

Open the configuration file using following command.

nano /etc/cassandra/default.conf/

Now find the following line in configuration.

# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>"

Uncomment the line and change its value form <public_name> to the localhost IP address

The configuration should look like shown below.

JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname="

Save the file and exit from editor, restart Apache Cassandra by running the following command.

systemctl restart cassandra

You should have the desired output while running the nodetool command.

Cassandra comes with a powerful command line shell cqlsh to run query on Cluster. Query is written in CQL or Cassandra Query language. To access CQL shell, run the following command.


You will see following output.

[root@liptan-pc ~]# cqlsh
Connected to Test Cluster at
[cqlsh 5.0.1 | Cassandra 3.11.0 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.


Apache Cassandra is now installed on your server. You can learn more about Cassandra by going to Cassandra website.

Share this page:

0 Comment(s)