Categories: Ubuntu

How To Install Zlib on Ubuntu 22.04

Data compression is an effective way of saving disk space and reducing network bandwidth consumption. However, it comes at the cost of additional computation. Thankfully, modern hardware is powerful enough so that compression minimizes impact on performance.

In this guide, we will showcase installing zlib on Ubuntu 22.04.

Zlib on Ubuntu

Zlib is a popular compression/decompression library that’s free and open-source. In addition, zlib is free from legal liabilities (not covered by any patent), making it a lucrative option for developers. Some other notable features include:

  • Lossless data compression
  • Small memory footprint
  • Never expands the data. For comparison, LZW can increase the compressed data size in extreme cases, even double/triple
  • Sponsored
  • Portable across platforms

Because of its widespread usage, zlib is also directly available from the default Ubuntu repo. Check the availability using the following command:

$ apt search zlib1g

Note that the package name for zlib is zlib1g, not to be confused with zlibc, a completely different package.

Installing zlib on Ubuntu

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

Installing zlib Using APT

Using APT, we can install the zlib package directly from the default Ubuntu repos. In most situations, this is the recommended way to go.

To install zlib, run the following commands:

$ sudo apt update

$ sudo apt install zlib1g -y

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

$ sudo apt install zlib1g-dev -y

Installing zlib From Source

Zlib is an open-source project. This allows us to grab the source code and build the package ourselves. However, this procedure comes with various inconveniences, such as requiring manual management of the package.

First, install the necessary tools for building zlib:

Sponsored
$ sudo apt install build-essential -y

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

$ wget https://zlib.net/zlib-1.2.12.tar.gz

Next, extract the archive using 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 is finished compiling, install it using the following command:

$ sudo make install

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

$ sudo make uninstall

Conclusion

In this guide, we explored various ways of installing zlib on Ubuntu. We installed the zlib packages (zlib1g and zlib1g-devel) using APT. We also showcased building and installing zlib from source (applicable in specific scenarios).

Interested in learning more about compression in Linux? Check out Linux file compression options and their comparisons. Zstd is another interesting compression algorithm worth looking into.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

5 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

6 days ago