Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Saturday, November 28, 2015 at 20:31

Every new user will experience dealing with package dependency in Ubuntu. This list is a shortcut to help you get what dependencies you want in faster way. You can choose any command you need from below. We list variety of 5 commands here dpkg, dpkg-deb, apt-rdepends, apt-cache, and apt-get. We use Ubuntu 12.04 32 bit for this article. If you are looking for package dependency searching in Ubuntu then this article is for you.

Prerequisites


  1. You must install apt-rdepends first because it is not built-in included in Ubuntu. Install it with sudo apt-get install rdepends
  2. You must at least ever once doing sudo apt-get update. It needs internet access. It builds complete APT Database for your Ubuntu. If you have no APT Database, no command apt-cache, apt-rdepends, or apt-get can be performed completely.

About APT Cache Terminology


In simplified words, APT Cache is a term to explain both APT Database and APT Package Files. APT Database is stored at /var/lib/apt/lists/. It contains plain text files stored from sudo apt-get update a user performs. APT Package Files are stored in /var/cache/apt/archives/. It contains DEB files stored from any sudo apt-get install command a user performs. apt-cache command works for these two types of cache.


1. dpkg: Show Package Information


Synopsis: dpkg -I <package> <directory>
Example: dpkg -I uget_1.8.0-1_i386.deb

This command will show control file contents including dependencies stated inside the package. The output will be like this. 

new debian package, version 2.0.
 size 193578 bytes: control archive= 1955 bytes.
     948 bytes,    23 lines      control              
    2618 bytes,    34 lines      md5sums              
     185 bytes,     7 lines   *  postinst             #!/bin/sh
     160 bytes,     5 lines   *  postrm               #!/bin/sh
 Package: uget
 Version: 1.8.0-1
 Architecture: i386
 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
 Original-Maintainer: Elías Alejandro Año Mendoza <ealmdz@gmail.com>
 Installed-Size: 736
 Depends: libc6 (>= 2.4), libcairo2 (>= 1.2.4), libcurl3 (>= 7.16.2-1), libglib2.0-0 (>= 2.20.0), libgstreamer0.10-0 (>= 0.10.0), libgtk2.0-0 (>= 2.24.0), libnotify4 (>= 0.7.0), libpango1.0-0 (>= 1.14.0)
 Section: net
 Priority: optional
 Homepage: http://urlget.sourceforge.net/
 Description: easy-to-use download manager written in GTK+2
  Uget (formerly urlgfe) is a simple, lightweight and easy-to-use
  download manager.
  It provides the following features:
   * Resume downloads.
   * Queue downloads.
   * Classify downloads in categories.
   * Mozilla Firefox integration (through Flashgot plugin).
   * Clipboard monitoring.
   * Import downloads import from HTML files.
   * Batch download.
  .
  It also can be launched from the command line.

2. dpkg-deb: Extracting DEB Package 


Synopsis: dpkg-deb --raw-extract <package> <directory>
Example: dpkg-deb --raw-extract uget_1.8.0-1_i386.deb /tmp

This command will extract DEB file named above into /tmp directory. This will produce two directories named DEBIAN and usr. What you need is to read a file named control inside DEBIAN directory. Do command cat control inside DEBIAN then it produces output exactly like this. 

Package: uget
Version: 1.8.0-1
Architecture: i386
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Elías Alejandro Año Mendoza <ealmdz@gmail.com>
Installed-Size: 736
Depends: libc6 (>= 2.4), libcairo2 (>= 1.2.4), libcurl3 (>= 7.16.2-1), libglib2.0-0 (>= 2.20.0), libgstreamer0.10-0 (>= 0.10.0), libgtk2.0-0 (>= 2.24.0), libnotify4 (>= 0.7.0), libpango1.0-0 (>= 1.14.0)
Section: net
Priority: optional
Homepage: http://urlget.sourceforge.net/
Description: easy-to-use download manager written in GTK+2
 Uget (formerly urlgfe) is a simple, lightweight and easy-to-use
 download manager.
 It provides the following features:
  * Resume downloads.
  * Queue downloads.
  * Classify downloads in categories.
  * Mozilla Firefox integration (through Flashgot plugin).
  * Clipboard monitoring.
  * Import downloads import from HTML files.
  * Batch download.
 .
 It also can be launched from the command line.

