By Ashish Kasamaauthor-img
July 3, 2025|6 Minute read|
Play
/ / A Step-by-Step Guide to Installing ZooKeeper
At a Glance:

This blog provides a step-by-step guide on installing and configuring ZooKeeper on Linux, macOS, and Windows. It covers the prerequisites, installation process, key configuration settings in the zoo.cfg file, and how to test ZooKeeper using the CLI. The article also includes tips for optimal performance.

Introduction

Zookeeper is a distributed coordination service for distributed applications, ensuring coordination and synchronization across multiple nodes. Simply, it provides a way for applications to coordinate with each other in a reliable and fault-tolerant way. However, setting it up can be a daunting task, especially for beginners. So, we are here with a step-by-step guide that simplifies the installation process, making it accessible for developers and system administrators.

You will also learn about prerequisite steps, installation steps, and crucial configuration settings in the zoo.cfg file. Moreover, this guide also includes testing Zookeeper using the Command-line interface (CLI) and further tips.

How to Install Zookeeper in Linux, macOS, and Windows?

Installing Apache ZooKeeper on different platforms, including macOS, Windows, and Linux, requires platform-specific approaches. Differences in package management, scripting, and file systems are the primary reasons behind the varying approaches to installation.

macOS uses Homebrew for a streamlined installation with brew install ZooKeeper.

Ubuntu combines apt for Java and manual tarball extraction with zkServer.sh.

And Windows relies on manual tarball setup, JAVA_HOME configuration, and zkServer.cmd.

All platforms, however, need Java, a zoo.cfg file, and zkCli to verify the connection to 127.0.0.1:2181.

Installing ZooKeeper on Linux (Ubuntu)

To install ZooKeeper on Linux, you can follow these steps:

Prerequisites

  • Ubuntu system (20.04 or later recommended)
  • Java installed (ZooKeeper requires Java)

Step 1: Update Your System

bashCopyEditsudo apt update
sudo apt upgrade -y

Step 2: Install Java (ZooKeeper Dependency)

ZooKeeper requires Java to run. You can install OpenJDK:

bashCopyEditsudo apt install default-jdk -y

Verify Java is installed:

bashCopyEditjava -version

Step 3: Create a User for ZooKeeper (optional but recommended)

bashCopyEditsudo useradd zookeeper -m

Step 4: Download ZooKeeper

Find the latest version at: https://zookeeper.apache.org/releases.html

bashCopyEditcd /opt
sudo wget https://downloads.apache.org/zookeeper/zookeeper-3.9.2/apache-zookeeper-3.9.2-bin.tar.gz
sudo tar -xzf apache-zookeeper-3.9.2-bin.tar.gz
sudo mv apache-zookeeper-3.9.2-bin zookeeper
sudo chown -R zookeeper:zookeeper /opt/zookeeper

Step 5: Configure ZooKeeper

Create a Data Directory:

bashCopyEditsudo mkdir -p /var/lib/zookeeper
sudo chown zookeeper:zookeeper /var/lib/zookeeper

Create Configuration File:

bashCopyEditsudo nano /opt/zookeeper/conf/zoo.cfg

Paste the following minimal config:

iniCopyEdittickTime=2000 dataDir=/var/lib/zookeeperclientPort=2181 initLimit=5 syncLimit=2 

Save and exit (Ctrl+O, then Ctrl+X).

Step 6: Run ZooKeeper

Switch to the zookeeper user:

bashCopyEditsudo su - zookeepercd /opt/zookeeper
bin/zkServer.sh start

To check status:

bashCopyEditbin/zkServer.sh status

To stop ZooKeeper:

bashCopyEditbin/zkServer.sh stop

Optional: Create a Systemd Service (to start on boot)

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

Paste:

iniCopyEdit[Unit] Description=Apache ZooKeeper ServerAfter=network.target
[Service] Type=simpleUser=zookeeperExecStart=/opt/zookeeper/bin/zkServer.sh start-foregroundExecStop=/opt/zookeeper/bin/zkServer.sh stopRestart=on-abnormal
[Install] WantedBy=multi-user.target

Enable and start:

bashCopyEditsudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable zookeeper
sudo systemctl start zookeeper

Steps to Install ZooKeeper on macOS

Prerequisites for installing ZooKeeper on macOS:

  1. macOS (Monterey or later recommended)
  2. Java JDK 8 or later
  3. Homebrew (macOS package manager)

