How to execute older version of free utility

I have described differences between old and new free output format, so now I want to mention how to execute the former free version on Debian Stretch using LD_LIBRARY_PATH environment variable to temporarily substitute a different library for this particular execution.

Operating system version.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 9.4 (stretch)
Release:        9.4
Codename:       stretch

free utility is provided by the procps package.

$ dpkg-query -S /usr/bin/free
procps: /usr/bin/free

List available procps and libprocps packages. You can inspect Debian Jessie - procps detail using web-browser.

$ curl --silent http://ftp.us.debian.org/debian/pool/main/p/procps/ | sed -n -e "/_amd64\.deb/ {s/.*<a.*>\(.*\)<\/a>.*/\1/;p}"
libprocps-dev_3.3.12-3_amd64.deb
libprocps-dev_3.3.12-4_amd64.deb
libprocps0-dev_3.3.3-3_amd64.deb
libprocps0_3.3.3-3_amd64.deb
libprocps3-dev_3.3.9-9_amd64.deb
libprocps3_3.3.9-9_amd64.deb
libprocps6_3.3.12-3_amd64.deb
libprocps6_3.3.12-4_amd64.deb
procps_3.3.3-3_amd64.deb
procps_3.3.9-9_amd64.deb
procps_3.3.12-3_amd64.deb
procps_3.3.12-4_amd64.deb

Create temporary directory and enter it.

$ mkdir jessie-free
$ cd jessie-free

Create packages directory.

jessie-free$ mkdir packages

Download procps 3.3.9-9 that is used on Debian Jessie.

# wget --directory-prefix packages http://ftp.us.debian.org/debian/pool/main/p/procps/procps_3.3.9-9_amd64.deb
--2018-03-31 15:21:10--  http://ftp.us.debian.org/debian/pool/main/p/procps/procps_3.3.9-9_amd64.deb
Resolving ftp.us.debian.org (ftp.us.debian.org)... 208.80.154.15, 128.30.2.26, 128.61.240.89, ...
Connecting to ftp.us.debian.org (ftp.us.debian.org)|208.80.154.15|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 235612 (230K) [application/octet-stream]
Saving to: _packages/procps_3.3.9-9_amd64.deb_

procps_3.3.9-9_amd64.deb                                  100%[=====================================================================================================================================>] 230.09K   671KB/s    in 0.3s

2018-03-31 15:21:10 (671 KB/s) - _packages/procps_3.3.9-9_amd64.deb_ saved [235612/235612]

Create bin directory.

jessie-free$ mkdir bin 

Display package contents.

jessie-free$ ar t packages/procps_3.3.9-9_amd64.deb
debian-binary
control.tar.gz
data.tar.xz

Extract data.tar.xz archive that contains program files.

jessie-free$ ar -vx packages/procps_3.3.9-9_amd64.deb data.tar.xz
x - data.tar.xz

Search for free binary.

jessie-free$ xz --decompress --stdout data.tar.xz | tar --list  --wildcards --file - .*free
./usr/bin/free

Extract free binary.

jessie-free$ xz --decompress --stdout data.tar.xz | tar --extract --strip-components 3 --verbose --directory bin --file - ./usr/bin/free
./usr/bin/free

Delete data.tar.xz archive.

jessie-free$ rm data.tar.xz

Inspect extracted file.

jessie-free$ file bin/free
bin/free: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=1c8c568fca62e6d1472643dd9aad39632fe24cb2, stripped

Inspect missing libraries.

jessie-free$ ldd bin/free
        linux-vdso.so.1 (0x00007ffd3bb9e000)
        libprocps.so.3 => not found
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1bb9fca000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1bb9c2b000)
        /lib64/ld-linux-x86-64.so.2 (0x000055a7a9468000)
libprocps.so file is provided by the corresponding libprocps package.

$ dpkg-query -S libprocps.so
libprocps6:amd64: /lib/x86_64-linux-gnu/libprocps.so.6
libprocps6:amd64: /lib/x86_64-linux-gnu/libprocps.so.6.0.0

Create libs directory.

jessie-free$ mkdir libs

Download libprocps3 package.

$ wget --directory-prefix packages http://ftp.us.debian.org/debian/pool/main/p/procps/libprocps3_3.3.9-9_amd64.deb
--2018-03-31 15:40:11--  http://ftp.us.debian.org/debian/pool/main/p/procps/libprocps3_3.3.9-9_amd64.deb
Resolving ftp.us.debian.org (ftp.us.debian.org)... 128.61.240.89, 208.80.154.15, 128.30.2.26, ...
Connecting to ftp.us.debian.org (ftp.us.debian.org)|128.61.240.89|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 56320 (55K) [application/octet-stream]
Saving to: _packages/libprocps3_3.3.9-9_amd64.deb_

libprocps3_3.3.9-9_amd64.deb                              100%[=====================================================================================================================================>]  55.00K   270KB/s    in 0.2s

2018-03-31 15:40:12 (270 KB/s) - _packages/libprocps3_3.3.9-9_amd64.deb_ saved [56320/56320]

Display package contents.

jessie-free$ ar t packages/libprocps3_3.3.9-9_amd64.deb
debian-binary
control.tar.gz
data.tar.xz

Extract data.tar.xz archive that contains program files.

jessie-free$ ar vx packages/libprocps3_3.3.9-9_amd64.deb data.tar.xz
x - data.tar.xz

Search for libprocps.so library files.

jessie-free$ xz --decompress --stdout data.tar.xz | tar --list  --wildcards --file - .*/libprocps\.so.*
./lib/x86_64-linux-gnu/libprocps.so.3.0.0
./lib/x86_64-linux-gnu/libprocps.so.3

Extract free binary.

jessie-free$ xz --decompress --stdout data.tar.xz | tar --extract --strip-components 3 --verbose --directory libs --wildcards --file - ./lib/x86_64-linux-gnu/libprocps.so.*
./lib/x86_64-linux-gnu/libprocps.so.3.0.0
./lib/x86_64-linux-gnu/libprocps.so.3

Delete data.tar.xz archive.

jessie-free$ rm data.tar.xz

Use LD_LIBRARY_PATH to temporarily indicate location of the additional directory (or colon-separated directories) which will be searched first for available libraries, before the standard set of directories to ensure that there are no missing ones.

jessie-free$ LD_LIBRARY_PATH=./libs/ ldd bin/free
        linux-vdso.so.1 (0x00007fff24abb000)
        libprocps.so.3 => ./libs/libprocps.so.3 (0x00007efeb374c000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007efeb3545000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efeb31a6000)
        /lib64/ld-linux-x86-64.so.2 (0x00005629ffe59000)

Execute free command using LD_LIBRARY_PATH environment variable.

jessie-free$ LD_LIBRARY_PATH=./libs/ bin/free -m
             total       used       free     shared    buffers     cached
Mem:         15975         61      15913        658          0         56
-/+ buffers/cache:          4      15970
Swap:        15623        910      14713

Directory tree created during previous steps.

jessie-free$ tree -A
.
├── bin
│   └── free
├── libs
│   ├── libprocps.so.3 -> libprocps.so.3.0.0
│   └── libprocps.so.3.0.0
└── packages
    ├── libprocps3_3.3.9-9_amd64.deb
    └── procps_3.3.9-9_amd64.deb

3 directories, 5 files

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.