How to install zlib on Ubuntu?[100% Working]


Author: Omer Cakmak
Reviewer: Deepak Prasad

Introduction to Zlib

zlib is the software library for data compression and is free software distributed under the zlib License. This library is an abstraction of the DEFLATE algorithm used in the gzip file compression program. zlib is also a critical part of many software such as Linux, MacOS and iOS.

zlib provides facilities for controlling CPU and memory usage. It is possible to play with the compression level to determine the compression speed. There are also memory containment facilities that are useful in constrained memory environments such as some embedded systems.

It comes preinstalled on many operating systems. In this article, we will explain the installation on Ubuntu with 2 different methods.


Different methods to install zlib in Ubuntu

As with every Linux operating system, there is a zlib package in the Ubuntu repositories. First of all, let's explain the package installation from the repository and then the zlib installation with the source code.


Method-1: Install zlib From Repository

Update the package list before installation:

foc@ubuntu22:~$ sudo apt update

Then look at the version in the repository:

foc@ubuntu22:~$ sudo apt search zlib

zlib1g/jammy-updates,jammy-security 1:1.2.11.dfsg-2ubuntu9.2 amd64 [upgradable from: 1:1.2.11.dfsg-2ubuntu9]
compression library - runtime

In Ubuntu, the zlib package is in the repository with the name zlib1g and version 1.2.11.  Installation is done with the following command:

foc@ubuntu22:~$ sudo apt install zlib1g -y

After installation, the files belonging to the package are placed in the relevant directories:

foc@ubuntu22:~$ dpkg -L zlib1g


Method-2: Install zlib From Source Code

In this method, we will install from the source code. Version 1.2.13 is available on the official github page. Let's download and compile.

Go to version 1.2.13 and right click on the tar.gz file and copy the link address.

install zlib


Then type the link address after the wget command in the terminal:

foc@ubuntu22:~$ wget

Extract the downloaded file using tar command:

foc@ubuntu22:~$ tar -xvf zlib-1.2.13.tar.gz

Enter the file created after this process:

foc@ubuntu22:~$ cd zlib-1.2.13/

Then configure the zlib library:

foc@ubuntu22:~/zlib-1.2.13$ ./configure --prefix=/usr/local/zlib
Checking for gcc...
Checking for shared library support...
Building shared library with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.

When installing from the repository, the libraries were located in /lib/x86_64-linux-gnu. When installing from the source code, give the above command the directory where the libraries will be placed with the --prefix parameter.

Then compile the zlib:

foc@ubuntu22:~/zlib-1.2.13$ make

And finally install the zlib:

foc@ubuntu22:~/zlib-1.2.13$ sudo make install
[sudo] password for foc:
rm -f /usr/local/zlib/lib/libz.a
cp libz.a /usr/local/zlib/lib
chmod 644 /usr/local/zlib/lib/libz.a
cp /usr/local/zlib/lib
chmod 755 /usr/local/zlib/lib/
rm -f /usr/local/zlib/share/man/man3/zlib.3
cp zlib.3 /usr/local/zlib/share/man/man3
chmod 644 /usr/local/zlib/share/man/man3/zlib.3
rm -f /usr/local/zlib/lib/pkgconfig/zlib.pc
cp zlib.pc /usr/local/zlib/lib/pkgconfig
chmod 644 /usr/local/zlib/lib/pkgconfig/zlib.pc
rm -f /usr/local/zlib/include/zlib.h /usr/local/zlib/include/zconf.h
cp zlib.h zconf.h /usr/local/zlib/include
chmod 644 /usr/local/zlib/include/zlib.h /usr/local/zlib/include/zconf.h

Installation completed successfully. The zlib library is located under the /usr/local/zlib directory:

foc@ubuntu22:~/zlib-1.2.13$ tree /usr/local/zlib/
├── include
│   ├── zconf.h
│   └── zlib.h
├── lib
│   ├── libz.a
│   ├── ->
│   ├── ->
│   ├──
│   └── pkgconfig
│   └── zlib.pc
└── share
└── man
└── man3
└── zlib.3

6 directories, 8 files



If you need to use an up-to-date zlib library, the installation steps from the source code will help. However, if there is no such requirement, we recommend using the packages in the Ubuntu repository. Packages in the repository are always stable and previously tested packages.

For more detailed and up-to-date information about Zlib, you can visit


Views: 130
Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

Leave a Comment