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:
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.
How to install zlib from source on Ubuntu (not recommended)
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:
After that, configure the zlib:
If you want to use a different path to copy files, sure, you can use a different directory rather than
Next, compile the zlib:
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:
I hope you will find this guide helpful.
And if you have suggestions or queries, feel free to let me know in the comments.