Linux - APT Commands


show/list

show package info

$ apt-cache show <packagename>

list all files of specified package

$ sudo dpkg-query -L <packagename>

list package versions

  1. https://www.cyberciti.biz/faq/debian-ubuntu-linux-apt-get-aptitude-show-package-version-command/
$ apt-cache policy elixir
elixir:
  Installed: 1.5.1-1
  Candidate: 1.5.1-1
  Version table:
  *** 1.5.1-1 500
        500 http://packages.erlang-solutions.com/ubuntu xenial/contrib amd64 Packages
        100 /var/lib/dpkg/status
      1.5.1-1 500
        500 http://packages.erlang-solutions.com/ubuntu xenial/contrib i386 Packages
      1.5.0-1 500
        500 http://packages.erlang-solutions.com/ubuntu xenial/contrib amd64 Packages
      1.5.0-1 500
        500 http://packages.erlang-solutions.com/ubuntu xenial/contrib i386 Packages

find

find any file

$ sudo updatedb
$ sudo locate <filename>

find package by name

$ apt-cache search <packagename>

find package containing specified file

$ sudo dpkg-query -S <filename>

update/upgrade

update (synchronize package index files)

$ sudo apt update

upgrade (upgrade all packages)

$ sudo apt upgrade

remove

remove package (only binaries)

$ sudo apt remove <packagename>

remove specific version of package

$ sudo apt remove <packagename>=<version>

it’s possible to use glob pattern instead of exact version (say, if you don’t know exact version currently installed):

$ sudo apt remove postgresql=10*

remove everything regarding package but without dependencies

$ sudo apt [purge|remove --purge] <packagename>

remove everything regarding package with dependencies

$ sudo aptitude [remove|purge] <packagename>

remove all orphaned packages

$ sudo apt autoremove