Skip to content

Debian

Package manager

Configuration

  • Use APT with a proxy:

      cat <<- 'EOF' >> /etc/apt/apt.conf.d/01proxy
      Acquire::ftp::Proxy "http://yourproxyaddress:proxyport";
      Acquire::http::Proxy "http://yourproxyaddress:proxyport";
      Acquire::https::Proxy "http://yourproxyaddress:proxyport";
      EOF

Mark packages

  • Show automatically installed packages:

      apt-mark showauto
  • Mark package ‘pkg’ as automatically installed:

      apt-mark auto <pkg>
  • Show held back packages:

      apt-mark showhold
  • Mark package ‘pkg’ as held back:

      apt-mark hold <pkg>
  • Search packages whose name and description contains ‘string’:

      apt search <string>

    or:

      apt-cache search <string>
  • Search packages whose name contains ‘string’:

      apt search --names-only '<string>'

    or:

      apt-cache search --names-only '<string>'
  • Search packages whose name contains ‘pattern’:

      apt list <pattern>
  • Search packages that contain ‘file’:

      apt-file search <file>

Information

  • Show information about package ‘pkg’:

      apt show <pkg>

    or:

      apt-cache show <pkg>
  • See which source package creates a specific binary package ‘pkg’:

      apt showsrc <pkg>

    or:

      apt-cache showsrc <pkg>
  • Show maintainer of package ‘pkg’:

      dpkg-query -W -f='${Maintainer}' <pkg>
  • Show upstream homepage of package ‘pkg’:

      dpkg-query -W -f='${Homepage}' <pkg>
  • Show packages from contrib or non-free section:

      dpkg-query -W -f='${Section}\t${Package}\n' | grep -E '^contrib|^non-free'

    or:

      aptitude search '~i ?section(non-free)'
  • Show packages from backports:

      dpkg-query -W | grep '~bpo'

Versions

  • Get information about version candidates for package ‘pkg’:

      apt policy <pkg>

    or:

      apt-cache policy <pkg>
  • Get information about available versions of package ‘pkg’:

      rmadison -a amd64 <pkg>

    or:

      apt-cache madison <pkg>
  • See installed version of package ‘pkg’:

      apt-show-versions -p <pkg>
  • See all available versions of package ‘pkg’:

      apt-show-versions -a -p <pkg>

Handle binary packages

Package commands

  • List installed packages:

      dpkg -l
  • List installed packages that match ‘string’:

      dpkg -l <string>
  • List of files in package ‘pkg.deb’:

      dpkg -c <pkg.deb>
  • Unpack package ‘pkg.deb’:

      dpkg --unpack <pkg.deb>
  • Install package ‘pkg.deb’:

      dpkg -i <pkg.deb>
  • Uninstall package ‘pkg’:

      dpkg -r <pkg>
  • Purge package ‘pkg’:

      dpkg -P <pkg>
  • See status of a specific package:

      dpkg -s <pkg>
  • Get name of installed package that contains ‘file’:

      dpkg -S <file>
  • List files of installed package ‘pkg’:

      dpkg -L <pkg>
  • List files of uninstalled package ‘pkg’:

      apt-file list <pkg>
  • List files inside package ‘pkg.deb’:

      dpkg -c <pkg.deb>

Repository commands

  • Update list of available packages:

      apt update

    or:

      apt-get update
  • List upgradable packages:

      apt list --upgradable
  • Update packages with newer versions (only installed):

      apt upgrade

    or:

      apt-get upgrade
  • Update packages with newer versions (handles changes in dependencies):

      apt full-upgrade

    or:

      apt-get dist-upgrade
  • Uninstall unnecessary packages:

      apt autoremove

    or:

      apt-get autoremove
  • Purge unnecessary packages:

      apt autoremove --purge

    or:

      apt-get autoremove --purge
  • Install package ‘pkg’:

      apt install <pkg>

    or:

      apt-get install <pkg>
  • Reinstall package ‘pkg’:

      apt install --reinstall <pkg>

    or:

      apt-get install --reinstall <pkg>
  • Download package ‘pkg’ without installing it:

      apt install --download-only <pkg>

    or:

      apt-get install --download-only <pkg>
  • Download package ‘pkg’ to current directory:

      apt download <pkg>

    or:

      apt-get download <pkg>
  • Uninstall package ‘pkg’:

      apt remove <pkg>

    or:

      apt-get remove <pkg>
  • Purge package ‘pkg’:

      apt purge <pkg>

    or:

      apt-get purge <pkg>
  • Fix broken dependencies (after installing with dpkg -i):

      apt install --fix-broken

    or:

      apt-get install --fix-broken
  • Install package ‘pkg’ from a specific release:

      apt install <pkg>/jessie-backports

    or:

      apt-get install <pkg>/jessie-backports
  • Install a specific version of package ‘pkg’:

      apt install <pkg>=1.0

    or:

      apt-get install <pkg>=1.0
  • Remove downloaded packages from cache:

      apt clean

    or:

      apt-get clean
  • Remove only outdated packages from cache:

      apt autoclean

    or:

      apt-get autoclean
  • Configure automatic security updates:

      dpkg-reconfigure --priority=low unattended-upgrades

Build from source

Repository packages

  • Update list of available source packages:

      apt-build update
  • Build and install package ‘pkg’:

      apt-build install <pkg>
  • Rebuild and reinstall package ‘pkg’:

      apt-build install --reinstall <pkg>
  • Uninstall package ‘pkg’:

      apt-build remove <pkg>
  • Purge package ‘pkg’:

      apt-build remove --purge <pkg>
  • Build and update packages with newer versions:

      apt-build upgrade
  • Build and reinstall whole system:

      apt-build world
  • Remove built packages

      apt-build clean-build

