Installing Zlib from Source Code in Ubuntu Linux

Posted on In Linux, QA, Tutorial

Zlib 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.

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.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

8 comments

    1. i believe you have to install “build-essential” if not you need to install “make”
      sudo apt install build-essential

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *