apt / dpkg

# Add repository
sudo apt-add-repository universe
# APT download only
apt-get upgrade -y --download-only
# run update
export DEBIAN_FRONTEND=noninteractive
LANG=en_US.UTF-8 sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y && sudo apt-get clean -y
# allow unauthenticated repository
apt-get update --allow-unauthenticated
# list updatable packages
apt list --upgradable
# view avaiable package version
apt-cache show wget
apt-cache madison wget
# install specific version
apt-get install package name=version
apt-get install wget=1.6
# install from specific repository
apt-get install -t squeeze-backports wget
# view available versions
apt-cache policy chromium-browser
# autoupdate
# download package
apt-get download
# list deb package dependency
dpkg -I <PACKAGE.deb>
# test DIRECT download package by apt
#Acquire::HTTP::Proxy::packages.gitlab.com "DIRECT";
#Acquire::HTTP::Proxy::packages-gitlab-com.s3.amazonaws.com "DIRECT";
#Acquire::https::Proxy "false";
Acquire::http::Proxy {
    packages.gitlab.com DIRECT;
    *.amazonaws.com DIRECT;
# use apt proxy
APT_PROXIES=$(apt-config shell \
http_proxy Acquire::http::Proxy \
https_proxy Acquire::https::Proxy \
ftp_proxy Acquire::ftp::Proxy \
dl_direct Acquire::http::Proxy::download.oracle.com \
echo 'Acquire::HTTP::Proxy::packages.gitlab.com "DIRECT";' > /etc/apt/apt.conf.d/99_gitlab
Acquire::http::Proxy {
    packages.gitlab.com DIRECT;
# list keys
apt-key list
# test
# lxc enable apt proxy?
eval $(apt-config shell MIRROR Acquire::http::Proxy)
apt-cache showpkg  libapache2-mod-php5
# install package from older distro
apt-get install -t etch -y libdb4.4
apt-get install -t squeeze -y libldap-2.4-2 libssl0.9.8 squid-common squid-langpack logrotate
# show package informtion
apt-cache show <PACKAGE>


apt-add-repository 'deb http://myserver/path/to/repo stable myrepo'
apt-add-repository 'http://myserver/path/to/repo myrepo'
apt-add-repository 'https://packages.medibuntu.org free non-free'
apt-add-repository http://extras.ubuntu.com/ubuntu
apt-add-repository ppa:user/repository
apt-add-repository multiverse
# test
sudo apt-get --allow-unauthenticated upgrade
APT::Get::AllowUnauthenticated "true";
# fix "Release file expired, ignoring..."
echo "Acquire::Check-Valid-Until false;" > /etc/apt/apt.conf.d/10squeeze-lts-no-check-valid-until
# list installed keys
apt-key list
# force remove
dpkg --remove --force-remove-reinstreq  wget
# mark a package as hold
apt-mark hold wget
echo "sonar hold" | dpkg --set-selections
# show packages marked to hold
apt-mark showhold
# unhold all APT packages
apt-mark showhold | awk '{ print $1, "install" }' | dpkg --set-selections
# force remove
dpkg --purge --force-all <package>
rm /var/lib/dpkg/info/<package>.postrm 
# download APT package with all recursive dependencies
PACKAGES="wget unzip"
apt-get download $(apt-cache depends \
    --recurse \
    --no-recommends \
    --no-suggests \
    --no-conflicts \
    --no-breaks \
    --no-replaces \
    --no-enhances \
    --no-pre-depends \
    ${PACKAGES} | grep "^\w")

Show installed version only

dpkg-query --showformat='${Version}\n' --show wget

diff installed packages between hosts

diff <(ssh host1.example.com dpkg -l | grep ii | cut -d" " -f3) <(ssh host2.example.com dpkg -l | grep ii | cut -d" " -f3)

APT proxy over SSH port forward

RemoteForward 8080 proxy.example.com:8080

Check if package installed

[[ $(dpkg-query -l wget) ]] || echo "Not installed"

http://wiki.grml.org/doku.php?id=debian - Package management commands