The dependencies information shows up after Depends flag. So, the dependencies of this uget package are libc6 (>= 2.4), libcairo2 (>= 1.2.4), libcurl3 (>= 7.16.2-1), libglib2.0-0 (>= 2.20.0), libgstreamer0.10-0 (>= 0.10.0), libgtk2.0-0 (>= 2.24.0), libnotify4 (>= 0.7.0), libpango1.0-0 (>= 1.14.0).

3. dpkg-deb: Show Depends Field Contents of A Package Directly


Synopsis: dpkg-deb --field <package> <field>
Example: dpkg-deb --field uget_1.8.0-1_i386.deb Depends
Output: libc6 (>= 2.4), libcairo2 (>= 1.2.4), libcurl3 (>= 7.16.2-1), libglib2.0-0 (>= 2.20.0), libgstreamer0.10-0 (>= 0.10.0), libgtk2.0-0 (>= 2.24.0), libnotify4 (>= 0.7.0), libpango1.0-0 (>= 1.14.0)

This command sums up what 2nd command above did, into just one single step. This command pulls directly Depends field from control file inside the DEBIAN directory. For frequent working with package, this command is more suitable than the previous. We see the output is exactly the same.

4. apt-cache: Show Package Information


Synopsis: apt-cache show <package>
Example: apt-cache show uget

This command shows up control file content inside a package that are already inside APT database. You must override <package> field with package name, not file name. It is similar with dpkg -I command above except apt-cache show will take information from APT Database not from a single DEB file.

5. apt-cache: Show Package More Information


Synopsis: apt-cache showpkg <package>
Example: apt-cache showpkg uget

This command shows up detailed information similar with show command before. But showpkg shows where a package belongs to in APT Database. Especially in which database file it belongs. The output will be like this.

Package: uget
Versions: 
2.0-0ubuntu0~precise (/var/lib/apt/lists/ppa.launchpad.net_plushuang-tw_uget-stable_ubuntu_dists_precise_main_binary-i386_Packages)
 Description Language: 
                 File: /var/lib/apt/lists/ppa.launchpad.net_plushuang-tw_uget-stable_ubuntu_dists_precise_main_binary-i386_Packages
                  MD5: df1c64f6fd949d38e1bd89de60a8af32
 Description Language: en
                 File: /var/lib/apt/lists/ppa.launchpad.net_plushuang-tw_uget-stable_ubuntu_dists_precise_main_i18n_Translation-en
                  MD5: df1c64f6fd949d38e1bd89de60a8af32

Reverse Depends: 
Dependencies: 
2.0-0ubuntu0~precise - libappindicator3-1 (2 0.2.92) libc6 (2 2.15) libcairo2 (2 1.2.4) libcurl3 (2 7.16.2-1) libgdk-pixbuf2.0-0 (2 2.22.0) libglib2.0-0 (2 2.28.0) libgstreamer0.10-0 (2 0.10.0) libgtk-3-0 (2 3.0.0) libnotify4 (2 0.7.0) libpango1.0-0 (2 1.14.0) libssl1.0.0 (2 1.0.0) aria2 (0 (null)) 
Provides: 
2.0-0ubuntu0~precise - 
Reverse Provides: 

So, based on showpkg command, the dependencies of uget package are libappindicator3-1 (2 0.2.92) libc6 (2 2.15) libcairo2 (2 1.2.4) libcurl3 (2 7.16.2-1) libgdk-pixbuf2.0-0 (2 2.22.0) libglib2.0-0 (2 2.28.0) libgstreamer0.10-0 (2 0.10.0) libgtk-3-0 (2 3.0.0) libnotify4 (2 0.7.0) libpango1.0-0 (2 1.14.0) libssl1.0.0 (2 1.0.0) aria2 (0 (null)).

6. apt-rdepends: Show Complete Dependencies Recursively


Synopsis: apt-rdepends <package>
Example: apt-rdepends nano

This command will track and show complete dependencies list of a package. This will list dependencies recursively so it will produce very long output. This command includes whole dependencies, it doesn't exclude installed dependencies. For the sake of output simplicity, we use nano instead of uget as example. Output below are exactly all dependencies of nano package in our Ubuntu 12.04.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
nano
  Depends: dpkg (>= 1.15.4)
  Depends: install-info
  Depends: libc6 (>= 2.11)
  Depends: libncursesw5 (>= 5.7+20100313)
