Install zlib on linux

Installing Zlib from Source Code in Ubuntu Linux

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:

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:

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.

Читайте также:  How to install vscode linux

If gcc returns no error, congratulations, you Zlib is ready.

Источник

How to install zlib on Ubuntu?[100% Working]

zlib is the software library for data compression and is free software distributed under the zlib License. This library is an abstraction of the DEFLATE algorithm used in the gzip file compression program. zlib is also a critical part of many software such as Linux, MacOS and iOS.

zlib provides facilities for controlling CPU and memory usage. It is possible to play with the compression level to determine the compression speed. There are also memory containment facilities that are useful in constrained memory environments such as some embedded systems.

It comes preinstalled on many operating systems. In this article, we will explain the installation on Ubuntu with 2 different methods.

Different methods to install zlib in Ubuntu

As with every Linux operating system, there is a zlib package in the Ubuntu repositories. First of all, let’s explain the package installation from the repository and then the zlib installation with the source code.

Method-1: Install zlib From Repository

Update the package list before installation:

foc@ubuntu22:~$ sudo apt update

Then look at the version in the repository:

foc@ubuntu22:~$ sudo apt search zlib zlib1g/jammy-updates,jammy-security 1:1.2.11.dfsg-2ubuntu9.2 amd64 [upgradable from: 1:1.2.11.dfsg-2ubuntu9] compression library - runtime

In Ubuntu, the zlib package is in the repository with the name zlib1g and version 1.2.11. Installation is done with the following command:

foc@ubuntu22:~$ sudo apt install zlib1g -y

After installation, the files belonging to the package are placed in the relevant directories:

foc@ubuntu22:~$ dpkg -L zlib1g /. /lib /lib/x86_64-linux-gnu /lib/x86_64-linux-gnu/libz.so.1.2.11 /usr /usr/share /usr/share/doc /usr/share/doc/zlib1g /usr/share/doc/zlib1g/changelog.Debian.gz /usr/share/doc/zlib1g/copyright /lib/x86_64-linux-gnu/libz.so.1

Method-2: Install zlib From Source Code

In this method, we will install from the source code. Version 1.2.13 is available on the official github page. Let’s download and compile.

Go to version 1.2.13 and right click on the tar.gz file and copy the link address.

install zlib

Then type the link address after the wget command in the terminal:

foc@ubuntu22:~$ wget https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz

Extract the downloaded file using tar command:

foc@ubuntu22:~$ tar -xvf zlib-1.2.13.tar.gz

Enter the file created after this process:

Читайте также:  Заикается звук linux mint

Then configure the zlib library:

foc@ubuntu22:~/zlib-1.2.13$ ./configure --prefix=/usr/local/zlib Checking for gcc. Checking for shared library support. Building shared library libz.so.1.2.13 with gcc. Checking for size_t. Yes. Checking for off64_t. Yes. Checking for fseeko. Yes. Checking for strerror. Yes. Checking for unistd.h. Yes. Checking for stdarg.h. Yes. Checking whether to use vs[n]printf() or s[n]printf(). using vs[n]printf(). Checking for vsnprintf() in stdio.h. Yes. Checking for return value of vsnprintf(). Yes. Checking for attribute(visibility) support. Yes.

When installing from the repository, the libraries were located in /lib/x86_64-linux-gnu . When installing from the source code, give the above command the directory where the libraries will be placed with the —prefix parameter.

And finally install the zlib:

foc@ubuntu22:~/zlib-1.2.13$ sudo make install [sudo] password for foc: rm -f /usr/local/zlib/lib/libz.a cp libz.a /usr/local/zlib/lib chmod 644 /usr/local/zlib/lib/libz.a cp libz.so.1.2.13 /usr/local/zlib/lib chmod 755 /usr/local/zlib/lib/libz.so.1.2.13 rm -f /usr/local/zlib/share/man/man3/zlib.3 cp zlib.3 /usr/local/zlib/share/man/man3 chmod 644 /usr/local/zlib/share/man/man3/zlib.3 rm -f /usr/local/zlib/lib/pkgconfig/zlib.pc cp zlib.pc /usr/local/zlib/lib/pkgconfig chmod 644 /usr/local/zlib/lib/pkgconfig/zlib.pc rm -f /usr/local/zlib/include/zlib.h /usr/local/zlib/include/zconf.h cp zlib.h zconf.h /usr/local/zlib/include chmod 644 /usr/local/zlib/include/zlib.h /usr/local/zlib/include/zconf.h

Installation completed successfully. The zlib library is located under the /usr/local/zlib directory:

foc@ubuntu22:~/zlib-1.2.13$ tree /usr/local/zlib/ /usr/local/zlib/ ├── include │ ├── zconf.h │ └── zlib.h ├── lib │ ├── libz.a │ ├── libz.so -> libz.so.1.2.13 │ ├── libz.so.1 -> libz.so.1.2.13 │ ├── libz.so.1.2.13 │ └── pkgconfig │ └── zlib.pc └── share └── man └── man3 └── zlib.3 6 directories, 8 files

Summary

If you need to use an up-to-date zlib library, the installation steps from the source code will help. However, if there is no such requirement, we recommend using the packages in the Ubuntu repository. Packages in the repository are always stable and previously tested packages.

For more detailed and up-to-date information about Zlib, you can visit zlib.net.

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Читайте также:  Линукс минт восстановление grub

Thank You for your support!!

Источник

How to Install Zlib on Ubuntu Linux

If you try installing Zlib on Ubuntu, it will throw «unable to locate package zlib» error. Here’s how to install Zlib on Ubuntu-based Linux distributions.

Zlib is an open source library for used for data compression. As an end user, you are likely to encounter the need of installing Zlib (or zlib devel package) as a dependency of another application. But here comes the problem. If you try installing Zlib on Ubuntu, it will throw “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? Because there is no package named zlib. If you use the apt search command, you’ll find that the there are a couple of packages that let you install zlib: zlib1g and zlib1g-dev. When you have that information, installing them is just one apt command away.

Install Zlib on Ubuntu-based Linux distributions

Please keep in mind that the the letter before g is 1 (one), not lowercase L. Many people make this mistake while typing the command. The other package, zlib1g-dev is development package. Only install it if you require it otherwise you should be good with the main runtime zlib1g package.

sudo apt install zlib1g-dev

You may also download the source code of Zlib from its website and install it. However, I won’t recommend going the source code way just for installing zlib unless you have a good reason to do so. For example, if you need the latest or a specific version of zlib which is not available in the distribution’s repository. It is interesting how seemingly small stuff like installing zlib could become a pain for two reasons: a different package name and the package name containing a “hidden” numeral one (1) which is confused with a lowercase L. I hope this quick tip helps you. Feel free to drop your questions, suggestions or a simple “thank you” in the comment section.

Источник

Оцените статью
Adblock
detector