Chapters

How to install Apache Kafka on Mac with Homebrew

Learn how to start Apache Kafka on Mac OS with Homebrew (brew)


How to Install Kafka with Homebrew?

  1. Install Homebrew

  2. Run brew install kafka

  3. Start Zookeeper using the CLI

  4. Start Kafka using the CLI in another terminal

Control vs Homebrew

For more control over your Kafka installation and different binary versions, we prefer using the method above instead of Homebrew. Nonetheless, here are the steps to install Kafka using Homebrew

If you have already installed Homebrew for Mac OS, you can use it to install Kafka in one step. This will ensure that you have Java installed first, and it will then install Apache Kafka.

If you have not yet installed Homebrew, do that first by following the directions on the installation page.

1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then you can install Kafka itself. The Homebrew package manager will ensure that you have all the dependencies installed first, including the necessary Java version:

1 brew install kafka

Homebrew will install Kafka under /usr/local/Cellar, but the files will be linked into other directories:

  • Binaries and scripts will be in /usr/local/bin

  • Kafka configurations will be in /usr/local/etc/kafka

  • Zookeeper configuration will be in /usr/local/etc/zookeeper

  • The log.dirs config (the location for Kafka data) will be set to /usr/local/var/lib/kafka-logs

Start Zookeeper

Apache Kafka depends on Zookeeper for cluster management. Hence, prior to starting Kafka, Zookeeper has to be started. There is no need to explicitly install Zookeeper, as it comes included with Apache Kafka.

After installation is complete, you can start Zookeeper using the following command

1 /usr/local/bin/zookeeper-server-start /usr/local/etc/zookeeper/zoo.cfg
Terminal screenshot showing that Zookeeper for Kafka is running.

Start Apache Kafka

Open another Terminal window and run the following command from the root of Apache Kafka to start Apache Kafka.

1 /usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties
Terminal screenshot taken when starting Apache Kafka via Homebrew on Mac

Ensure to keep both terminal windows opened, otherwise you will shut down Kafka or Zookeeper.

Kafka is now started, congratulations!


Optional: Changing the Kafka and Zookeeper data storage directory when using Homebrew

For Zookeeper:

  • edit the zoo.cfg file at /usr/local/etc/zookeeper/zoo.cfg and set the following to your heart's desire dataDir=/your/path/to/data/zookeeper

  • start Zookeeper using the update zoo.cfg file as shown above

  • you can also make a copy of the zoo.cfg file anywhere in your computer and edit that file instead, and reference it in the Zookeeper start command shown above

For Kafka:

  • edit the server.properties file at /usr/local/etc/kafka/server.properties and set the following to your heart's desire log.dirs=/your/path/to/data/kafka

  • start Zookeeper using the update server.properties file as shown above

  • you can also make a copy of the server.properties file anywhere in your computer and edit that file instead, and reference it in the Zookeeper start command shown above.

Was this content helpful?
7
1
PreviousHow to Install Apache Kafka on Mac without Zookeeper? (KRaft mode)
NextHow to Install Apache Kafka on Linux?

Start Kafka clusters in seconds using Conduktor

Conduktor offers the fastest way to start Kafka ever. In a couple of clicks and a few seconds, you will launch a local Kafka cluster with any version of Apache Kafka and optionally the Schema Registry. Download Conduktor and see the instructions here.

Screenshot show how to start a Kafka cluster quickly with Conduktor
Start a local cluster in a couple of clicks
Live local cluster with Schema Registry in a few seconds
Your cluster is live and ready to go