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
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.
Now just wait until the download and installation ends…
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
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)
4. Profit
😉