dpkg
  PreDepends: coreutils (>= 5.93-1)
  PreDepends: libbz2-1.0
  PreDepends: libc6 (>= 2.11)
  PreDepends: libselinux1 (>= 1.32)
  PreDepends: tar (>= 1.23)
  PreDepends: xz-utils
  PreDepends: zlib1g (>= 1:1.1.4)
coreutils
  Depends: dpkg (>= 1.15.4)
  Depends: install-info
  PreDepends: libacl1 (>= 2.2.51-5)
  PreDepends: libattr1 (>= 1:2.4.46-5)
  PreDepends: libc6 (>= 2.15)
  PreDepends: libselinux1 (>= 1.32)
install-info
  Depends: libc6 (>= 2.4)
libc6
  Depends: libc-bin (= 2.15-0ubuntu10)
  Depends: libgcc1
  Depends: tzdata
libc-bin
libgcc1
  Depends: gcc-4.6-base (= 4.6.3-1ubuntu5)
  Depends: libc6 (>= 2.2.4)
  PreDepends: multiarch-support
gcc-4.6-base
multiarch-support
  Depends: libc6 (>= 2.13-0ubuntu6)
tzdata
  Depends: debconf (>= 0.5)
  Depends: debconf-2.0
debconf
  PreDepends: perl-base (>= 5.6.1-4)
perl-base
  PreDepends: dpkg (>= 1.14.20)
  PreDepends: libc6 (>= 2.11)
debconf-2.0
libacl1
  Depends: libattr1 (>= 2.4.46-3)
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
libattr1
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
libselinux1
  Depends: libc6 (>= 2.8)
  PreDepends: multiarch-support
libbz2-1.0
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
tar
  PreDepends: libc6 (>= 2.8)
xz-utils
  Depends: libc6 (>= 2.7)
  Depends: liblzma5 (>= 5.1.1alpha+20110809)
liblzma5
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
zlib1g
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
libncursesw5
  Depends: libc6 (>= 2.4)
  Depends: libtinfo5 (= 5.9-4)
  PreDepends: multiarch-support
libtinfo5
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support

7. apt-rdepends -p <package>


Synopsis: apt-rdepends --print-state <package>
Example: apt-rdepends --print-state nano

This command including --print-state option gives every output status whether it is Installed or NotInstalled. The result is exactly same with normal command, but including status. It is useful to begin learning dependency for offline installation. We choose nano as example to avoid too long output.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
fping
  Depends: libc6 (>= 2.7) [Installed]
libc6
  Depends: libc-bin (= 2.15-0ubuntu10) [Installed]
  Depends: libgcc1 [Installed]
  Depends: tzdata [Installed]
libc-bin
libgcc1
  Depends: gcc-4.6-base (= 4.6.3-1ubuntu5) [Installed]
  Depends: libc6 (>= 2.2.4) [Installed]
  PreDepends: multiarch-support [Installed]
gcc-4.6-base
multiarch-support
  Depends: libc6 (>= 2.13-0ubuntu6) [Installed]
tzdata
  Depends: debconf (>= 0.5) [Installed]
  Depends: debconf-2.0 [NotInstalled]
debconf
  PreDepends: perl-base (>= 5.6.1-4) [Installed]
perl-base
  PreDepends: dpkg (>= 1.14.20) [Installed]
  PreDepends: libc6 (>= 2.11) [Installed]
dpkg
  PreDepends: coreutils (>= 5.93-1) [Installed]
  PreDepends: libbz2-1.0 [Installed]
  PreDepends: libc6 (>= 2.11) [Installed]
  PreDepends: libselinux1 (>= 1.32) [Installed]
  PreDepends: tar (>= 1.23) [Installed]
  PreDepends: xz-utils [Installed]
  PreDepends: zlib1g (>= 1:1.1.4) [Installed]
