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 showautoMark package ‘pkg’ as automatically installed:
apt-mark auto <pkg>Show held back packages:
apt-mark showholdMark package ‘pkg’ as held back:
apt-mark hold <pkg>
Search
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 -lList 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 updateor:
apt-get updateList upgradable packages:
apt list --upgradableUpdate packages with newer versions (only installed):
apt upgradeor:
apt-get upgradeUpdate packages with newer versions (handles changes in dependencies):
apt full-upgradeor:
apt-get dist-upgradeUninstall unnecessary packages:
apt autoremoveor:
apt-get autoremovePurge unnecessary packages:
apt autoremove --purgeor:
apt-get autoremove --purgeInstall 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-brokenor:
apt-get install --fix-brokenInstall package ‘pkg’ from a specific release:
apt install <pkg>/jessie-backportsor:
apt-get install <pkg>/jessie-backportsInstall a specific version of package ‘pkg’:
apt install <pkg>=1.0or:
apt-get install <pkg>=1.0Remove downloaded packages from cache:
apt cleanor:
apt-get cleanRemove only outdated packages from cache:
apt autocleanor:
apt-get autocleanConfigure automatic security updates:
dpkg-reconfigure --priority=low unattended-upgrades
Build from source
Repository packages
Update list of available source packages:
apt-build updateBuild 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 upgradeBuild and reinstall whole system:
apt-build worldRemove built packages
apt-build clean-build
Backports
Get source for package ‘pkg’:
apt source <pkg>/sidor:
apt-get source <pkg>/sidGet source for package ‘pkg’ using dsc file:
dget -x http://ftp.debian.org/debian/pool/main/p/<pkg>_<version>.dscClean 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>.debDirty 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 dquiltCreate the file
~/.quiltrc-dpkgwith 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 fiGet source for package ‘pkg’:
apt source <pkg> && cd <pkg>-<version>Install build dependencies:
mk-build-deps --install --removeMove patch <file.patch> into the appropriate directory:
mv file.patch debian/patches/ echo 'file.patch' >> debian/patches/seriesRefresh the patch:
quilt push quilt refreshUpdate 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-nameBuild package ‘pkg’ from PPA:
apt build-dep <pkg> apt source --compile <pkg> dpkg -i <pkg>.debRemove 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" EOFConfigure 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" EOFRegenerate
grub.cfgso 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
Download pre-installed image:
wget http://cdimage.debian.org/cdimage/ports/current-hurd-i386/debian-hurd.img.tar.gzUnpack image:
tar xzf debian-hurd.img.tar.gzUse QEMU to run the image:
kvm -m 1G -drive file=$(echo debian-hurd*.img),cache=writeback
Links
- Applying patches in debian packages - Part 2 - Unix & Linux Stack Exchange
- AptGet/Howto > Setting up apt-get to use a http-proxy - Comunity Help Wiki
- AutomaticSecurityUpdates - Community Help Wiki
- Building debian packages with debuild
- Chapter 2. Debian package management
- CrossCompiling - Debian Wiki
- CrossToolchains > Installation - Debian Wiki
- D.3. Installing Debian GNU/Linux from a Unix/Linux System
- How do I backport a sid package to testing or stable? > DebianUnstable - Debian Wiki
- How to cross-build a Debian package - Unix & Linux Stack Exchange
- IntroDebianPackaging Step 4: Build the package - Debian Wiki
- Packaging/SourcePackage - Debian Wiki
- SimpleBackportCreation - Debian Wiki
- Why is dh_usrlocal throwing a build error?
- Debian – Debian GNU/Hurd Configuration
- Debian GNU/Hurd README.txt
- Debian 9: GRUB2 and Linux with serial console - Narrow Escape