Skip to main content

Install Apache Cassandra on macOS

· 3 min read
All round blogger

Install Apache Cassandra on macOS

You often want to set up a development environment when building an application or website and running Apache Cassandra is much easier locally than other options.

This article will show you how to use two different methods. Install it directly in macOS or use Podman to install and use a container of Apache Cassandra.

Install OpenJDK

The first task is to install Java on macOS. This is easy to do with Homebrew:

brew update
brew upgrade
brew install openjdk@21

Then we need to ensure that Java is on the $PATH. You can do this by adding the following line to ~/.zshrc or ~/.bashrc.

export PATH="/opt/homebrew/Cellar/openjdk@21/21.0.7/bin:$PATH"

then we set the JAVA_HOME environment variable also in ~./.zshrc or ~/.bashrc.

export JAVA_HOME=/opt/homebrew/Cellar/openjdk@21/21.0.7/libexec/openjdk.jdk/Contents/Home

Download Apache Cassandra

Now we need to download the Apache Cassandra binary.

Go to this website:

https://cassandra.apache.org/_/download.html

and download the latest version (at the time of writing it is 5.0.4).

Go to your ~/Downlaods folder and untar the archive. This will create a folder named something like this:

apache-cassandra-5.0.4

Now we just need to start the binary:

cd ~/Downloads/apache-cassandra-5.0.4/bin/
./cassandra

and you now have Cassandra up and running on your Mac.

You should now be able to connect to Apache Cassandra by using the IP address 127.0.0.1 and port number 9042.

Add Apache Cassandra binaries to the PATH

If you want to use Apache Cassandra binaries from any directory you need to add them to the PATH. This will mean you just need to type the program name without needing to type the path to the program.

In order to edit the path open either ~/.zshrc or ~/.bashrc and place this line at the top of the file:

export PATH="/Users/<username>/Downloads/apache-cassandra-5.0.4/bin:$PATH"

You'll need to change username to whatever your macOS username is and change the Apache Cassandra folder name to the version you are running. In the above example I am using 5.0.4 and it is stored in the Downloads folder.

Install Apache Cassandra using Podman on macOS

First of all you need to install Podman Desktop for macOS.

You can do that here:

https://podman.io/

Start and Run the Container

Run the following commands to get up and running:

podman pull cassandra
podman run --name cassandra -d -p 9042:9042 cassandra

If you want to use the binaries inside the container such as cqlsh you can do like this:

podman exec -it cassandra cqlsh

This assumes the container name is cassandra.

To check if the container is actually running use:

podman ps