Installing Cassandra
Prerequisites
Before you can install Cassandra, you need to make sure you have the following prerequisites installed on your system:
- Java Development Kit (JDK) version 8 or higher
- Python version 2.7 or 3.x (optional, required only for running some Cassandra tools)
Make sure you have these prerequisites installed before proceeding to the next steps.
Step 1: Download Cassandra
The first step in installing Cassandra is to download the latest stable release from the official Apache Cassandra website. Go to the download page and select the version you want to download.
Once you’ve selected the version, you’ll be presented with a list of mirror sites from which to download the software. Choose a mirror site closest to your location and download the appropriate package for your operating system.
Step 2: Install Cassandra
Once you’ve downloaded the Cassandra package, you can install it by following these steps:
- Extract the contents of the package to a directory of your choice.
- Set the
CASSANDRA_HOMEenvironment variable to the directory where you extracted the package. - Add the
bindirectory to your system’sPATHenvironment variable.
How to Install Cassandra on Linux based System?
Here’s how you can do this on a Linux-based system:
- Open a terminal window and navigate to the directory where you downloaded the package.
- Extract the package by running the following command:
tar -xvf apache-cassandra-<version>-bin.tar.gz(replace<version>with the version number you downloaded). - Move the extracted directory to a location of your choice, such as
/opt/cassandra. - Set the
CASSANDRA_HOMEenvironment variable by running the following command:export CASSANDRA_HOME=/opt/cassandra(replace/opt/cassandrawith the directory where you extracted the package). - Add the
bindirectory to your system’sPATHenvironment variable by running the following command:export PATH=$PATH:$CASSANDRA_HOME/bin.
How to Install Cassandra on Windows based System?
Here’s how you can do this on a Windows-based system:
- Open a command prompt and navigate to the directory where you downloaded the package.
- Extract the package by running the following command:
tar -xvf apache-cassandra-<version>-bin.tar.gz(replace<version>with the version number you downloaded). - Move the extracted directory to a location of your choice, such as
C:\Program Files\Apache Cassandra. - Open the System Properties dialog by right-clicking on the My Computer icon and selecting Properties.
- Click on the Advanced tab, then click the Environment Variables button.
- Under System Variables, click the New button and add a new variable called
CASSANDRA_HOMEwith the value set to the directory where you extracted the package (e.g.C:\Program Files\Apache Cassandra). - Edit the
PATHvariable and add thebindirectory to the end of the existing value (e.g.%PATH%;C:\Program Files\Apache Cassandra\bin).
Step 3: Start Cassandra
Now that you’ve installed Cassandra, you can start it by following these steps:
- Open a terminal window or command prompt.
- Navigate to the Cassandra installation directory (e.g.
/opt/cassandraon Linux orC:\Program Files\Apache Cassandraon Windows). - Start Cassandra by running the following command:
bin/cassandra(on Windows, you can runbin\cassandra.batinstead). - Wait for Cassandra to start up.
Step 4: Verify Cassandra is running
After starting Cassandra, you can verify that it’s running by using the nodetool command-line tool, which is included with the Cassandra package.
To check the status of the Cassandra cluster, run the following command:
$ nodetool status
This command should output a table containing information about the Cassandra cluster, including the status of each node in the cluster.
Step 5: Connect to Cassandra
To connect to Cassandra, you can use the cqlsh command-line tool, which is also included with the Cassandra package.
To connect to Cassandra, run the following command:
$ cqlsh
This will start the cqlsh shell and connect to the local Cassandra node. From here, you can execute CQL statements to create tables, insert data, and query data.
Step 6: Install Cassandra as a service (optional)
If you plan on running Cassandra as a service on your system, you can install it as a service using the cassandra.in.sh script, which is located in the bin directory of the Cassandra installation.
To install Cassandra as a service on a Linux-based system, follow these steps:
- Open a terminal window and navigate to the Cassandra installation directory.
- Run the following command to create a symlink to the
cassandra.in.shscript in the/etc/init.ddirectory:sudo ln -s $CASSANDRA_HOME/bin/cassandra.in.sh /etc/init.d/cassandra. - Run the following command to add the Cassandra service to the startup sequence:
sudo update-rc.d cassandra defaults.
To install Cassandra as a service on a Windows-based system, follow these steps:
- Open a command prompt and navigate to the Cassandra installation directory.
- Run the following command to install Cassandra as a service:
bin\cassandra.bat -install. - Start the Cassandra service by running the following command:
net start "Cassandra".
Conclusion
In this tutorial, we’ve covered the steps required to install Cassandra on your system, along with all the prerequisites needed to run Cassandra. We’ve also shown you how to start Cassandra, verify that it’s running, and connect to it using the cqlsh command-line tool.
By following these steps, you should now have a working installation of Cassandra on your system that you can use to store and retrieve data.
