How to Install Apache Cassandra on Ubuntu 18.04
4 min read
Apache Cassandra is a free and open source NoSQL database with no single point of failure. It provides linear scalability and high availability without compromising performance. Apache Cassandra is used by a number of organizations including Apple, NetFlix, eBay, and Easou.
In this tutorial, we will show you how to install Apache Cassandra on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Linux Mint, Kubuntu and Elementary OS.
In order to be able to install packages on your Ubuntu system, you must be logged in as a user with sudo privileges.
Installing Apache Cassandra
The easiest way to install Apache Cassandra on Ubuntu 18.04 is by installing the deb package from the official Apache Cassandra repository.
At the time of writing this article, the latest version of Apache Cassandra is
3.11 and requires OpenJDK 8 to be installed on the system.
Java installation is pretty simple, start by updating the package index:
sudo apt update
Install the OpenJDK package by typing:
sudo apt install openjdk-8-jdk
Verify the Java installation by running the following command which will print the Java version:
The output should look something like this:
openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Install the apt-transport-https package that necessary to access a repository over HTTPS:
sudo apt install apt-transport-https
The next step is to add the Apache Cassandra repository.
Import the repository’s GPG using the following
wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
The command above should output
OK which means that the key has been successfully imported and packages from this repository will be considered trusted.
Next, add the Cassandra repository to the system by issuing:
sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
Once the repository is enabled, update the
apt package list and install the latest version of Apache Cassandra by typing:
sudo apt update sudo apt install cassandra
Cassandra service will automatically start after the installation process is complete. You can verify that Cassandra is running by typing:
You should see something similar to this:
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 114.55 KiB 256 100.0% d8c27e24-ea26-4eeb-883c-5986218ba3ca rack1
Congratulations, at this point you have Apache Cassandra installed on your Ubuntu server.
Configuring Apache Cassandra
Apache Cassandra data is stored in the
/var/lib/cassandra directory, configuration files are located in
/etc/cassandra and Java start-up options can be configured in the
By default, Cassandra is configured to listen on localhost only. If the client connecting to the database is also running on the same host you don’t need to change the default configuration file.
To interact with Cassandra through CQL (the Cassandra Query Language) you can use a command line utility named
cqlsh that is shipped with the Cassandra package.
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh>
Renaming Apache Cassandra Cluster
By default, the Cassandra cluster is named “Test Cluster”. If you want to change it follow the steps bellow:
Login to the Cassandra CQL terminal with
Run the following command to change the cluster name to “Linuxize Cluster”:
UPDATE system.local SET cluster_name = 'Linuxize Cluster' WHERE KEY = 'local';
Change “Linuxize Cluster” with your desired name. Once done type
exitto exit the console.
cassandra.yamlconfiguration file and enter your new cluster name./etc/cassandra/cassandra.yaml
cluster_name: 'Linuxize Cluster'
Run the following command to clear the system cache:
nodetool flush system
Finally restart the Cassandra service:
sudo systemctl restart cassandra
You have successfully installed Apache Cassandra on your Ubuntu 18.04. You can now visit the official Apache Cassandra Documentation page and learn how to get started with Cassandra.
If you hit a problem or have feedback, leave a comment below.