Skip to main content
How To

Install zlib on Ubuntu

Struggling to install zlib on Ubuntu? Here's how you can get zlib on Ubuntu Linux.

Sagar Sharma

The zlib is not a typical package but a software library used for data compression.

And if you are not aware, the gzip utility uses the zlib library for the data compression.

But if you'd try to perform the straightforward installation with apt, you will get the following error:

Unable to locate package zlib

It does not mean that zlib is not available in the default repository but the package name is quite different.

How to install zlib on Ubuntu

As I mentioned earlier, you must use the correct package name for the installation.

To install zlib, use the following command:

sudo apt install zlib1g

Similarly, there is another package intended for development purposes. Unless you know what you are doing, the mainline package (zlib1g) will do just fine.

And for the installation of the development package, use:

sudo apt install zlib1g-dev

Similarly, you can get the most recent version of zlib by building it from the source.

Want to learn how? Here's how you do it.

To build packages, the first step is to have the build-essentials and git package:

sudo apt install build-essential git

First, clone the zlib git repository:

git clone https://github.com/madler/zlib

Next, change the directory to zlib using the cd command:

cd zlib

After that, configure the zlib:

./configure --prefix=/usr/local/zlib

If you want to use a different path to copy files, sure, you can use a different directory rather than /usr/local/zlib.

Next, compile the zlib:

make

Finally, use the following command to complete the installation:

sudo make install 

That's it! You have the most recent version of zlib installed on your system.

Become a pro at installing packages from the source

If you are just getting started with Linux, installing packages from the source may seem like a huge deal.

And to solve that issue, we have a dedicated guide on installing packages from the source:

How to Install Software from Source Code… and Remove it Afterwards
Brief: This detailed guide explains how to install a program from source code in Linux and how to remove the software installed from the source code. One of the greatest strength of your Linux distribution is its package manager and the associated software repository. With them, you have all th…

I hope you will find this guide helpful.

And if you have suggestions or queries, feel free to let me know in the comments.

Sagar Sharma