Apache Kafka is an open-source distributed event streaming platform used for building real-time data pipelines and applications. Originally developed by LinkedIn and now part of the Apache Software Foundation, Kafka is designed for high-throughput, low-latency, and fault-tolerant data processing across systems.
In this tutorial, we will show you the complete steps to install Apache Kafka on Ubuntu 24.04 OS.
Step 1: Update Operating System
Update your Debian 12 operating system to make sure all existing packages are up to date:
# apt update && apt upgrade
Step 2: Install Java (OpenJDK) on Ubuntu 24.04
Java packages are available on Ubuntu 24.04 repositories and you can install it with the following command:
# apt install default-jdk
Check Java version after installation:
# java -version
openjdk version "21.0.6" 2025-01-21
OpenJDK Runtime Environment (build 21.0.6+7-Ubuntu-124.04.1)
OpenJDK 64-Bit Server VM (build 21.0.6+7-Ubuntu-124.04.1, mixed mode, sharing)
Step 3: Download Apache Kafka
Check the official Apache Kafka Download page to locate the latest version of the software.
The latest version at the moment is 4.0.0. You can download it with the following command:
# wget https://downloads.apache.org/kafka/4.0.0/kafka_2.13-4.0.0.tgz
Once that downloads, unpack the tarball file using the following command:
# tar xvf kafka_2.13-4.0.0.tgz
Then move this directory into the /usr/local/ directory and rename it kafka:
# mv kafka_2.13-4.0.0 /usr/local/kafka
Step 4: Create a systemd file for Apache Kafka
First navigate to Kafka’s directory:
# cd /usr/local/kafka
Then you need to generate a Cluster UUID:
# KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
Format Log Directories:
# bin/kafka-storage.sh format --standalone -t $KAFKA_CLUSTER_ID -c config/server.properties
Now create a systemd file so you can control the Kafka service. Create the file with the following command:
# nano /etc/systemd/system/kafka.service
In that file, paste the following content:
[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service
[Service]
Type=simple
Environment="JAVA_HOME=/usr/lib/jvm/java-1.21.0-openjdk-amd64"
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
Save the changes and exit.
Reload system daemon and start the services:
# systemctl daemon-reload
# systemctl start kafka
# systemctl enable kafka
To confirm everything is working normally, check the status of service:
# systemctl status kafka
Output:
● kafka.service - Apache Kafka Server
Loaded: loaded (/etc/systemd/system/kafka.service; enabled; preset: enabled)
Active: active (running)
Docs: http://kafka.apache.org/documentation.html
Main PID: 11915 (java)
Tasks: 99 (limit: 2217)
Memory: 365.1M (peak: 365.4M)
CPU: 16.435s
CGroup: /system.slice/kafka.service
Step 5: Create a Kafka Topic
So before you can write your first events, you must create a topic. Create a topic named “my-events
” with the following command:
# usr/local/kafka
# bin/kafka-topics.sh --create --topic my-events --bootstrap-server localhost:9092
Created topic my-events.
To verify the topic list run the following command:
# bin/kafka-topics.sh --list --bootstrap-server localhost:9092
my-events
The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as events to the Kafka
cluster.
By default, each line you enter will result in a separate event being written to the topic.
# bin/kafka-console-producer.sh --topic my-events --bootstrap-server localhost:9092
>Hello World!
>This is my first topic
You can stop the consumer client with Ctrl-C
at any time.
If you also want to delete any data of your local Kafka environment including any events you have created along the way, run the command:
# rm -rf /tmp/kafka-logs /tmp/kraft-combined-logs
Comments and Conclusion
That’s it! You have now installed and started Apache Kafka
on your Ubuntu 24.04 system.
Remember that this guide assumes you have administrative privileges on your system.
Always check the official Apache Kafka documentation for the most up-to-date installation instructions and any specific considerations related to your system configuration.
If you have any questions please leave a comment below.