Now your macOS is ready for ZooKeeper installation.

Step 1: Install Homebrew (if not already installed)

Homebrew is a package manager for macOS. Open Terminal and run:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install ZooKeeper using Homebrew

brew install zookeeper

This will install ZooKeeper and its dependencies.

Step 3: Start ZooKeeper

You can start ZooKeeper using the built-in configuration:

zkServer start

To stop ZooKeeper:

zkServer stop

To check the status:

zkServer status

Step 4: (Optional) Run ZooKeeper as a background service

brew services start zookeeper

This will keep ZooKeeper running in the background across reboots.

Step 5: Verify Installation

You can verify ZooKeeper is running by connecting to it via the CLI:

zkCli

How to Install Zookeeper on Windows

Follow the ensuing steps to run Zookeeper on Windows;

Prerequisites:

  1. Java (JDK)
  2. ZooKeeper binaries
  3. Optional: Notepad++ or any text editor

Step 1: Install Java

  1. Download and install the Java JDK: https://www.oracle.com/java/technologies/javase-jdk11-downloads.html
  2. Verify installation:
bashCopyEditjava -version

If not recognized, add Java's bin folder to your system's Environment Variables(Path.)

Step 2: Download ZooKeeper

  1. Go to: https://zookeeper.apache.org/releases.html
  2. Download a binary release (e.g., zookeeper-3.8.4).
  3. Extract the .tar.gz using 7-Zip.

Step 3: Configure ZooKeeper

  1. Inside the extracted folder (zookeeper-3.8.4-bin), go to conf/.
  2. Copy zoo_sample.cfg and rename it to zoo.cfg.
  3. Edit zoo.cfg:
propertiesCopyEdittickTime=2000
dataDir=C:/zookeeper/data
clientPort=2181
initLimit=5
syncLimit=2
  1. Create the data directory:
bashCopyEditmkdir C:\zookeeper\data

Step 4: Start ZooKeeper

  1. Open Command Prompt, navigate to ZooKeeper bin folder:
bashCopyEditcd path\to\zookeeper-3.8.4-bin\bin
  1. Start the server:
bashCopyEditzkServer.cmd

You should see Mode: standalone at the end, meaning it iss running.

Step 5: Test with CLI

  1. In a new terminal, run:
bashCopyEditzkCli.cmd
  1. Try basic commands:
bashCopyEditcreate /test "hello"get /test

Configuring ZooKeeper

The conf/zoo.cfg file contains the configuration settings for your ZooKeeper cluster. These settings include the following:

  • The number of ZooKeeper servers in the cluster
  • The hostname and port of each ZooKeeper server
  • tickTime (time unit in milliseconds)
  • syncLimit (synchronization limit)
  • dataDir (data storage directory)

For more information on the configuration settings, please refer to the ZooKeeper documentation: https://zookeeper.apache.org/doc/r3.1.2/zookeeperStarted.html

Starting and Testing Zookeeper

Once you have installed and configured ZooKeeper, you can test it by connecting to it using the ZooKeeper CLI. The ZooKeeper CLI is a command-line tool that allows you to interact with ZooKeeper.

Run the following command to start;

bin/zkCli.sh start

Next, you will see the following standard response:

ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Now, you can test it by connecting to it using the ZooKeeper CLI. The ZooKeeper CLI is a command-line tool that allows you to interact with ZooKeeper.

Upon connection, you should see a prompt indicating a successful connection to 127.0.0.1:2181.

Security Considerations for Apache Zookeeper

  • Use ACLs to restrict access and configure permissions for create, delete, read, and write for granular control.
  • Enable SSL/TLS for secure client and server communication.
  • Utilize firewalls to allow only trustworthy IPs to connect.
  • Monitor regularly to detect any suspicious acts.
  • Implement these security measures to ensure a secure setup.

Conclusion

In this blog, we went through the step-by-step guide for installing Zookeeper on Windows, Linux, and macOS. This will help you get started with Zookeeper, no matter the operating system you are using. Here, we also discussed some additional tips for securing the ZooKeeper setup. Hope this helps!

Ashish Kasama

Co-founder & Your Technology Partner

One-stop solution for next-gen tech.

Frequently Asked Questions

Still have Questions?

Let’s Talk

Can I run ZooKeeper on Windows?

arrow

How to start ZooKeeper on Linux?

arrow

What are the key configuration settings in the zoo.cfg file?

arrow