Installing Zlib Library in Ubuntu Linux

On Ubuntu (18.04 and 20.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?

Install zlib in Ubuntu from Ubuntu package repo

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

Install zlib in Ubuntu from zlib source code

Download Zlib by using the following command (please check the version and replace the zlib version string VERSION with the version you need):


Extract the file from the downloaded package:

tar -xvzf zlib-VERSION.tar.gz

Enter the directory where the package is extracted:

cd zlib-VERSION

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.

Note about linking C/C++ programs with zlib

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


    1. i believe you have to install “build-essential” if not you need to install “make”
      sudo apt install build-essential

  1. Hi, thanks for the article:

    ‘Note about linking C/C++ programs with zlib

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

    i did not understand this.

    Any help would be appreciated,

    have a good day

Leave a Reply

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