sodcalculator

10 Tech How-To

Install Cassandra on Windows: Step-by-Step Guide

Guide 10-30893 · Updated · Step by step

Yes, you can install Apache Cassandra on Windows, and the process is straightforward if you follow the right steps. This guide walks you through the entire setup, from prerequisites to running your first query, and covers common pitfalls along the way.

What Is Apache Cassandra?

Apache Cassandra is a free, open-source, distributed NoSQL database designed to handle large amounts of data across many commodity servers. It offers high availability with no single point of failure, making it a popular choice for applications that need continuous uptime and linear scalability. Unlike traditional relational databases, Cassandra uses a wide-column store model, where data is organized into rows and columns but without a fixed schema, allowing for flexible and fast writes.

Prerequisites

Before you begin, ensure your Windows machine meets these requirements:

  • Java 8 or 11: Cassandra 4.x requires Java 8 or 11 (Oracle JDK or OpenJDK). Check with java -version.
  • Python 2.7 or 3.x: Needed for the cqlsh command-line tool. Verify with python --version.
  • Environment variables: Set JAVA_HOME to your JDK installation path and add %JAVA_HOME%\bin to your PATH.
  • Administrator rights: Needed to modify system settings and run services.

Downloading Cassandra

Go to the official Apache Cassandra download page and grab the latest stable binary tarball (e.g., apache-cassandra-4.1.3-bin.tar.gz). Extract the archive to a simple path like C:\cassandra to avoid long path issues. Avoid spaces in the directory name, as some scripts may fail.

Installing and Configuring

  1. Set environment variables: Add C:\cassandra\bin to your PATH so you can run commands from anywhere.
  2. Configure data directories: Edit conf/cassandra.yaml. By default, data is stored in C:\cassandra\data, commit logs in C:\cassandra\commitlog, and saved caches in C:\cassandra\saved_caches. Create these folders if they don’t exist.
  3. Adjust heap size (optional): In conf/jvm-server.options, set -Xms and -Xmx to reasonable values (e.g., 1-4 GB) based on your RAM.
  4. Start Cassandra: Open a command prompt as Administrator, navigate to C:\cassandra, and run bin\cassandra.bat. Wait for the message “Starting listening for CQL clients” (usually takes 30-60 seconds).
  5. Verify: In another terminal, run nodetool status. You should see a node with status UN (Up Normal).

Using cqlsh (Cassandra Query Language Shell)

To interact with the database, use the cqlsh tool. Run cqlsh from the bin directory. If you get a connection error, ensure Cassandra is running. Then create a keyspace and a table:

CREATE KEYSPACE test WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};
USE test;
CREATE TABLE users (id int PRIMARY KEY, name text);
INSERT INTO users (id, name) VALUES (1, 'Alice');
SELECT * FROM users;

Common Problems and Fixes

  • Java version mismatch: Cassandra may refuse to start if Java is too new (e.g., Java 17). Use Java 8 or 11.
  • “Unable to load JNA library”: This warning is harmless, but you can install JNA by adding the jar to the classpath or ignore it.
  • Port conflicts: Cassandra uses ports 7000, 9042, and 9160. If other services occupy them, change ports in cassandra.yaml.
  • “Error while loading native library”: Ensure you have the Microsoft Visual C++ Redistributable installed.
  • cqlsh not recognized: Check Python is installed and in PATH, and that the cqlsh script has the correct shebang (on Windows, use cqlsh.bat).

Running Cassandra as a Windows Service

To run Cassandra automatically in the background, you can use a tool like NSSM (Non-Sucking Service Manager). Download NSSM, then:

  1. Run nssm install Cassandra.
  2. Set the application path to C:\cassandra\bin\cassandra.bat.
  3. Set the startup directory to C:\cassandra\bin.
  4. Start the service via Services.msc or net start Cassandra.

This is optional but convenient for production-like setups.

Frequently Asked Questions

Can I run Cassandra on Windows 10 or 11?

Yes, Cassandra works on Windows 10 and 11, but it is not officially supported by Apache (they only guarantee Linux). Many developers use it for development and testing; for production, Linux is recommended.

Do I need to install Python?

Only if you want to use cqlsh. Cassandra itself does not require Python, but cqlsh is the standard command-line client and it depends on Python.

How do I stop Cassandra?

Press Ctrl+C in the terminal where it’s running, or run nodetool stopdaemon from another terminal.

Can I use Cassandra with Docker on Windows?

Yes, running Cassandra in a Docker container is often easier. Use docker run --name cassandra -d cassandra:latest and then connect via docker exec -it cassandra cqlsh.

Why is Cassandra so slow on my Windows machine?

Likely due to insufficient heap size or disk I/O. Increase -Xmx in jvm-server.options and ensure your data directory is on an SSD.

Is Cassandra free for commercial use?

Yes, Cassandra is licensed under the Apache License 2.0, which permits free commercial use.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →