How To

Install Apache Cassandra on Ubuntu 18.04: NoSQL Setup Guide

Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with no single point of failure. It achieves this by distributing data across multiple nodes with no master node, so any node can handle any request. If one node goes down, other nodes continue serving traffic without interruption.

Cassandra is trusted at scale by organizations like Apple, Netflix, and eBay. It is a solid choice when you need a database that can grow horizontally and stay available under heavy load.

This guide shows you how to install Cassandra on Ubuntu 18.04, verify the installation, connect with the CQL shell, and rename the cluster. The same steps work on Ubuntu 16.04, Kubuntu, and Linux Mint.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install Cassandra on Ubuntu: Java, Repository, and Package Setup

Cassandra 3.11 requires OpenJDK 8. Install it first:

bashsudo apt updatesudo apt install openjdk-8-jdk

Verify with java -version. The output should show openjdk version "1.8.0_191" or similar.

Add the Cassandra repository. Install the HTTPS transport package so apt can reach the repository over HTTPS:

bashsudo apt install apt-transport-https

Import the Apache Cassandra GPG key:

bashwget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -

The command prints OK to confirm the key was imported successfully. Add the Cassandra 3.11 repository to your apt sources:

bashsudo sh -c 'echo "deb https://archive.apache.org/dist/cassandra/debian/ 311x main" &gt; /etc/apt/sources.list.d/cassandra.list'

Update the package list and install Cassandra:

bashsudo apt updatesudo apt install cassandra

The Cassandra service starts automatically after installation.

Verify the Installation and Connect with cqlsh

Check that Cassandra is running with the nodetool utility:

bashnodetool status

The output lists the cluster nodes and their status. A healthy node shows UN in the first column. The U means the node is Up and the N means its state is Normal. If you see 100.0% in the Owns column, the single node owns the full data range.

Key file locations. Cassandra stores its data in /var/lib/cassandra. Configuration files are in /etc/cassandra, and Java startup options live in /etc/default/cassandra. By default, Cassandra listens on localhost only, which is fine if your application runs on the same server.

Connect with cqlsh. Cassandra ships with cqlsh, a command-line interface for the Cassandra Query Language:

bashcqlsh

A successful connection shows the Cassandra version and the cluster name (Test Cluster by default), followed by the cqlsh> prompt. Type exit to leave the shell.

Configure Cassandra and Rename the Cluster

The default cluster name “Test Cluster” is fine for development but should be changed before using Cassandra in production. Renaming requires three steps.

Step 1. Open cqlsh and update the cluster name in the system table:

sqlUPDATE system.local SET cluster_name = 'YourClusterName' WHERE KEY = 'local';

Type exit to close the shell.

Step 2. Update the cluster name in the Cassandra configuration file /etc/cassandra/cassandra.yaml:

yamlcluster_name: 'YourClusterName'

Replace YourClusterName with the same name you used in Step 1. The names must match exactly.

Step 3. Clear the system cache so Cassandra reads the new name cleanly on restart:

bashnodetool flush system

Then restart the service:

bashsudo systemctl restart cassandra

Run nodetool status again to confirm the cluster is still showing UN after the restart.

Apache Cassandra is now installed and configured on your Ubuntu 18.04 server. Visit the Apache Cassandra documentation to learn how to create keyspaces, define tables, and query data with CQL. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 days ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

2 days ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

3 days ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

6 days ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

6 days ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

6 days ago