If you try to install zlib on Ubuntu, it will throw an "unable to locate package zlib" error.
Zlib is an open-source library for data compression.
As a user, you may encounter situations where you need to install zlib (or zlib-devel package) as a dependency for another application.
But here's the problem, if you try to install zlib on Ubuntu, it will throw an "unable to locate package zlib" error.
sudo apt install zlib
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package zlib
Why do you see this "Unable to locate package" error? It's because there is no package named zlib.
If you use the apt search command, you will find several packages that allow you to install zlib: zlib1g and zlib1g-dev. Once you know these, you just need one apt command to install them.
Installing Zlib on Ubuntu-based Linux Distributions#
Open a terminal and use the following command:
sudo apt install zlib1g
Please note that the letter before "g" is the number 1, not the lowercase letter L. Many people make this mistake when entering the command.
Another package, zlib1g-dev, is the development package. Only install it if you need it, otherwise, you should use the zlib1g package.
sudo apt install zlib1g-dev
You can also download the source code from the Zlib website and install it. However, I do not recommend using the source code method to install zlib unless you have a good reason to do so. For example, if you need the latest or a specific version of zlib that is not available in the distribution's repository.
Interestingly, something as seemingly small as installing zlib can become tricky for two reasons: different package names and the inclusion of the "hidden" number 1, which can be confused with the lowercase letter L.
References#
Zlib [1]