Installing Zlib from Source Code in Ubuntu Linux
Posted on In Linux, QA, TutorialZlib is a popular open-source compression library used by many software applications to compress and decompress data. While it can be installed in Ubuntu using the apt package manager, you may need to install it from the source code if the version available in the Ubuntu repositories is outdated or if you need to customize the installation. In this post, we will discuss how to install zlib in Ubuntu from the zlib source code.
Table of Contents
Download the zlib source code
The first step is to download the zlib source code. You can download the latest version of zlib from the official website at https://zlib.net/. Alternatively, you can download the source code using the following command in the terminal:
wget https://zlib.net/zlib-1.2.11.tar.gz
This command will download the zlib source code in a compressed tar archive.
Extract the source code
Next, you need to extract the source code from the compressed tar archive. You can do this using the following command:
tar -xf zlib-1.2.11.tar.gz
This command will extract the source code into a directory called “zlib-1.2.11”.
Compile and install zlib
To compile and install zlib from the source code, you need to navigate to the directory where the source code was extracted and run the following commands:
cd zlib-1.2.11
./configure
make
sudo make install
The ./configure
command will configure the build system, make
will compile the code, and sudo make install
will install the compiled binaries and headers to their respective directories.
Verify the installation of Zlib
Once the installation is complete, you can verify that zlib is installed on your system by checking the files install in the previous step.
We can also build a C program calling zlib to verify it is ready to use by C++ program.
wget http://zlib.net/zpipe.c
gcc zpipe.c -o zpipe -lz
If gcc
returns no error, congratulations, you Zlib is ready.
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