How to Install Apache Kafka on Ubuntu 22.04 LTS

In this article We are going to perform How to Install Apache Kafka on Ubuntu 22.04 LTS and also covered creating systemd unit file for zookeeper and Kafka service, create a topic in Kafka, send messages in Kafka, Start consumer in Kafka.

What is Kafka ?

Kafka is an open source software which provides a framework for storing, reading and analysing streaming data.

Being open source means that it is essentially free to use and has a large network of users and developers who contribute towards updates, new features and offering support for new users.

Kafka is designed to be run in a “distributed” environment, which means that rather than sitting on one user’s computer, it runs across several (or many) servers, leveraging the additional processing power and storage capacity that this brings.

Why do you need Kafka it depends on your use case

Some use cases I can think of :

  1. you can have a streaming app that captures logs of all the apps in a company and all can be redirected to common logging space.
  2. Real-time transactions you can leverage kafka.
  3. You can build set of micro services that perform complex business logic to communicate through Kafka .

You can easily integrate kafka to various big data processing frameworks like apache spark , Apache storm seamlessly.

You can know more about it here : Apache Kafka


  • Create Ubuntu Instance 22.04 LTS
  • SSH Access with Sudo privileges
  • Firewall Port 9092
  • JDK 1.8 or higher version

Install OpenJDK on Ubuntu 22.04 LTS

To update system packages

sudo apt-get update

you can install OpenJDK 8 or OpenJDK 11

sudo apt install openjdk-8-jdk


sudo apt install openjdk-11-jdk
install jdk

To check the java version, Here I have install installed Oracle Java 11 on my system.

java -version


java version

Step #1:Install Apache Kafka on Ubuntu 22.04 LTS

To download the Kafka binary from offical website. Please use this Kafka official download page and to prompts to download page and you can download Kafka using wget

sudo wget

Now to un-tar or Unzip the archive file and move to another location:

sudo tar xzf kafka_2.12-3.5.0.tgz
sudo mv kafka_2.12-3.5.0 /opt/kafka
unzip n mv

Step #2:Creating Zookeeper and Kafka Systemd Unit Files in Ubuntu 22.04 LTS

Create the systemd unit file for zookeeper service

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

paste the below lines

Description=Apache Zookeeper service

ExecStart=/opt/kafka/bin/ /opt/kafka/config/


Reload the daemon to take effect

sudo systemctl daemon-reload

Create the systemd unit file for kafka service

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

paste the below lines

Description=Apache Kafka Service

ExecStart=/opt/kafka/bin/ /opt/kafka/config/

kafka ser

Note: Modify the value of JAVA_HOME value, If the path of your Java installation is different path like If your java version is 1.8 the use Environment=”JAVA_HOME=/opt/jdk/jdk1.8.0_251″ this path.

Reload the daemon to take effect

sudo systemctl daemon-reload

Step #3:To Start ZooKeeper and Kafka Service and Check its Status

Lets start zookeeper service first

sudo systemctl start zookeeper

Check the status of  zookeeper service if it started

sudo systemctl status zookeeper


zooker status

Start the kafka service

sudo systemctl start kafka

Check the status of  kafka service if it started

sudo systemctl status kafka


kafka status

To Start Kafka And ZooKeeper Server in the background(without creating systemd unit file)

We have shell script to run the kafka and zookeeper server in backend:

Create a file named and copy the below script:

sudo nohup /opt/kafka/bin/ -daemon /opt/kafka/config/ > /dev/null 2>&1 &
sleep 5
sudo nohup /opt/kafka/bin/ -daemon /opt/kafka/config/ > /dev/null 2>&1 &

After give the executable permissions to the file:

sudo chmod +x

Successfully We have covered how to install apache kafka on ubuntu 22.04 LTS.

Step #4:Creating Topic in Kafka

Now we will create a topic named as “DevOps” with a single replicaton-factor and partition:

cd /opt/kafka
bin/ --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic DevopsHint


topic created1

Explanation of command

  • –create :- It is used for create a new topic
  • –replication-factor :- It is used for how many copies of data will be created.
  • –partitions :- It is used for set the partitions options as the number of brokers you want your data to be split between.
  • –topic :- It is used for name of the topic

To check the list of topics created.

bin/ --list --bootstrap-server localhost:9092


topic status

Step #5:To send some messages using Kafka

To send some messages for created Topic.

sudo bin/ —broker-list localhost:9092 —topic DevopsHint

its prompt for messages to type:

> hello world!
> How are you?
> This is DevopsHint
> Bye…

Step #6:To Start consumer in Kafka

Using below command we can see the list of messages:

sudo bin/ ---bootstrap-server localhost:9092 ---topic DevopsHint ---from-beginning


consumer messages

Step #7:To Connect Kafka from remote machine

To connect, create Topic and send messages from remote server. Please follow below steps.

Go to the below path:

cd /opt/kafka/config

Now look for and make some configuration changes:

sudo vi

In this properties file uncomment as mentioned  below:

advertised.listeners=PLAINTEXT://<HOST IP>:9092

Step #8:To Delete any Topics in Kafka

If you want to delete any created  topic use below command:

sudo bin/ --delete localhost:9092 --topic <anytopic>

We have covered How to Install Apache Kafka on Ubuntu 22.04 LTS.


In this article, We have covered ,How to Install Apache Kafka on Ubuntu 22.04 LTS and also covered creating systemd unit file for zookeeper and kafka service, start zookeeper, start kafka, create a topic, To send some messages, To start consumer.

Related Articles:

How to Install NGINX on Ubuntu 22.04 LTS

About Priti Adkine

I am Priti Adkine working as Software Engineer and having 1+ years of Experience. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link