DEV Community

Cover image for How to Install Apache Kafka on Ubuntu 24.04
Abhinav
Abhinav

Posted on

How to Install Apache Kafka on Ubuntu 24.04

Apache Kafka is a powerful distributed event streaming platform used for real-time data processing, messaging, and logging. In this guide, we’ll walk through the step-by-step process of installing and setting up Kafka on Ubuntu 24.04.


1. Prerequisites

Before installing Kafka, ensure you have:

✅ A system running Ubuntu 24.04

Java 17+ installed

✅ Root or sudo privileges


2. Install Java (OpenJDK 17)

Kafka requires Java to run. Install it with:

sudo apt update
sudo apt install openjdk-17-jdk -y
Enter fullscreen mode Exit fullscreen mode

Verify Java installation:

java -version
Enter fullscreen mode Exit fullscreen mode

Expected output (version may vary):

openjdk version "17.0.9" 2024-01-15
Enter fullscreen mode Exit fullscreen mode

3. Download Apache Kafka

Visit the official Kafka download page and copy the latest binary version’s link. Then, download and extract it:

wget https://downloads.apache.org/kafka/3.6.0/kafka-3.9.0-src.tgz
tar -xvzf kafka-3.9.0-src.tgz 
sudo mv kafka-3.9.0-src.tgz  /opt/kafka
Enter fullscreen mode Exit fullscreen mode

Navigate to Kafka’s directory:

cd /opt/kafka
Enter fullscreen mode Exit fullscreen mode

4. Start Zookeeper

Kafka requires Zookeeper to manage broker nodes. Start Zookeeper with:

bash bin/zookeeper-server-start.sh config/zookeeper.properties

Leave this terminal open while running Kafka.

Image description


5. Start Kafka Broker

Open a new terminal and start the Kafka broker:

bin/kafka-server-start.sh config/server.properties
Enter fullscreen mode Exit fullscreen mode

Image description

Leave this terminal open while using Kafka.


6. Create a Kafka Topic

Once Kafka is running, open a new terminal and create a test topic named test-topic:

/opt/kafka/bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
Enter fullscreen mode Exit fullscreen mode

Verify the topic list:

/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092
Enter fullscreen mode Exit fullscreen mode

7. Send and Consume Messages

Send a Message (Producer)

/opt/kafka/bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
Enter fullscreen mode Exit fullscreen mode

Type a message and press Enter.

Image description

Consume Messages (Consumer)

bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092

Enter fullscreen mode Exit fullscreen mode

You should see the message you typed earlier.

Image description


Conclusion

Congratulations! 🎉 You have successfully installed and configured Apache Kafka on Ubuntu 24.04. Now, you can start using Kafka for real-time data streaming, event-driven architectures, and more.

Would you like a guide on integrating Kafka with NestJS? Let me know! 🚀

Top comments (1)

Collapse
 
nullcareexception profile image
Patrick

ZooKeeper is marked as deprecated since the 3.5.0 release. ZooKeeper is planned to be removed in Apache Kafka 4.0. So why are you still using it?