Installing zlib through source code on Ubuntu Linux

This short tutorial shows you how to install zlib on Ubuntu Linux Server. The process is very simple. For this tutorial, I'll be installing zlib version 1.2.3. Linux kernel is 2.6.15-26-powerpc. I have used a Mac Mini (powerpc/ppc architecture). GCC version number is 4.0.3. Your configuration may be different from mine but the installation steps below should work fine for most configurations with little or no change at all (including other Linux distributions and even unixes e.g. MacOS X).


According to,

"zlib is designed to be a free, general-purpose, legally unencumbered -- that is, not covered by any patents -- lossless data-compression library for use on virtually any computer hardware and operating system. The zlib data format is itself portable across platforms. Unlike the LZW compression method used in Unix compress(1) and in the GIF image format, the compression method currently used in zlib essentially never expands the data. (LZW can double or triple the file size in extreme cases.) zlib's memory footprint is also independent of the input data and can be reduced, if necessary, at some cost in compression."

Before starting, please check to see if there is a latest version available to download. Visit to find out about the available versions. IMPORTANT: See "Configuring Ubuntu Linux After Installation" to install the development tools required to compile and install zlib from source code.

Steps to download, compile, and install are as follows. Note: Replace 1.2.3 with your version number:

Downloading zlib:

Run the command below,

Extracting files from the downloaded package:

tar -xvzf zlib-1.2.3.tar.gz

Now, enter the directory where the package is extracted.

cd zlib-1.2.3

Configuring zlib Library:

./configure --prefix=/usr/local/zlib

Replace "/usr/local/zlib" above with the directory path where you want to copy the files and folders. Note: check for any error message.

Compiling zlib:


Note: check for any error message.

Installing zlib:

As root (for privileges on destination directory), run the following.

With sudo,

sudo make install

Without sudo,

make install

Note: check for any error messages.

That’s it. Library has bee successfully installed.

Did this tutorial help a little? How about buy me a cup of coffee?

Buy me a coffee at

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.

IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.

Comments (write a comment):

hey man, thx for sharing. But after I installed it, how could i use it? is it possible i use it like winrar or gzip Posted by: guang on Nov 26, 2012

when i try to install the zlib software under /home/regcm/intelsoft/src it shows error:
linux-to7r:/home/regcm/intelsoft/src # cd zlib-1.2.7
linux-to7r:/home/regcm/intelsoft/src/zlib-1.2.7 # make
/path/to/gcc -O3 -xHost -axSSE4.2 -fPIC -DNO_FSEEKO -DNO_STRERROR -DNO_snprintf -DHAS_sprintf_void -I. -c -o example.o test/example.c
make: /path/to/gcc: Command not found
make: *** [example.o] Error 127
linux-to7r:/home/regcm/intelsoft/src/zlib-1.2.7 #
so i request your good self to kindly help and guide me in this regard.
M.Muslim Posted by: Mohammad M on Apr 12, 2013

@guang: its a library that is used by other programs not an executable as far as I know. Posted by: shahryar on May 27, 2013

@Mohammad: looks like gcc is missing ... did you install build tools and compilers etc?

see: Posted by: shahryar on May 27, 2013

Can anyone pls guide me as to how to use zlib in ubuntu?when I run example.c through gcc -o example example.c -lz
i dont get any errors but what next?

TIA Posted by: Priya A on Jul 04, 2013

i want to install netcdf 4.1.3 version in linux centOS 6.5. before that i have install zlib. i have installed zlib without any errors..but while installing netcdf i get the following error while making kindly help me in this regard
/usr/bin/ld: /usr/local/cube/zlib/lib/libz.a(compress.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/cube/zlib/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [] Error 1
make[2]: Leaving directory `/root/Desktop/model/hdf5-1.8.13/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/Desktop/model/hdf5-1.8.13/src'
make: *** [all-recursive] Error 1 Posted by: xxzz on Sep 22, 2014

how can i find whether zlib is installed or not?? Posted by: vignesh on Feb 09, 2015

Thank you this tutorial was really helpeful Posted by: Tandavala on Sep 23, 2015

leave a comment on tutorial leave a comment