Backports

  • Get source for package ‘pkg’:

      apt source <pkg>/sid

    or:

      apt-get source <pkg>/sid
  • Get source for package ‘pkg’ using dsc file:

      dget -x http://ftp.debian.org/debian/pool/main/p/<pkg>_<version>.dsc
  • Clean way to backport package ‘pkg’ from sid to current release:

      cd <pkg>-<version>
      mk-build-deps --install --remove
      dch --bpo ''
      debuild -us -uc
      dpkg -i ../<pkg>.deb
  • Dirty way to backport package ‘pkg’ from sid to current release:

      apt build-dep <pkg>/sid
      apt source --compile <pkg>/sid
      dpkg -i <pkg>.deb

Patch official packages

  • Set up quilt by adding these to ~/.bashrc:

      alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
      complete -F _quilt_completion -o filenames dquilt
  • Create the file ~/.quiltrc-dpkg with these:

      d=. ; while [ ! -d $d/debian -a `readlink -e $d` != / ]; do d=$d/..; done
      if [ -d $d/debian ] && [ -z $QUILT_PATCHES ]; then
          # if in Debian packaging tree with unset $QUILT_PATCHES
          QUILT_PATCHES="debian/patches"
          QUILT_PATCH_OPTS="--reject-format=unified"
          QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
          QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
          QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33"
          if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
      fi
  • Get source for package ‘pkg’:

      apt source <pkg> && cd <pkg>-<version>
  • Install build dependencies:

      mk-build-deps --install --remove
  • Move patch <file.patch> into the appropriate directory:

      mv file.patch debian/patches/
      echo 'file.patch' >> debian/patches/series
  • Refresh the patch:

      quilt push
      quilt refresh
  • Update changelog:

      dch -n "Apply patch file.patch"
  • Build package:

      debuild -us -uc

Ubuntu PPAs

  • Add Ubuntu PPA repository with sources:

      add-apt-repository --enable-source ppa:user/ppa-name
  • Build package ‘pkg’ from PPA:

      apt build-dep <pkg>
      apt source --compile <pkg>
      dpkg -i <pkg>.deb
  • Remove Ubuntu PPA repository:

      add-apt-repository --remove ppa:user/ppa-name

Other architectures

  • Build package ‘pkg’ for architecture ‘arch’ with sbuild:

      sbuild-adduser $USER
      sbuild-update --keygen
      sbuild-createchroot --make-sbuild-tarball=/srv/chroots/jessie-sbuild.tgz jessie /srv/chroots/jessie http://httpredir.debian.org/debian/
      sbuild --host=<arch> --dist=jessie <pkg>
  • Backport package ‘pkg’ from sid for architecture ‘arch’ with pbuilder:

      pbuilder-dist jessie <arch> create
      apt source <pkg>
      (cd <pkg>-<version>; dch --bpo '')
      dpkg-source --build <pkg>_<ver>
      pbuilder-dist jessie <arch> <pkg>_<ver-bpo>.dsc
      dpkg -i ~/pbuilder/jessie-<arch>_result/<pkg>.deb

Other sources

  • Build package from downloaded sources:

      apt install <pkg_dep1> <pkg_dep2> ... <pkg_depN>
      dh_make -s -n -y -e $USER@$(hostname) -p <pkg>_<version>
      env PREFIX=/usr debuild -us -uc
      dpkg -i ../<pkg>.deb

Serial console

  • Configure GRUB to use normal console output:

      cat <<- 'EOF' >> /etc/default/grub.d/console.cfg
      GRUB_TERMINAL="$GRUB_TERMINAL console"
      GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX console=tty1"
      EOF
  • Configure GRUB to also use serial and enable a serial console:

      cat <<- 'EOF' >> /etc/default/grub.d/serial.cfg
      GRUB_TERMINAL="$GRUB_TERMINAL serial"
      GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX console=ttyS0,115200"
      EOF
  • Regenerate grub.cfg so it uses our new configuration:

      update-grub

Debootstrap

  • Use debootstrap to install inside a chroot:

      mount /dev/sdc1 /mnt/debian
      debootstrap --arch amd64 stable /mnt/debian http://deb.debian.org/debian
      mount -t proc /proc /mnt/debian/proc
      mount --rbind --make-rslave /dev /mnt/debian/dev
      mount --rbind --make-rslave /sys /mnt/debian/sys
      mount --rbind --make-rslave /run /mnt/debian/run
      chroot /mnt/debian /bin/bash
      # echo 'myhostname' > /etc/hostname
      # echo -e '127.0.1.1\tmyhostname' >> /etc/hosts
      # echo -e '/dev/sdc1\t/\text4\tdefaults\t0\t0' >> /etc/fstab
      # echo -e 'APT::Install-Suggests "0";\nAPT::Install-Recommends "0";' >> /etc/apt/apt.conf.d/99local
      # apt update
      # apt install locales linux-image-amd64 grub2
      # dpkg-reconfigure locales
      # grub-install /dev/sdc && update-grub
      # passwd
      # exit
      umount -R /mnt/debian

Ports

Debian GNU/Hurd

  1. Download pre-installed image:

     wget http://cdimage.debian.org/cdimage/ports/current-hurd-i386/debian-hurd.img.tar.gz
  2. Unpack image:

     tar xzf debian-hurd.img.tar.gz
  3. Use QEMU to run the image:

     kvm -m 1G -drive file=$(echo debian-hurd*.img),cache=writeback