Learn and Discover Open Source with Daily Genuine Experience. From Coding, Design, Package Management Tweak to Desktop Customization.
 
   

Table of Content

This is a four-parts article. There are few sections here.

Part One
  • Preface: Test Bed, Must Read
  • Getting Started With Docker
  • Package Management: DPKG Frontend, APT Frontend, Get Help, The new APT, APT Shell
  • Updating System: OS Release, Refresh Update, List Upgradable, Upgrade
  • Package IRSIF: Install, Download, Removal, Unused Dependency, Query Search, Show Info, List Files, Extract
  • What's Next
Part Two
  • Group: Task
  • Package More: Change Log, Policy, aptitude, dselect, configure, Search Files, dlocate, Unused Dependency
  • System Wide: Statistics, List Packages, Config, Verify
  • History: The Log File
  • Clean Up: Clean, Unused Dependency, Orphan
  • What's Next
Part Three
  • Dependency: Dependency, Reverse Dependency, Test
  • Hold Package: Building Example, Mark Hold, Pinning
  • Repository: Configuration, Policy, Add Repository, Mirror
  • Distribution Upgrade
  • Repository Pinning: nmap Case, New Docker for Stretch, Stable nmap, Pinning Unstable, Unstable nmap
  • What's Next
Part Four
  • Build from Source: The Toolchain, Source Repository, User Privilege, Build Directory, Example, Download Source, Build Source, Examine Directory, Install Result
  • Developer Script: debcheckout, Build Dependency, Build Package, Lintian, Source Compile, debi, Deb Checksums, Show Source
  • Conclusion

Preface

Goal: Examine Package Manager, Focus on Command Line Interface

Using Debian minimal install in Docker, is a good way to learn The Advance Package Tool. APT is considered a basic knowledge utilized by Debian’s derived distribution such as Ubuntu, Mint, Elementary, Zorin, Kali Linux, Parrot, Cyborg, and some other cool Distribution.

We only need Stretch stable release. We will switch to testing later on part three, so that we have a chance to play more with package cycle.

Test Bed

  1. Container: Docker

  2. Operating System: Artix (OpenRC )

  3. Window Manager: Herbstluftwm

Since we are going to use docker again, you can read a common overview here.

Of course you can use virtualization, the issue is distraction. We need to avoid tendency to focus on GUI tools. At the same time, limiting the scope to CLI tools. Most of the time, CLI tools is considered lower level than the GUI one.

Must Read

You are encouraged to read this first, before even starting to read this article.

There are already so many references for this APT. This is just another reference. I think that I’m late. I should have write these ten years ago.


Getting Started With Docker

As usual, first, we do attach docker process.

$ docker pull debian:stretch

Docker Pull Debian Strecth

$ docker image list  

  --filter "reference=debian:*"
  --format 'table {{.Repository}}\t{{.Size}}'

REPOSITORY          SIZE
debian              100MB

By the container image size, Debian is good at managing minimal install.

$ docker run -it debian:stretch
root@f77ea94688d1:/# exit
exit

Docker Debian: Running Docker

$ docker ps

  --format 'table {{.Image}}\t{{.Names}}\t{{.Status}}'

IMAGE               NAMES               STATUS
debian:stretch      goofy_allen         Up 7 minutes

Docker Debian: Docker ps

$ docker start goofy_allen
goofy_allen
$ docker attach goofy_allen
root@f77ea94688d1:/# 

Docker Debian: Getting Started


Package Management

Debian utilize APT, The Advanced Package Tool. APT has a lower level tool caled dpkg that handle .deb package files.

It has many front end,

DPKG Frontend

Last updated Eight Years Ago.

APT Frontend

Get Help

Read the fine manual.

$ apt help

Note that with minimal install in docker, we do not have man-db and less yet.

$ man apt

The new APT

I have been a Debian user since 2007. It means a decade. My hand automatically type every few days.

$ apt-get update
$ apt-get upgrade
$ apt-get autoremove
$ apt-get autoclean

Whenever there is a conflict, I use aptitude instead of apt-get.

But this is going to change. Now we have apt instead of apt-get. apt is a combination of most common command from apt-get and apt-cache.

Now you can see there are some front end. Our focus now is apt.

APT Shell

There also APT shell, separated from the official APT that enable user to focus on the task of managing package.

$ aptsh
Generating and mapping caches...
Reading commands history...
 apt sh > 

Note that with minimal install in docker, we do not have aptsh.

I personally never use this aptsh.


Updating System

First Thing First

First thing to do is updating my system as usual.

  • OS Release

  • Update

  • List Upgradable

  • Upgrade

OS Release

$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
...

Refresh Update

$ apt-get update

Almost equal to:

$ apt update
Get:1 http://security.debian.org stretch/updates InRelease [62.9 kB]
Get:2 http://security.debian.org stretch/updates/main amd64 Packages [200 kB]
Ign:3 http://deb.debian.org/debian stretch InRelease
Get:4 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:5 http://deb.debian.org/debian stretch Release [118 kB]        
Get:6 http://deb.debian.org/debian stretch-updates/main amd64 Packages [5553 B]
Get:7 http://deb.debian.org/debian stretch Release.gpg [2373 B]    
Get:8 http://deb.debian.org/debian stretch/main amd64 Packages [9497 kB]
Fetched 9977 kB in 22s (444 kB/s)                                                    
Reading package lists... Done
Building dependency tree       
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.

Alternatively:

$ aptitude update
aptitude update 
Ign http://deb.debian.org/debian stretch InRelease
Hit http://deb.debian.org/debian stretch-updates InRelease
Hit http://deb.debian.org/debian stretch Release
Hit http://security.debian.org stretch/updates InRelease

Docker APT: Update

List Upgradable

just relax, folow what the command above, told us to do to list upgradable packages.

$ apt list --upgradable -a
Listing... Done
libgcrypt20/stable 1.7.6-2+deb9u2 amd64 [upgradable from: 1.7.6-2+deb9u1]
libgcrypt20/stable,now 1.7.6-2+deb9u1 amd64 [installed,upgradable to: 1.7.6-2+deb9u2]

Docker APT: List Upgradable

Upgrade

$ apt-get upgrade

Almost equal to:

$ apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Alternatively:

$ aptitude upgrade

Docker APT: Upgrade

Full Upgrade

There is also this full-upgrade, that resolve dependency conflict automatically.

$ apt-get full-upgrade

Almost equal to:

$ apt full-upgrade

Alternatively:

$ aptitude full-upgrade

There is however.

$ aptitude safe-upgrade

And later we will discuss

$ apt dist-upgrade

Package IRSIF

Install, Remove, Search, Info, File

Package Install

Consider our favorite example package below. This will have a verbose long output.

$ apt-get install htop ncdu fish wget curl vim sudo aptitude

Almost equal to:

$ apt install man-db nano less aptsh  
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  bsdmainutils groff-base libbsd0 libgdbm3 libgpm2 libncurses5
  libpipeline1 libreadline5 readline-common
Suggested packages:
  cpp wamerican | wordlist whois vacation groff gpm www-browser
  spell readline-doc
The following NEW packages will be installed:
  aptsh bsdmainutils groff-base less libbsd0 libgdbm3 libgpm2
  libncurses5 libpipeline1 libreadline5 man-db nano
  readline-common
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 3511 kB of archives.
After this operation, 9857 kB of additional disk space will be used.
Do you want to continue? [Y/n]
...

Alternatively:

$ aptitude install man-db nano less aptsh
man-db is already installed at the requested version (2.7.6.1-2)
nano is already installed at the requested version (2.7.4-1)
less is already installed at the requested version (481-2.1)
aptsh is already installed at the requested version (0.0.8)
man-db is already installed at the requested version (2.7.6.1-2)
nano is already installed at the requested version (2.7.4-1)
less is already installed at the requested version (481-2.1)
aptsh is already installed at the requested version (0.0.8)
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.

Docker APT: Install

You can add -y to avoid confirmation. This will assume yes for each confirmation.

$ apt-get install -y htop ncdu fish wget curl vim sudo aptitude

Download

There are two ways to download package without installing.

$ apt-get install --download-only ncdu
...
Get:1 http://deb.debian.org/debian testing/main amd64 ncdu amd64 1.12-1+b1 [41.3 kB]
Fetched 41.3 kB in 1s (27.8 kB/s)
Download complete and in download only mode

Docker Debian: Cache

The package will be in cache.

$ ls /var/cache/apt/archives/
lock  ncdu_1.12-1+b1_amd64.deb	partial

Docker APT: Download Only

The next time you do install, it does need to download anymore, because the package is alre4ady in the cache.

Alternatively you can bypass the cache.

$ cd ~
$ apt-get download htop
Get:1 http://deb.debian.org/debian testing/main amd64 htop amd64 2.0.2-1 [88.2 kB]
Fetched 88.2 kB in 1s (69.2 kB/s)
W: Download is performed unsandboxed as root as file '/root/htop_2.0.2-1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

Docker APT: Download

And you can install using low level dpkg later on.

$ dpkg -i htop_2.0.2-1_amd64.deb 
Selecting previously unselected package htop.
(Reading database ... 36837 files and directories currently installed.)
Preparing to unpack htop_2.0.2-1_amd64.deb ...
Unpacking htop (2.0.2-1) ...
Setting up htop (2.0.2-1) ...
Processing triggers for mime-support (3.60) ...
Processing triggers for man-db (2.7.6.1-2) ...

Docker DPKG: Install

Package Removal

There are two kind of removal in APT. It is apt remove and apt purge. The last one also purge configuration.

Consider this groff-base, that is dependency of man-db. Debian is mature in managing dependency.

$ apt-get remove groff-base

Almost equal to:

$ apt remove groff-base
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgdbm3 libpipeline1
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  groff-base man-db
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 5624 kB disk space will be freed.
Do you want to continue? [Y/n] 

Docker APT: Remove

Alternatively, with aptitude use different approach:

$ aptitude remove groff-base
The following packages will be REMOVED:  
  groff-base 
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 3339 kB will be freed.
The following packages have unmet dependencies:
 man-db : Depends: groff-base (>= 1.18.1.1-15) but it is not going to be installed
The following actions will resolve these dependencies:

     Remove the following packages:    
1)     man-db [2.7.6.1-2 (now, stable)]



Accept this solution? [Y/n/q/?]

Docker Aptitude: Remove

This different aptitude approach is, why I use aptitude whenever I have package conflict. Before the new apt comes out.

It is just an example. We do not realy need to delete it.

Search used to be handled by apt-cache. But the output is slightly different.

$ apt search ncdu
Sorting... Done
Full Text Search... Done
ncdu/stable 1.12-1+b1 amd64
  ncurses disk usage viewer

$ apt-cache search ncdu
ncdu - ncurses disk usage viewer

Alternatively:

$ aptitude search ncdu

Docker APT: Search

There are a lower level dpkg-query --list tool as well. I must admit this is my favorite.

$ dpkg-query --list apt*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name            Version      Architecture Description
+++-===============-============-============-====================================
ii  apt             1.4.7        amd64        commandline package manager
un  apt-doc         <none>       <none>       (no description available)
un  apt-utils       <none>       <none>       (no description available)
un  apt-xapian-inde <none>       <none>       (no description available)
ii  aptitude        0.8.7-1      amd64        terminal-based package manager
ii  aptitude-common 0.8.7-1      all          architecture independent files for t
un  aptitude-doc    <none>       <none>       (no description available)
un  aptitude-doc-en <none>       <none>       (no description available)
ii  aptsh           0.0.8        amd64        apt interactive shell

Docker DPKG: Query List

Package Show Info

Pretty straightforward.

$ apt-cache show ncdu

Almost equal to:

$ apt show ncdu
Package: ncdu
Version: 1.12-1+b1
Priority: optional
Section: admin
Source: ncdu (1.12-1)
Maintainer: Eugene V. Lyubimkin <jackyf@debian.org>
Installed-Size: 94.2 kB
Depends: libc6 (>= 2.14), libncursesw5 (>= 6), libtinfo5 (>= 6)
Homepage: http://dev.yorhel.nl/ncdu/
Tag: admin::monitoring, implemented-in::c, interface::text-mode,
 role::program, scope::utility, uitoolkit::ncurses
Download-Size: 41.3 kB
APT-Sources: http://deb.debian.org/debian stretch/main amd64 Packages
Description: ncurses disk usage viewer

Alternatively:

$ aptitude show ncdu

Docker APT: Show

This show will grab all package with respected pattern. You can narrow the result using regular expression.

$ apt search '^apt$'

There are a lower level dpkg-query --status tool as well.

$ dpkg-query --status apt
Package: apt
Status: install ok installed
Priority: important
Section: admin
Installed-Size: 3538
Maintainer: APT Development Team <deity@lists.debian.org>
Architecture: amd64
Version: 1.4.7
Replaces: apt-utils (<< 1.3~exp2~)
Depends: adduser, gpgv | gpgv2 | gpgv1, debian-archive-keyring, init-system-helpers (>= 1.18~), libapt-pkg5.0 (>= 1.3~rc2), libc6 (>= 2.15), libgcc1 (>= 1:3.0), libstdc++6 (>= 5.2)
Recommends: gnupg | gnupg2 | gnupg1
Suggests: apt-doc, aptitude | synaptic | wajig, dpkg-dev (>= 1.17.2), powermgmt-base, python-apt
Breaks: apt-utils (<< 1.3~exp2~)

Docker DPKG: Query Status

You may find dpkg -I useful to get information directly from the package.

$ dpkg-deb --info htop_2.0.2-1_amd64.deb 
 new debian package, version 2.0.
 size 88164 bytes: control archive=856 bytes.
     581 bytes,    17 lines      control              
     564 bytes,     9 lines      md5sums              
 Package: htop
 Version: 2.0.2-1
 Architecture: amd64
 Maintainer: Daniel Lange <dl.ml1@usrlocal.de>
...

Docker DPKG: Deb Info

List Files

Listing package files can be achieved using dpkg.

$ dpkg -L ncdu

Or

$ dpkg-query --listfiles ncdu
/.
/usr
/usr/bin
/usr/bin/ncdu
/usr/share
/usr/share/doc
/usr/share/doc/ncdu
/usr/share/doc/ncdu/changelog.Debian.amd64.gz
/usr/share/doc/ncdu/changelog.Debian.gz
/usr/share/doc/ncdu/changelog.gz
/usr/share/doc/ncdu/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/ncdu.1.gz

Docker DPKG: List Files

Extract

If you are a curious person, you can even extract the package.

$ dpkg-deb --extract htop_2.0.2-1_amd64.deb .

What’s Next

APT is a mature package management, so many commands that this topic deserve its own long article. Consider finish reading [ Part Two ].

Thank you for reading


Epsi Nurwijayadi bio photo
By Epsi Nurwijayadi