How to install Cassandra on Ubuntu 22.04

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Apache Cassandra is a distributed, wide-column store, NoSQL database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. We already have some articles of Cassandra installation on CentOS and Debian; now I will show you how to install Cassandra on the (so far)latest Ubuntu LTS 22.04.

1. Add the Cassandra repository

First we need to add the Cassandra repository and key. According to the installation instructions available on the Cassandra website, we need to run the following commands:

$ sudo -i
# echo "deb http://downloads.apache.org/cassandra/debian 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
deb http://downloads.apache.org/dist/cassandra/debian 40x main
# curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
# apt-get update
how to install cassandra. Adding the repository
this is not good
I should have read the previous warning…

If you just copy&paste the commands without paying attention this would work, because apt-key is deprecated. The manpage have the solution, you can read it with:

man 8 apt-key

Or you can just copy the following command:

# curl https://downloads.apache.org/cassandra/KEYS | tee /etc/apt/trusted.gpg.d/cassandra.asc
# apt-get update

and continue with the next section.

2. Install Cassandra and dependencies

Repository added, now we can continue installing Cassandra and the prerequisites. Other tutorials I saw instruct you to install java first, but that’s what apt-get and software repositories are for:

# apt-get install cassandra

This will download and install the package cassandra and all the packages needed by Cassandra, a JRE for example.

about to install cassandra

Now just wait until the download and installation ends…

how to install cassandra. Download and installation just finished
..Cassandra installed!, let’s continue with the last section

3. Testing Cassandra

Just like that, Apache Cassandra is installed and running. But this time I’ve payed attention to the screen messages, so I’ve checked if the service is actually running with:

# service cassandra status
cassandra.service is running

One last check: I will use the CQL shell to create a keyspace (database) and populate with some data:

# cqlsh
cqlsh> CREATE KEYSPACE IF NOT EXISTS gonz  WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : '1' };
cqlsh> CREATE TABLE gonz.tabla (
   ... clave int PRIMARY KEY,
   ... valor text );
cqlsh> INSERT INTO gonz.tabla (clave, valor)
   ... VALUES (1, 'value1');
cqlsh> SELECT * FROM gonz.tabla ;

(if you don’t know a word in spanish, tabla is for table, clave for key and valor for value)

how to install cassandra. Testing the database
Creating a keyspace and table. I still can’t find the error at my 2nd try on creating the keyspace…

4. Profit

😉

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Gonzalo Rivero
Gonzalo Rivero
I am Gonzalo, I live in Salta, a city located in the NW of Argentina. I play the guitar and a little harmonica. I also like to bike.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook