Debian Package Management Tricks

This topic was published by and viewed 2114 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author

  • DevynCJohnson
    • Topics - 437
    • @devyncjohnson

    The Debian-packaging system and the apt-subsystem have many features and abilities that are seldomly used by many users. Some of these tricks may be helpful to know for future use.

    To allow the use of other architectures of the currently used repos, type "dpkg --add-architecture ARCH" where "ARCH" is the name of the architecture to add. For instance, to allow your system to download Debian packages for armhf, a user would type "dpkg --add-architecture armhf". This allows the Debian tools (like apt-get) to search the armhf repos in addition to the repos for your current system (like amd64 and i386). Obviously, on a system that is not armhf compatible, the armhf packages should be downloaded only. This allows users to obtain packages for other architectures that could be placed in a virtual-machine (like Qemu and Oracle's VirtualBox). Alternately, assume a user has a PowerPC system that is not connected to the Internet and an amd64 Debian system with an Internet connection. The amd64 system could obtain the needed packages, and then, the user can transfer the packages to the PowerPC system.

    NOTE: By default, the system will download the packages for its native architecture. As for dependencies, they will be obtained for the alternate architecture.

    Once a particular architecture has been added, user can obtain a package of that specific architecture by running a command like "apt-get -o APT::Architecture="armhf" download PACKAGE". The "-o" indicates an option is being specified, such as 'APT::Architecture="armhf"', which specifies armhf. The sub-command "download" indicates that the package will be downloaded without installation. The installation would not be possible on many architectures and errors would result. Other helpful parameters that can be appended include "--allow-unauthenticated" and "--show-progress".

    To disable the access to a particular architecture, type "dpkg --remove-architecture ARCH".

    To view the currently used architecture preference used by the Debian tools, type "dpkg --print-architecture". On a system that downloads and installs amd64 packages by default, the returned value would be "amd64". To view all of the other accepted package architectures for the system, type "dpkg --print-foreign-architecture".

    To search the currently available packages in the repos for a string, type "apt-cache search REGEX". This command will search the package names and descriptions (both short and long). Users may type a plain string or use regex. POSIX-compatible regex patterns are accepted. Use the parameter "--names-only" to search the package names and not the descriptions.

    To get information on a package with a known name, type "apt-cache show NAME". This command allows users to view dependencies, conflicts, etc. of the package. It may help to pipe the output to "less" (apt-cache show NAME | less) for easier viewing.


    To check if a package is installed, type "dpkg --status package". This will return the current status of the package.


    To list all currently installed packages, type "dpkg --get-selections". Users can save this data to a file by running "dpkg --get-selections > ~/packages.txt". Users can then place this file on another system and install the listed packages by running cat packages.txt > sudo dpkg --set-selections && sudo apt-get dselect-upgrade. Alternately, the list of packages can be loaded for installation by running dpkg --clear-selections && sudo dpkg --set-selections < packages.txt. Users could also use this trick for recovery. This trick is helpful when a system must be reinstalled, then all of the same packages can be installed all at once. However, be sure that the new system has the same repos so that all of the listed packages can be found.

    NOTE: Sometimes, the output of "dpkg --get-selections" may list packages marked to be uninstalled (or some other status). If so, add " | grep -w install$" which will ensure that the last word on the line is "install". So, the modified command would look like "dpkg --get-selections | grep -w install$ > ~/packages.txt".

    To generate a list of dependencies for a particular package, use the command below.

    apt-cache depends PKGNAME | grep -o -E -e "Depends: (.+)" | xargs apt-cache depends 2>/dev/null | grep -o -E -e "Depends: (.+)" | sed -r -e 's|Depends: (.+)|\1|gI' | sort | uniq | sed -e ':a;N;$!ba;s/\s/ /g' > ~/packages.txt

    NOTE: If you prefer awk rather than sed, replace the sed command with "awk '{ printf "%s ", $0 }'".

    To load the dependencies list into apt-get, run the commands below.

    # To install
    export PKGS=&96;cat ~/packages.txt&96;
    apt-get install $PKGS
    # Download-only
    export PKGS=&96;cat ~/packages.txt&96;
    apt-get download $PKGS

    To mirror a repo, install "debmirror" (deb apt-mirror/). Then, use a command like "debmirror -p --host=URL --root=FOLDER --dist=DIST -s SECTIONS --arch=ARCH --allow-dist-rename /STORAGE/DIRECTORY/".

    The '--host=' parameter specifies the URL to the repo that will be mirrored. '--root=FOLDER' is the folder name (like on an ftp server) containing the repository. To specify the distro/series repo, use '--dist=DIST', and use '-s SECTIONS' to list the types of software (such as main, free, universe, etc.). The listed sections may be differently named for each type of Debian-based distro. For instance, some would use "universe", "multiverse", etc. (for Ubuntu-like systems) or "main", "contrib", "non-free", etc. (for Debian-like systems). To specify the architecture, type "--arch=ARCH". The very last argument must be the desired download/storage location. For illustration, to mirror the Wheezy armhf repo for "main", "contrib", and "non-free" software for Debian, use a command like the one below.

    debmirror -p --root=debian --dist=wheezy -s main,contrib,non-free --arch=armhf --allow-dist-rename -v /media/collier/Vmware/arm-mirror/

    If any or all architectures are to be downloaded, remove the "--arch=ARCH" parameter. The same logic is true for the "--dist=DIST" and "-s SECTIONS" parameters. To ignore GPG-related tasks completely, add the parameters "--no-check-gpg --ignore-release-gpg". To not download source packages, use "--nosource". Many other parameters exist, so be sure to check the man page.

    Once the desired mirror is obtained, users can then install APTonCD ( and create an apt-repo on a DVD. This allows users to transfer packages to a system that may lack Internet connection.

    NOTE: Alternately, users could use rsync to create a mirror (

Viewing 1 post (of 1 total)