How to Install Apache Cassandra on Ubuntu and Other Linux

Apache Cassandra is a free and open-source NoSQL database management system drawn to manipulate large amounts of information across many servers, providing high availability with no single point of failure.

I am not going into the details of NoSQL database. I am going to so you how you can install Apache Cassandra on Ubuntu based Linux distributions.

Please note that it is more for practicing

Installing Apache Cassandra on Linux

There are multiple ways you can install Cassandra on Ubuntu and other Linux distributions:

  • Install it using the official deb repositories from Apache: suitable and recommended for Debian and Ubuntu-based distributions. Gets automatic update if a newer version is available.
  • Install it using Docker: works for all Linux distributions
  • Install it from the tarball: works with all Linux but it won’t get updated to a new version automatically.

This is merely for practicing and experiencing Apache Cassandra. If you are going to use it in a project with other services, you’ll have to follow the complete configuration and setting guide of that service.

I’ll show the first two methods.

Method 1: Install Cassandra on Ubuntu and Debian using the official repository

Before you could install and use Cassandra, you need to have Python and Java installed on your system. You may have to install Java on Ubuntu however Python usually comes preinstalled.

You can check the prerequisite with the next line:

java -version ; python --version

All prerequisites well installed? That’s good. Let’s install Cassandra. The method here is the same as adding any external repository in Ubuntu.

First, add the Apache Cassandra repository to your sources list. This one adds the latest major version (at the time of writing it) 4.0 series.

echo "deb http://www.apache.org/dist/cassandra/debian 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
installing the debian packages step 1
Add Apache Cassandra repository

Now, download and add the Apache Cassandra repository keys to the list of trusted keys on the server. This way, your system will trust the packages coming from the repository you added in the previous step.

You should make sure that apt can be used over https.

sudo apt install apt-transport-https

And then add the key:

wget https://www.apache.org/dist/cassandra/KEYS && sudo apt-key add KEYS
installing the debian packages step 2
Add Apache Cassandra repository key

You have added the repository. Update the local cache so that your system is aware of the presence of this new repository.

sudo apt update

And lastly, install Cassandra with the following command:

sudo apt install cassandra
installing the debian packages step 3
Installing Apache Cassandra on Ubuntu

Once the installation finishes, Cassandra service starts running automatically. You could still verify it if you want:

sudo systemctl status cassandra.service
verify cassandra
Check if Cassandra is running

You can connect to the database by typing cqlsh. Type exit to exit this shell.

installing the debian packages step 4
Entering cqlsh

This was the very basic and default set up. You’ll probably need to configure it based on your requirement. Please the official document for the configuration part.

Method 2: Install Apache Cassandra using Docker

This method will work with any Linux distribution as long as you are going to use it in a Docker setup.

Of course, you need to have Docker installed on your system for this method. That’s a prerequisite for this method and I let you handle that.

If you have Docker, use the command below to pull the docker image of Apache Cassandra.

sudo docker pull cassandra:latest
using docker images step 2
Pulling Apache Cassandra docker image

Once that’s done, you can start Cassandra with the docker run command like this:

sudo docker run --name cass_cluster cassandra:latest
using docker images step 3
Running Cassandra in a container

Note: the --name option will be the name of the Cassandra cluster created.

To interact with the Cassandra node started before, you need to initialize the CQL shell, and you can do it with the Docker exec command like this:

sudo docker exec -it cass_cluster cqlsh
using docker images step 4
Access the cqlsh running in Docker.

Congrats! Now you know at least two different ways to install Apache Cassandra in your system.

Please keep in mind that this post is only an introduction. If you are interested in knowing more about Apache Cassandra, read the documentation where you can find out more about this amazing NoSQL database management system. Enjoy it and share this post if it was interesting and helpful for you! See you in the next one.

About the author
Marco Carmona

Marco Carmona

My name is Marco Antonio Carmona, I'm a physics and data science student, a great and passionate reader, and randomly, my favorite hobby is writing about what I learn day by day.

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.