Linux HOWTOs

About | Home | Search


HOWTO: zlib
Description: Compression library
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything


# zlib 1.2.11 (latest stable)
# ==========
# Slackware 13.0, 13.1: zlib 1.2.3
# Slackware 13.37: zlib 1.2.5
# Slackware 14.0: zlib 1.2.6
# Slackware 14.1: zlib 1.2.8

# After upgrading the library you should restart anything linked with the
# shared library.  If the machine you're upgrading is a non-server or a
# non-critical server, it might be easier to just reboot the machine in
# some cases (lots of things use zlib).  To check to see if a binary is
# linked with zlib's shared library, try something like 'ldd /usr/bin/ssh'
# to look for a line of output like one of these:
#         libz.so.1 => /usr/lib/libz.so.1 (0x40138000)
#         libz.so.1 => /lib64/libz.so.1 (0x00007fac8f68c000)
# which shows that /usr/bin/ssh was linked with the zlib shared library. 
# You can also try (if you have lsof installed) 'lsof /usr/lib/libz.so'
# which will list currently running applications that have the zlib shared
# library opened.
#
# Rebuild and reinstall anything that was statically linked with zlib
# (libz.a).
#
# You can find a partial list of apps that use zlib here:
# http://www.gzip.org/zlib/apps.gz.html

# zlib ChangeLog

# Get it
cd
test -f installed/zlib-1.2.11.tar.xz && mv installed/zlib-1.2.11.tar.xz .
test ! -f zlib-1.2.11.tar.xz && wget http://zlib.net/zlib-1.2.11.tar.xz

# Verify tarball w/ sha256sum:
echo "4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf0\
66  zlib-1.2.11.tar.xz" | sha256sum -c

# Verify tarball w/ gpg:
( gpg --list-keys 58BCAFBA > /dev/null 2>&1 || gpg --recv-keys 58BCAFBA ) &&
 wget -nc http://www.zlib.net/zlib-1.2.11.tar.xz.asc &&
  gpg --verify zlib-1.2.11.tar.xz.asc &&
   rm zlib-1.2.11.tar.xz.asc

# Extract the source
mkdir -p -m 0700 ~/src
cd ~/src
find -maxdepth 1 -type d -name "zlib-*" -exec rm -r {} \;
tar xJvf ~/zlib-1.2.11.tar.xz
cd zlib-1.2.11
test $UID = 0 && chown -R root:root .

# Because libkmod requires libz, Slackware moves the shared library file
# (libz.so.1.2.11) up a level to /lib or /lib64.  I would imagine this is
# done in case /usr is NFS-mounted or something like that.  We pass
# sharedlibdir to configure below to get the same effect.  The shared
# library itself ends up in /lib*/ and the rest under /usr/lib*/ and that
# way the paths in the zlib.pc file are correct as well.

## configure the build
# 64-bit systems:
test $(uname -m) = "x86_64" &&
 ./configure --prefix=/usr --libdir=/usr/lib64 --sharedlibdir=/lib64
# Non-64-bit systems:
test $(uname -m) = "x86_64" || ./configure --prefix=/usr --sharedlibdir=/lib

# Build it
make

# Test the build
make test

# Become root to remove old files and install the new version
su

# If you want to see what daemon-type things are running right now that are
# using the zlib shared library, try this:
# lsof /lib*/libz.so.*
# Anything in the list is using it right now.  If you see things using, for
# example: /lib64/libz.so.1.2.6 now, after you install libz.so.1.2.11 below,
# if you restart them, you should see them using the newer one.

# Remove the Slackware package, if there is one.  zlib is in the aaa_elflibs
# package also (just elflibs in earlier versions), so there will still be a
# shared library file left in /lib or /lib64 after this.
test -x /sbin/removepkg && /sbin/removepkg zlib

# Remove the many variations of symlinks and let 'make install' create new
# ones:
test -d /lib64 && ( cd /lib64 ; rm -f libz.so.1 libz.so )
test -d /usr/lib64 && ( cd /usr/lib64 ; rm -f libz.so.1 libz.so )
test -d /lib && ( cd /lib ; rm -f libz.so.1 libz.so )
test -d /usr/lib && ( cd /usr/lib ; rm -f libz.so.1 libz.so )

# Install the new version.  It will install static (.a) and shared (.so)
# versions of libz.  The default base man directory is /usr/share/man,
# which in Slackware is usually either not there or a symlink to /usr/man.
make install mandir=/usr/man

# Now create symlinks in /usr/lib*/ pointing to the real one in /lib*/:
test -f /lib64/libz.so.1.2.11 &&
 ( ln -sf /lib64/libz.so.1.2.11 /usr/lib64/libz.so.1.2.11
   ln -sf /lib64/libz.so.1.2.11 /usr/lib64/libz.so.1
   ln -sf /lib64/libz.so.1.2.11 /usr/lib64/libz.so )
test -f /lib/libz.so.1.2.11 &&
 ( ln -sf /lib/libz.so.1.2.11 /usr/lib/libz.so.1.2.11
   ln -sf /lib/libz.so.1.2.11 /usr/lib/libz.so.1
   ln -sf /lib/libz.so.1.2.11 /usr/lib/libz.so )

# Update /etc/ld.so.cache
ldconfig

# Remove old docs, then put new ones in /usr/doc/zlib-1.2.11
find /usr/doc -maxdepth 1 -type d -name "zlib-*" -exec rm -r {} \;
mkdir -p /usr/doc/zlib-1.2.11
cp ChangeLog FAQ INDEX README /usr/doc/zlib-1.2.11/
chown -R root:root /usr/doc/zlib-1.2.11

# Now that you've installed the new version, you'll find that if you restart
# the things that showed up in the 'lsof' list above, they will start
# using the new version's shared library: /lib/libz.so.1.2.11
# (or /lib64/libz.so.1.2.11, or a symlink pointing to one of them)
# Once you are 100% sure that nothing is using the old version shared
# library file any more, you can remove it, but a tidy system is the only
# reason to bother doing that.

# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .

# Become your non-root user again
exit

# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/zlib-*.tar.* installed/zlib-*patch*.txt
mv zlib-1.2.11.tar.xz installed/

Back to the list


Last updated: Tue, 07 Aug 2018 12:06:17 -0400
Jason Englander <jason at englanders dot us>