How To Install Apache Kafka on Ubuntu 20.04

How To Install Apache Kafka on Ubuntu 20.04


Step 1 — Creating a User for Kafka

 We will create a dedicated kafka user in this step.

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


sudo adduser kafka


Follow the prompts to set a password and create the kafka user.

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


Create a directory called kafka and change to this directory. This will be the base directory of the Kafka installation:


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

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


Enter the following unit definition into the file:






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:








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


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.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *