How to Install Zlib on Ubuntu 22.04

Data compression is an effective way to save disk space and reduce network bandwidth consumption. However, this comes at the expense of additional calculations. Fortunately, modern hardware is powerful enough that compression minimizes the impact on performance.

In this guide we show the installation zlib on Ubuntu 04/22

Zlib on Ubuntu

Zlib is a popular compression/decompression library that is free and open source. Additionally, zlib is free from legal obligations (not protected by patents), making it a lucrative option for developers. Some other notable features are:

  • Lossless data compression
  • Low memory requirements
  • Never expands the data. For comparison: LZW can even double/triple the compressed data size in extreme cases
  • Portable across platforms

Due to its widespread use, zlib is also available directly from the standard Ubuntu repo. Check availability with the following command:

$ matching search zlib1g

Note that the package name for zlib is zlib1gnot to be confused with zlibca completely different package.

Install zlib on Ubuntu

There are two different ways to install zlib on Ubuntu. We can either get the zlib1g package from Ubuntu or build it from source.

Installing zlib with APT

APT allows us to install the zlib package directly from the standard Ubuntu repos. In most situations, this is the recommended way.

Run the following commands to install zlib:

$ sudo appropriate update

$ sudo suitable To install zlib1g -y

If you need the development package for zlib, install the zlib1g-dev package with the following command:

$ sudo suitable To install zlib1g-dev -y

Install zlib from source

Zlib is an open source project. This way we can get the source code and build the package ourselves. However, this method is associated with various inconveniences such as: B. the need to manually manage the package.

First, install the necessary tools to build zlib:

$ sudo suitable To install build essential -y

At the time of writing, the latest version of zlib is v1.2.12. Download the source code archive:

$ wget

Next, extract the archive with tar:

$ tar -xvf zlib-1.2.12.tar.gz

From the source code directory, run the following commands:

$ ./configure

$ make -j$(nproc)

Once the package has finished compiling, install it with the following command:

$ sudo make To install

If you want to uninstall the package later, use the following command:

$ sudo make uninstall


In this guide, we’ve explored different ways to install zlib on Ubuntu. We installed the zlib packages (zlib1g and zlib1g-devel) with APT. We also demonstrated building and installing zlib from source (applicable in certain scenarios).

Want to learn more about compression in Linux? Check out Linux file compression options and how they compare. Zhr is another interesting compression algorithm worth checking out.

Related Posts