coreutils
  Depends: dpkg (>= 1.15.4) [Installed]
  Depends: install-info [Installed]
  PreDepends: libacl1 (>= 2.2.51-5) [Installed]
  PreDepends: libattr1 (>= 1:2.4.46-5) [Installed]
  PreDepends: libc6 (>= 2.15) [Installed]
  PreDepends: libselinux1 (>= 1.32) [Installed]
install-info
  Depends: libc6 (>= 2.4) [Installed]
libacl1
  Depends: libattr1 (>= 2.4.46-3) [Installed]
  Depends: libc6 (>= 2.4) [Installed]
  PreDepends: multiarch-support [Installed]
libattr1
  Depends: libc6 (>= 2.4) [Installed]
  PreDepends: multiarch-support [Installed]
libselinux1
  Depends: libc6 (>= 2.8) [Installed]
  PreDepends: multiarch-support [Installed]
libbz2-1.0
  Depends: libc6 (>= 2.4) [Installed]
  PreDepends: multiarch-support [Installed]
tar
  PreDepends: libc6 (>= 2.8) [Installed]
xz-utils
  Depends: libc6 (>= 2.7) [Installed]
  Depends: liblzma5 (>= 5.1.1alpha+20110809) [Installed]
liblzma5
  Depends: libc6 (>= 2.4) [Installed]
  PreDepends: multiarch-support [Installed]
zlib1g
  Depends: libc6 (>= 2.4) [Installed]
  PreDepends: multiarch-support [Installed]
debconf-2.0


8. apt-rdepends: Show NotInstalled Dependencies


Synopsis: apt-rdepends -p --state-show=NotInstalled --state-follow=NotInstalled <package>
Example: apt-rdepends -p --state-show=NotInstalled --state-follow=NotInstalled xchat

This command is the clearest of apt-rdepends when we want to know exactly what dependencies for a package to be downloaded for one Ubuntu system. This command is same with apt-get --print-uris below except this apt-rdepends doesn't print URL. This command firstly list the complete dependencies of package, then filter only the packages NotInstalled to show. It discards all packages has status Installed. It is basically the same when user see dependencies list every sudo apt-get install performed. So, with this command you will able to note the dependencies and go download them one by one then go back to install them completely. It will be same with apt-get install. Output from our example above will be like this.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
xchat
  Depends: libsexy2 (>= 0.1.8) [NotInstalled]
  Depends: xchat-common (= 2.8.8-3ubuntu12) [NotInstalled]
libsexy2
xchat-common

So, if we want to install xchat on our Ubuntu 12.04, we just need to download libsexy2 and xchat-common packages then install them manually with dpkg.

9. apt-cache: Show Only Important Dependencies


Synopsis: apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances <package>
Example: apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances ed

This command will track and show all dependencies but discards unneeded dependencies because of --no-* options. Important means only Depends and Pre-depends statuses will be printed. We choose ed package here to avoid long output. This command is practically same with next command.

ed
  Depends: libc6
 |Depends: dpkg
  Depends: install-info
libc6
  Depends: libc-bin
  Depends: libgcc1
  Depends: tzdata
dpkg
  PreDepends: libbz2-1.0
  PreDepends: libc6
  PreDepends: libselinux1
  PreDepends: zlib1g
  PreDepends: coreutils
  PreDepends: tar
  PreDepends: xz-utils
install-info
  Depends: libc6
libc-bin
libgcc1
  Depends: gcc-4.6-base
  Depends: libc6
  PreDepends: multiarch-support
tzdata
 |Depends: debconf
  Depends: <debconf-2.0>
    cdebconf
    debconf
libbz2-1.0
  Depends: libc6
  PreDepends: multiarch-support
libselinux1
  Depends: libc6
  PreDepends: multiarch-support
zlib1g
  Depends: libc6
  PreDepends: multiarch-support
coreutils
 |Depends: dpkg
  Depends: install-info
  PreDepends: libacl1
  PreDepends: libattr1
  PreDepends: libc6
  PreDepends: libselinux1
tar
  PreDepends: libc6
xz-utils
  Depends: libc6
  Depends: liblzma5
gcc-4.6-base
multiarch-support
  Depends: libc6
debconf
  PreDepends: perl-base
cdebconf
  Depends: libc6
  Depends: libdebian-installer4
  Depends: libnewt0.52
  Depends: libslang2
  Depends: libtextwrap1
  Depends: debconf
  Depends: dpkg
