How to install the zlib library in Ubuntu?

On Ubuntu (18.04), installing zlib reported unable to locate package zlib:

$ sudo apt install zlib
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package zlib

How to install zlib in Ubuntu?

In Ubuntu, the zlib package is zlib1g.

$ sudo apt show zlib1g
Package: zlib1g
Version: 1:1.2.11.dfsg-0ubuntu2
Priority: required
Section: libs
Source: zlib
Origin: Ubuntu
Maintainer: Ubuntu Developers <>
Original-Maintainer: Mark Brown <>
Installed-Size: 173 kB
Provides: libz1
Depends: libc6 (>= 2.14)
Conflicts: zlib1 (<= 1:1.0.4-7)
Breaks: libxml2 (<< 2.7.6.dfsg-2), texlive-binaries (<< 2009-12)
Task: minimal
Supported: 5y
Download-Size: 56.5 kB
APT-Manual-Installed: yes
APT-Sources: bionic/main amd64 Packages
Description: compression library - runtime
 zlib is a library implementing the deflate compression method found
 in gzip and PKZIP.  This package includes the shared library.

You may install them by

$ sudo apt install zlib1g

If you would install the development package:

$ sudo apt install zlib1g-dev

And if you would link against zlib in your program, add -lz to the gcc or g++ commands.

Download Zlib by using the following command :
Extract the file from the downloaded package:
tar -xvzf zlib-1.2.3.tar.gz
Enter the directory where the package is extracted:
cd zlib-1.2.3
Now configure Zlib directory:
./configure –prefix=/usr/local/zlib
Replace "/usr/local/zlib" above with the directory path where you want to copy the files and folders. Check whether you get any error message. Compile and install Zlib. If you are root run the following:
sudo make install
Library has bee successfully installed.

One comment:

Leave a Reply

Your email address will not be published. Required fields are marked *