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
cqlshcommand-line tool. Verify withpython --version. - Environment variables: Set
JAVA_HOMEto your JDK installation path and add%JAVA_HOME%\binto yourPATH. - 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
- Set environment variables: Add
C:\cassandra\binto yourPATHso you can run commands from anywhere. - Configure data directories: Edit
conf/cassandra.yaml. By default, data is stored inC:\cassandra\data, commit logs inC:\cassandra\commitlog, and saved caches inC:\cassandra\saved_caches. Create these folders if they don’t exist. - Adjust heap size (optional): In
conf/jvm-server.options, set-Xmsand-Xmxto reasonable values (e.g., 1-4 GB) based on your RAM. - Start Cassandra: Open a command prompt as Administrator, navigate to
C:\cassandra, and runbin\cassandra.bat. Wait for the message “Starting listening for CQL clients” (usually takes 30-60 seconds). - Verify: In another terminal, run
nodetool status. You should see a node with statusUN(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
cqlshscript has the correct shebang (on Windows, usecqlsh.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:
- Run
nssm install Cassandra. - Set the application path to
C:\cassandra\bin\cassandra.bat. - Set the startup directory to
C:\cassandra\bin. - 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
- How to Enable Desktop Slideshow in Windows 10
- BattlEye Service Failed: Test Signing Fix
- Chrome Remote Desktop on Chromebook: Setup Guide
- App Store Missing on iPad? Fix It
- How to Unroot Samsung Galaxy Core LTE
- Ways to Create More Disk Space in Windows 10