Apache Cassandra is a high availability NoSQL database used for storing and managing large amount of data. It provides distributed, wide-column store that allows you to easily scale data across multiple distributed servers. In this article, we will look at how to install Apache Cassandra in Ubuntu.
How to Install Apache Cassandra in Ubuntu
Here are the steps to install Apache Cassandra in Ubuntu. Please note, you need a user with root privileges for this installation.
1. Install Prerequisites
Open terminal and run the following commands to install prerequisites Java OpenJDK and api-transport-https packages.
$ sudo apt update $
sudo apt install openjdk-8-jdk -y$
sudo apt install apt-transport-https
Test if Java was installed properly with the following command.
$ java -version
Also read : How to Create Empty File in Linux
2. Add Apache Cassandra to Repository List
Run the following command to add Apache Cassandra to repository list.
sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 40x main" > /etc/apt/sources.list.d/cassandra.list'
We have used 40 in the above command because Apache Cassandra 4.0 was the last major version. Please update it as per your requirement. For example, use 39x for Cassandra 3.9.
Next, run the following command to get GPG key for Apache Cassandra.
wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
Also read : How to Install Sublime Text in Ubuntu
3. Install Apache Cassandra
Run the following commands to install Apache Cassandra.
sudo apt update$
sudo apt install Cassandra
After installation, Apache Cassandra will start immediately. Check its status with the following command.
sudo systemctl status cassandraOR $ sudo nodetool status
Also read : How to Add & Remove User in Ubuntu
4. Commonly used commands
Here are some commonly used commands for Apache Cassandra
To start Apache Cassandra, enter
$ sudo systemctl start cassandra
To stop Apache Cassandra, enter
$ sudo systemctl stop cassandra
To restart Apache Cassandra, enter
$ sudo systemctl restart cassandra
To start Apache Cassandra on boot, enter
$ sudo systemctl enable cassandra
Also read : How to Read & Write Files in Python
5. Configure Apache Cassandra
Apache Cassandra stores its data at /var/lib/cassandra and configuration at /etc/cassandra/cassandra.yaml. You can open this file in a text editor and customize configuration as per your requirement. The default configuration is good enough to run Apache Cassandra on a single node (localhost).
$ sudo vi /etc/cassandra/cassandra.yaml
You can also test your Cassandra database using the cqlsh tool that comes with Cassandra package.
The above command will open a shell that allows you to query your database using CQL (Cassandra Query Language).
Also read : How to Find Largest Files & Directories in Linux
6. Uninstall Apache Cassandra
If you feel the need to remove or uninstall Apache Cassandra from your system, run the following command.
$ sudo apt remove cassandra OR $ sudo apt uninstall cassandra
That’s it. In this article we have seen how to install Apache Cassandra in Ubuntu.