Installing Zlib from Source Code in Ubuntu Linux

This guide provides a step-by-step process to install Zlib from source code on Ubuntu Linux. Follow the commands and their expected outputs for a successful installation.
1. Install Build Dependencies
Install the necessary tools for compiling Zlib:
1 | sudo apt update |
Expected Output:
The system updates the package list and installs build-essential
(GCC, make, etc.) and checkinstall
.
2. Download Zlib Source Code
Download the latest Zlib source code:
1 | wget https://zlib.net/zlib-1.2.11.tar.gz |
Expected Output:
A file named zlib-1.2.11.tar.gz
is downloaded to the current directory.
3. Extract the Source Code
Extract the tarball:
1 | tar -xvzf zlib-1.2.11.tar.gz |
Expected Output:
A directory named zlib-1.2.11
is created, containing the source code.
4. Navigate to the Source Directory
Move into the extracted directory:
1 | cd zlib-1.2.11 |
Expected Output:
The terminal is now inside the zlib-1.2.11
directory.
5. Configure the Build
Run the configuration script:
1 | ./configure --prefix=/usr/local/zlib |
Expected Output:
The script checks the system and prepares the build environment. Example output:
1 | Checking for gcc... |
6. Compile the Source Code
Compile Zlib using make
:
1 | make |
Expected Output:
The system compiles the source code. Example output:
1 | gcc -O3 -D_LARGEFILE64_SOURCE=1 -I. -c -o example.o test/example.c |
7. Install Zlib
Install the compiled Zlib library:
1 | sudo make install |
Expected Output:
The library is installed to /usr/local/zlib
. Example output:
1 | Installing shared library: /usr/local/zlib/lib/libz.so.1.2.11 |
8. Verify the Installation
Check the installed version of Zlib:
1 | /usr/local/zlib/lib/libz.so.1.2.11 --version |
Expected Output:
The version information is displayed:
1 | zlib 1.2.11 |
9. Update the Library Cache
Update the system’s library cache:
1 | sudo ldconfig |
Expected Output:
No output if successful. The system updates the library cache.
Conclusion
You have successfully installed Zlib from source code on Ubuntu Linux. This method allows for custom configurations and specific version installations. For further details, refer to the official Zlib documentation.