Installing Zlib in Ubuntu 22.04

Zlib is a popular open-source compression library used by many software applications to compress and decompress data. It provides fast and efficient compression and decompression algorithms that can be used to reduce the size of data, which can improve performance and reduce storage requirements. In this post, we will discuss how to install zlib in Ubuntu 22.04. We will also demonstrated how to test that zlib is working correctly by compressing and decompressing a sample file. After these steps, you should have zlib installed on your Ubuntu 22.04 system.

Update the package list

Before we begin, it’s a good idea to update the package list on your Ubuntu system to ensure that you have the latest information on available packages. You can do this by running the following command in the terminal:

sudo apt update

Install zlib

To install zlib in Ubuntu 22.04, you can use the apt package manager. The zlib package is available in the default Ubuntu repositories, so you can install it by running the following command in the terminal:

sudo apt install zlib1g zlib1g-dev

This command will download and install the zlib1g-dev package, which contains the development files and headers needed to compile software that uses zlib.

Example output:

$ sudo apt install zlib1g-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 164 kB of archives.
After this operation, 606 kB of additional disk space will be used.
Get:1 jammy-security/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu9.2 [164 kB]
Fetched 164 kB in 1s (124 kB/s)      
Selecting previously unselected package zlib1g-dev:amd64.
(Reading database ... 509962 files and directories currently installed.)
Preparing to unpack .../zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu9.2_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu9.2) ...
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu9.2) ...
Processing triggers for man-db (2.10.2-1) ...

Verify the installation of zlib dev

Once the installation is complete, you can verify that zlib is installed on your system by checking files. You can do this by running the following command in the terminal:

dpkg -L zlib1g-dev

This command should output the files of zlib that is installed on your system. One example output is as follows.

$ dpkg -L zlib1g-dev 

Build a C program that uses zlib dev

We can also build a C program calling zlib to verify it is ready to use by C++ program.

gcc zpipe.c -o zpipe -lz

If gcc returns no error, congratulations that Zlib is ready in your Ubuntu 22.04.

Leave a Reply

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