libacl1
  Depends: libattr1
  Depends: libc6
  PreDepends: multiarch-support
libattr1
  Depends: libc6
  PreDepends: multiarch-support
liblzma5
  Depends: libc6
  PreDepends: multiarch-support
perl-base
  PreDepends: libc6
  PreDepends: dpkg
libdebian-installer4
  Depends: libc6
libnewt0.52
  Depends: libc6
  Depends: libslang2
libslang2
  Depends: libc6
  PreDepends: multiarch-support
libtextwrap1
  Depends: libc6
<debconf-2.0>

10. apt-cache depends --recurse --important <package>


Synopsis: apt-cache depends --recurse -i <package>
Example: apt-cache depends --recurse -i ed

This command is shorten form of the previous command. The output is same with the previous.

11. apt-cache depends --recurse --important --installed <package>


Synopsis: apt-cache depends --important --installed <package>
Example: apt-cache depends --important --installed ed

This command is same with previous except this prints only installed dependencies. It is useful, but is not useful when you are looking for dependencies that must be downloaded. The output will be shorter like this. 

ed
  Depends: libc6
 |Depends: dpkg
  Depends: install-info
libc6
  Depends: libc-bin
  Depends: libgcc1
  Depends: tzdata
dpkg
  PreDepends: libbz2-1.0
  PreDepends: libc6
  PreDepends: libselinux1
  PreDepends: zlib1g
  PreDepends: coreutils
  PreDepends: tar
  PreDepends: xz-utils
install-info
  Depends: libc6
libc-bin
libgcc1
  Depends: gcc-4.6-base
  Depends: libc6
  PreDepends: multiarch-support
tzdata
 |Depends: debconf
    cdebconf
    debconf
libbz2-1.0
  Depends: libc6
  PreDepends: multiarch-support
libselinux1
  Depends: libc6
  PreDepends: multiarch-support
zlib1g
  Depends: libc6
  PreDepends: multiarch-support
coreutils
 |Depends: dpkg
  Depends: install-info
  PreDepends: libacl1
  PreDepends: libattr1
  PreDepends: libc6
  PreDepends: libselinux1
tar
  PreDepends: libc6
xz-utils
  Depends: libc6
  Depends: liblzma5
gcc-4.6-base
multiarch-support
  Depends: libc6
debconf
  PreDepends: perl-base
cdebconf
  Depends: libc6
  Depends: libnewt0.52
  Depends: libslang2
  Depends: debconf
  Depends: dpkg
libacl1
  Depends: libattr1
  Depends: libc6
  PreDepends: multiarch-support
libattr1
  Depends: libc6
  PreDepends: multiarch-support
liblzma5
  Depends: libc6
  PreDepends: multiarch-support
perl-base
  PreDepends: libc6
  PreDepends: dpkg
libnewt0.52
  Depends: libc6
  Depends: libslang2
libslang2
  Depends: libc6
  PreDepends: multiarch-support

12. apt-get: List All Dependencies URL 


Synopsis: sudo apt-get install --yes --print-uris <package> | grep \' | cut --delimiter=\' --field=2
Example: sudo apt-get install --yes --print-uris xchat | grep \' | cut --delimiter=\' --field=2

This command is actually a combo for three different commands (apt-get install, grep, and cut). This firstly will print exactly all complete dependencies URLs plus many other additional information, then take only the URL lines, then discards any other additional information except the URLs. So, we will have a complete list of URLs to be downloaded separately. Note them into a paper, download manually on another computer, take it back to offline computer, and finally install them with dpkg. This is an emulation for complete apt-get install sessions when user doesn't have direct internet connection. The output for this command is like this. 

http://kambing.ui.ac.id/ubuntu/pool/main/libs/libsexy/libsexy2_0.1.11-2build2_i386.deb
http://kambing.ui.ac.id/ubuntu/pool/universe/x/xchat/xchat-common_2.8.8-3ubuntu12_all.deb
http://kambing.ui.ac.id/ubuntu/pool/universe/x/xchat/xchat_2.8.8-3ubuntu12_i386.deb

Note: our Ubuntu 12.04 sets the repository to Kambing repository in Indonesia. So the URL will be like above. Same thing will happen on your system.