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 <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Mark Brown <broonie@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
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)
Homepage: http://zlib.net/
Task: minimal
Supported: 5y
Download-Size: 56.5 kB
APT-Manual-Installed: yes
APT-Sources: http://hk.archive.ubuntu.com/ubuntu 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):
wget http://www.zlib.net/zlib-VERSION.tar.gz
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.
Thanks!!! This help me so much!!
thanks!!!!!!!!!!!!!!!!!
“Library has bee successfully installed.”
Thanks for tutorial, but at the last make command…it says…sudo: make: command not found
i believe you have to install “build-essential” if not you need to install “make”
sudo apt install build-essential
Very thanks.
Note that the “zlib1g” library has a 1 (one) in it, not an L (ell).
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