How to Install Zlib on Ubuntu-[3 Methods]

zlib is a general-purpose data compression library widely used across Linux that implements the DEFLATE compression algorithm providing lossless compression and decompression while maintaining minimal memory usage. There are three methods to install Zlib on Ubuntu, which this guide will cover extensively.

Method 1: Through Zlib Tar File

To install the latest version of Zlib on Ubuntu using its tar file, either with .gz or .xz extension, is one of the best methods. To download the tar file, visit the zlib official website:

Downloading Zlib Tar file on Ubuntu from its offical site

Alternatively, download the zlib tar file via terminal using its download link:

wget https://zlib.net/zlib-1.3.1.tar.xz

Downloading Zlib Tar file on Ubuntu from its downlaod link

Next, extract the zlib tar file using the tar utility by executing:

sudo tar xf zlib-1.3.1.tar.xz

Extracting zlib tar file on Ubuntu

Now navigate to the Zlib extracted folder and execute the configure file to build a preparation script that will analyze the system environment, check for required dependencies, and generate a platform-specific Makefile to guide the compilation process:

cd zlib-1.3.1
sudo ./configure

Executing the configure file of zlib on Ubuntu

Next, execute the build process defined in the Makefile, typically to compile source code and install binaries into the system:

sudo make

Creating the make file for zlib on Ubuntu

Now use the make utility to install the compiled binaries, libraries, and supporting files from the build directory into the system as defined by the Makefile:

sudo make install

Installing Zlib on Ubuntu via make utility

To verify the zlib installation, use the pkg-config utility to check the version of the installed library:

pkg-config --modversion zlib

Verifying the zlib installation via version command on Ubuntu

Method 2: Through Apt Package Manager

By default, zlib comes pre-installed in Linux; however, it has an older version and lacks the developmental version. So the following command installs the simple version of zlib on Ubuntu:

sudo apt-get install zlib1g

Installing non dev version of zlib on Ubuntu via apt package manager

The development version provides the headers and libraries needed to build and compile software against zlib, to install zlib1g-dev, execute:

sudo apt-get install zlib1g-dev

Installing dev version of zlib on Ubuntu via apt package manager

The installed version of zlib1g-dev can be verified by listing apt-installed apps in Ubuntu:

sudo apt list --installed

Verifying the zlib installation via version command on Ubuntu

Method 3: Through Conda Package Manager

Conda is a package management tool that simplifies the installation, distribution, and management of software dependencies, supporting multiple programming languages. To install Zlib on Ubuntu, install Conda first using its bash script. Download the Conda bash script by executing the command below:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Downloading Conda bash File on Ubuntu to install Zlib

 

Now execute the Conda bash file by using the command below:

bash Miniconda3-latest-Linux-x86_64.sh

Executing Conda bash file on Ubuntu to install Zlib

Now reload the shell configuration file (.bashrc) into the current shell session without needing to log out or restart the terminal:

source ~/.bashrc

Reloading the shell configuration file (.bashrc) into the current shell session on Ubuntu for conda

Next, install the Zlib Library on Ubuntu using Conda package management via the command below:

conda install conda-forge::zlib

installing Zlib Library on Ubuntu using Conda package management

To verify the Zlib installation via Conda, execute the command below:

conda list zlib

Verifying the zlib installation via Conda on Ubuntu

Note: To install Zlib on Ubuntu via Conda, several commands are available, each with a different version. The following are commands that can be used:

conda install conda-forge/label/broken::zlib
conda install conda-forge/label/cf201901::zlib
conda install conda-forge/label/cf202003::zlib
conda install conda-forge/label/gcc7::zlib

Here is the simple explanation for each command:

  • label/broken: packages flagged as broken → not recommended.
  • label/cf201901, cf202003: historical snapshots from January 2019 / March 2020.
  • label/gcc7: package builds specifically tied to GCC 7 ABI compatibility.

Conclusion

Zlib is a core Linux compression library that provides fast, lossless data compression and is widely used as a dependency for applications, libraries, and system utilities. There are three ways to install Zlib on Ubuntu, which were discussed in this guide: using Zlib tar file, Zlib-dev using apt, and the Conda package installer.

 

Index
Scroll to Top