How to Install zlib on Ubuntu 22.04 | 20.04

Zlib is a powerful data compression library used in many software projects worldwide. It simplifies the process of compressing and decompressing data, making it an essential tool for any experienced developer. This small guide will explain two different methods to install Zlib on Ubuntu.

Step 1 – Update Ubuntu

Now, before you proceed to install zlib, I would suggest you update your system to ensure all system packages are up-to-date.

sudo apt update

You can list upgrades before you continue to ensure what you are updating on your system with the following command.

apt list --upgradable

If any updates are available, use the following command to begin the upgrade process.

sudo apt upgrade

Step 2 – Install Zlib

Method 1: Using the APT Package Manager

Step 1: Update package lists

Before installing zlib, it’s a good practice to update the package lists on your system to ensure that you have the latest information about available packages. Open a terminal and run the following command:

sudo apt update

Step 2: Install zlib

To install zlib, you can use the apt package manager. Run the following command:

sudo apt install zlib1g-dev

This will install the zlib development package, which contains the header files and libraries needed to develop software that uses zlib.

Method 2: Compiling and Installing from the Source

Step 1: Download the zlib source code

First, you will need to download the zlib source code from the official website. Open a terminal and navigate to the directory where you want to download the source code, then run the following command and replace “{replace with your version downloaded}” with your link, as the versions will change in the future, so it is pointless adding a command link here.

wget{replace with your version downloaded}

Step 2: Extract the source code

Next, you will need to extract the source code from the downloaded archive. Run the following command to extract the source code:

tar -xvzf zlib-{replace with your version downloaded}

Step 3: Compile and install zlib

First, install the required dependencies. These may already be installed but run the command to be sure.

sudo apt install build-essential gcc make

Next, navigate to the extracted zlib source code directory and run the following commands.

sudo make install

This will compile and install zlib on your system.


Installing zlib on Ubuntu is a straightforward process that can be completed in just a few steps. It is important to note that zlib is a widely used library, so it is highly recommended to install it if you are working on software development projects. And also, keep your system updated before installing any new packages.

See also
How to Install BleachBit on Ubuntu 22.04 or 20.04

Leave a Comment

Share to...