How To Install Apache Kafka on Ubuntu

Step 1 — Creating a User for Kafka

Logged in as your non-root sudo user, create a user called kafka:

sudo adduser kafka

Next, add the kafka user to the sudo group with the adduser command. You need these privileges to install Kafka’s dependencies:

sudo adduser kafka sudo

Your kafka user is now ready. Log into the account using su:

su -l kafka
Step 2 — Downloading and Extracting the Kafka Binaries

Let’s download and extract the Kafka binaries into dedicated folders in our kafka user’s home directory.

To start, create a directory in /home/kafka called Downloads to store your downloads:

mkdir ~/Downloads

Use curl to download the Kafka binaries:

curl “” -o ~/Downloads/kafka.tgz

mkdir ~/kafka && cd ~/kafka

Extract the archive you downloaded using the tar command:

tar -xvzf ~/Downloads/kafka.tgz –strip 1
Step 3 — Configuring the Kafka Server

Kafka’s configuration options are specified in Open this file with nano or your favorite editor:

nano ~/kafka/config/

First, add a setting that will allow us to delete Kafka topics. Add the following to the bottom of the file:

delete.topic.enable = true

Second, change the directory where the Kafka logs are stored by modifying the logs.dir property:

Step 4 — Creating Systemd Unit Files and Starting the Kafka Server

Create the unit file for zookeeper:

sudo nano /etc/systemd/system/zookeeper.service

Enter the following unit definition into the file:


[Service] Type=simple
ExecStart=/home/kafka/kafka/bin/ /home/kafka/kafka/config/


Next, create the systemd service file for kafka:

sudo nano /etc/systemd/system/kafka.service

Enter the following unit definition into the file:

[Unit] Requires=zookeeper.service

[Service] Type=simple
ExecStart=/bin/sh -c ‘/home/kafka/kafka/bin/ /home/kafka/kafka/config/ > /home/kafka/kafka/kafka.log 2>&1’


Now that you have defined the units, start Kafka with the following command:

sudo systemctl start kafka

To ensure that the server has started successfully, check the journal logs for the kafka unit:

sudo systemctl status kafka

You will receive output like this:

● kafka.service
Loaded: loaded (/etc/systemd/system/kafka.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2021-02-10 00:09:38 UTC; 1min 58s ago
Main PID: 55828 (sh)
Tasks: 67 (limit: 4683)
Memory: 315.8M
CGroup: /system.slice/kafka.service
├─55828 /bin/sh -c /home/kafka/kafka/bin/ /home/kafka/kafka/config/ > /home/kafka/kafka/kafka.log 2>&1
└─55829 java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -XX:MaxInlineLevel=15 -Djava.awt.headless=true -Xlog:gc*:file=>

Feb 10 00:09:38 cart-67461-1 systemd[1]: Started kafka.service.

About admin

Check Also

how to Installing Deluge BitTorrent Client in linux

Deluge utilizes a client/server model with “deluged” being daemon or service and the “deluge” being …

Leave a Reply

Your email address will not be published.