Apache Cassandra is a free open source NoSQL database with no single point of failure. It provides linear scalability and high availability without sacrificing performance. Apache Cassandra is used by many companies that have large active datasets including Reddit, NetFlix, Instagram, and Github.
This article will walk you through installing Apache Cassandra on Ubuntu 20.04.
Installing Apache Cassandra on Ubuntu is very easy. We will install Java, enable the Apache Cassandra repository, import the repository’s GPG key, and install the Apache Cassandra server.
At the time of this writing, the latest version of Apache Cassandra 3.11 required OpenJDK 8 to be installed on the system.
Run the following command as root or sudo to install OpenJDK:
sudo apt update sudo apt install openjdk-8-jdk
Verify your Java installation by printing the Java version:
The result should look something like this:
openjdk version "1.8.0_265" OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01) OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
Installing Apache Cassandra
Install the dependencies required to add a new repository over HTTPS:
sudo apt install apt-transport-https
Import the repository GPG key and add the Cassandra repository to the system:
wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
After enabling the repository, update the package list and install the latest version of Apache Cassandra:
sudo apt update sudo apt install cassandra
The Apache Cassandra service will automatically start after the installation process is complete. You can check this 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 70 KiB 256 100.0% 2eaab399-be32-49c8-80d1-780dcbab694f rack1
That’s all. At this point, you have Apache Cassandra installed on your Ubuntu server.
Apache Cassandra setup
Apache Cassandra data is stored in the / var / lib / cassandra directory, which contains the / etc / cassandra configuration files, and Java startup options can be configured in the / etc / default / cassandra file.
By default, Cassandra is configured to only listen on localhost. If the client connecting to the database is also running on the same host, then you don’t need to change the default config file.
To interact with Cassandra through CQL (Cassandra Query Language), you can use a command line tool named cqlsh that comes with the Cassandra package.
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.11.7 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh>
Renaming Apache Cassandra cluster
The default Cassandra cluster is named Test Cluster. If you want to change the name of the cluster, follow these steps:
- Login to Cassandra CQL terminal using cqlsh:
Run the following command to change the cluster name to “AndreyEx Cluster”:
UPDATE system.local SET cluster_name="AndreyEx Cluster" WHERE KEY = 'local';
Change “AndreyEx Cluster” to your desired name.
Then enter exit to exit the console.
- Open the cassandra.yaml configuration file and enter a new cluster name. /etc/cassandra/cassandra.yaml
cluster_name: 'AndreyEx Cluster'
Save and close the file.
- Clear the system cache:
nodetool flush system
- Restart the Cassandra service:
sudo systemctl restart cassandra
We showed you how to install Apache Cassandra on Ubuntu 20.04. You can now visit the official Apache Cassandra documentation page and learn how to get started with Cassandra.
If you run into an issue or want to provide feedback, please leave a comment below.