Install Kafka with ZookeeperFor maximum compatibility purposes, it is recommended to start Apache Kafka with Zookeeper. If you would like to run Kafka without Zookeeper, take a look here.
How to install Kafka with Zookeeper on Linux
- Install Java JDK version 11
- Download Apache Kafka from https://kafka.apache.org/downloads under Binary Downloads
- Extract the contents on Linux
- Start Zookeeper using the binaries
- Start Kafka using the binaries in another process
- Setup the $PATH environment variables for easy access to the Kafka binaries
Installing Java JDK 11
To install Apache Kafka on Linux, Java 11 is the only prerequisite.- Navigate to Amazon Corretto 11 Linux install page and follow the steps, which work for Debian, RPM, Alpine and Amazon Linux. Alternatively, you can download from the Amazon Corretto 11 download page and install the correct package for your Linux distribution (x64, aarch64, x86, arch32, etc…).
- For example on Ubuntu (Debian-based systems)
java -version
:
Install Apache Kafka
1. Download the latest version of Apache Kafka from https://kafka.apache.org/downloads under Binary downloads.
2.13-2.8.1
.
Alternatively you can run a wget command
~/kafka_2.13-2.8.1
.
~/kafka_2.13-2.8.1
directory.
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. Make sure yourJAVA_HOME
environment variable is set first, as instructed in the Install Java section, so that Java 11 is used when doing java -version
From the root of Apache Kafka, run the following command to start Zookeeper:

Daemon ModeYou can use the -daemon flag to run Zookeeper in daemon mode in the background
Start Apache Kafka
Open another Shell window and run the following command from the root of Apache Kafka to start Apache Kafka.
Setup the $PATH environment variable
In order to easily access the Kafka binaries, you can edit your PATH variable by adding the following line to your system run commands (for example~/.zshrc
if you use zshrc or ~/.bashrc
for Bash ):
PATH="$PATH:~/kafka_2.13-2.8.1/bin"
This ensures that you can now run the kafka commands without prefixing them.
After reloading your shell, the following should work from any directory
Optional: changing the Kafka and Zookeeper data storage directory
For Zookeeper:-
edit the
zookeeper.properties
file at~/kafka_2.13-2.8.1/config/zookeeper.properties
and set the following to your heart’s desiredataDir=/your/path/to/data/zookeeper
-
start Zookeeper using the update
zookeeper.properties
file as shown above -
you can also make a copy of the
zookeeper.properties
file anywhere in your computer and edit that file instead, and reference it in the Zookeeper start command shown above
-
edit the
server.properties
file at~/kafka_2.13-2.8.1/config/server.properties
and set the following to your heart’s desirelog.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