The Advanced Package Tool (APT) is a suite of commands that allow us to interface with our package management system. With it, we can install new software packages (straight from the web via terminal) and upgrade existing ones. Additionally, the
apt-get command pulls in any dependencies necessary, which covers
dpkg's drawback. When dealing with installing and updating software, you'll mostly be working with these commands.
Again, make sure you're signed in as root permissions with the
sudo -s command.
Let's start with a moo:
apt-get moo (__) (oo) /------\/ / | || * /\---/\ ~~ ~~ ..."Have you mooed today?"...
Here is a list of actions you can use with the
Okay, now let's get down to business! Here are 14 ways you can use the
apt tool to manage your packages.
You may have wondered during the previous lesson how
apt-get knows where to look for Vim when we typed
apt-get install vim. The answer to this question lies in the system's cache. This is where all the software package names are linked to their location on the Debian packaging server. A list of where important packages can be obtained lies in /etc/apt/sources.list. Since the Debian package management system performs automatic updates via the links in this file, it's advisable to not add any repositories unless you're sure that it may be trusted.
To update the cache on your local system, use the
apt-get update command. This will make sure your current listing is up-to-date so you can download the latest packages.
apt-get update Ign http://security.ubuntu.com trusty-security InRelease Ign http://extras.ubuntu.com trusty InRelease ... Ign http://us.archive.ubuntu.com trusty/restricted Translation-en_US Ign http://us.archive.ubuntu.com trusty/universe Translation-en_US Reading package lists... Done
Overtime, there will be new releases of your software, fixing bugs and adding new features. On Windows, you may have had to install and update them individually (darn you annoying Java updates!). On Linux however, you can upgrade all your software in one go:
apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages have been kept back: linux-generic-lts-vivid linux-headers-generic-lts-vivid linux-image-generic-lts-vivid 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
In the above case, there were no upgrades performed, but from time to time you may see changes. Remember that you must update your package index before running this command!
To install a package, use the
apt-get install command, followed by the package names. This will install any packages, along with its dependencies.
apt-get install vim Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: ctags vim-doc vim-scripts The following NEW packages will be installed: vim 0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded. Need to get 0 B/956 kB of archives. After this operation, 2,237 kB of additional disk space will be used. Selecting previously unselected package vim. (Reading database ... 166549 files and directories currently installed.) Preparing to unpack .../vim_2%3a7.4.052-1ubuntu3_amd64.deb ... Unpacking vim (2:7.4.052-1ubuntu3) ... Setting up vim (2:7.4.052-1ubuntu3) ... update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
To remove any packages, use
apt-get remove. This will remove any particular package, but not its dependencies. It will also keep the configuration files, so you can revert to your normal settings in case you install the particular software again.
apt-get remove vim Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: vim 0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded. After this operation, 2,237 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 166554 files and directories currently installed.) Removing vim (2:7.4.052-1ubuntu3) ... update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/vi (vi) in auto mode update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/rview (rview) in auto mode
To remove a package along with all its dependencies and config files, use the
apt-get purge command. This is a combination of typing
apt-get remove and
For multiple package installation and removals, separate each package name by spaces.
apt-get install vim-nox emacs24 nanoweb
To remove any packages that were downloaded and are in your cache, you may remove them with the
apt-get clean command. This will free up a good amount of previously unused space.
Sometimes you may want to simulate a run just to see what a
apt-get install command would do. In this case, you can pass in the simulate option
Instead of actually performing any actions, you'll see parameters such as Inst and Conf, indicating where the package will be installed and configured.
To set all responses to Yes, so that you don't have to type them per each confirmation prompt, use the
apt-get -y remove vim
To download but not install, use the
apt-get -d install vim
To suppress output, use the
apt-get install -qq vim
apt-cache command is used to query the package database for information. For example, if you know the name of the package, but aren't sure of the keyword, you can search the package as a query string.
To find a package, first update your cache, the run
apt-cache search with your query.
apt-cache search convert wma
dir2ogg - audio file converter into ogg-vorbis format kid3 - KDE MP3 ID3 tag editor kid3-cli - Command line audio tag editor kid3-core - Audio tag editor core libraries and data kid3-qt - Audio tag editor nautilus-script-audio-convert - A nautilus audio converter script pacpl - multi-purpose audio converter/ripper/tagger script sorune - tool to manage the database on the Neuros Audio player
You can easily see package details with
apt-cache show vim
Package: vim Priority: optional Section: editors Installed-Size: 2185 Maintainer: Ubuntu Developers <firstname.lastname@example.org> Original-Maintainer: Debian Vim Maintainers <email@example.com> Architecture: amd64 Version: 2:7.4.052-1ubuntu3 Provides: editor Depends: vim-common (= 2:7.4.052-1ubuntu3), vim-runtime (= 2:7.4.052-1ubuntu3), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgpm2 (>= 1.20.4), libpython2.7 (>= 2.7), libselinux1 (>= 1.32), libtinfo5 Suggests: ctags, vim-doc, vim-scripts Filename: pool/main/v/vim/vim_7.4.052-1ubuntu3_amd64.deb Size: 955616 MD5sum: f870bba8885a240acb21977e22503c73 SHA1: 038639fda5e3a73d7f26a8e1bd20faa0282c74ff SHA256: 1c59553660fb37a9a0317ce7a906b55d580be53e4a478c55a88da4de9f9a86b9 Description-en: Vi IMproved - enhanced vi editor Vim is an almost compatible version of the UNIX editor Vi. . Many new features have been added: multi level undo, syntax highlighting, command line history, on-line help, filename completion, block operations, folding, Unicode support, etc. . This package contains a version of vim compiled with a rather standard set of features. This package does not provide a GUI version of Vim. See the other vim-* packages if you need more (or less). Description-md5: 59e8b8f7757db8b53566d5d119872de8 Homepage: http://www.vim.org/ Bugs: https://bugs.launchpad.net/ubuntu/+filebug Origin: Ubuntu Supported: 5y Task: ubuntu-usb, cloud-image, server, edubuntu-desktop-gnome, edubuntu-usb
To view the current and most recent package versions, use the
apt-cache policy command.
apt-cache policy vim
vim: Installed: 2:7.4.052-1ubuntu3 Candidate: 2:7.4.052-1ubuntu3 Version table: *** 2:7.4.052-1ubuntu3 0 500 http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages 100 /var/lib/dpkg/status h3 14) View package's dependencies p | To view a package's dependencies, use the code.lang-bash.single.command apt-cache showpkg | command. To view any unmet dependencies, use code.lang-bash.single.command apt-cache unmet | . pre # apt-cache showpkg vim Package: vim Versions: 2:7.4.052-1ubuntu3 (/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_binary-amd64_Packages) (/var/lib/dpkg/status) Description Language: File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_binary-amd64_Packages MD5: 59e8b8f7757db8b53566d5d119872de8 Description Language: en File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_i18n_Translation-en MD5: 59e8b8f7757db8b53566d5d119872de8 Reverse Depends: vim-syntax-docker,vim mercurial,vim exuberant-ctags,vim byobu,vim vim:i386,vim vimhelp-de,vim 2:7.5 vimhelp-de,vim 2:7.4 vim-vimoutliner,vim vim-syntax-go,vim vim-syntax-docker,vim vim-scripts,vim vim-scripts,vim vim-rails,vim vim-migemo,vim vim-latexsuite,vim vim-latexsuite,vim vim-gocomplete,vim vim-addon-manager,vim supercollider-vim,vim ocaml-tools,vim mercurial,vim libvi-quickfix-perl,vim libtext-vimcolor-perl,vim kde-developer-sdk,vim halibut,vim gworkspace-apps-wrappers,vim edubuntu-desktop,vim debian-reference-common,vim vim-runtime,vim vim-dbg,vim 2:7.4.052-1ubuntu3 vim-common,vim exuberant-ctags,vim byobu,vim Dependencies: 2:7.4.052-1ubuntu3 - vim-common (5 2:7.4.052-1ubuntu3) vim-runtime (5 2:7.4.052-1ubuntu3) libacl1 (2 2.2.51-8) libc6 (2 2.15) libgpm2 (2 1.20.4) libpython2.7 (2 2.7) libselinux1 (2 1.32) libtinfo5 (0 (null)) ctags (0 (null)) vim-doc (0 (null)) vim-scripts (0 (null)) vim:i386 (0 (null)) Provides: 2:7.4.052-1ubuntu3 - editor Reverse Provides: vim-nox 2:7.4.052-1ubuntu3 vim-gtk 2:7.4.052-1ubuntu3 vim-athena 2:7.4.052-1ubuntu3 vim-gnome 2:7.4.052-1ubuntu3
The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.$ Check price
This book synthesizes the most effective techniques and must-know principles into clear, pragmatic guidance. No matter what your experience level, development environment, or project size, this book will inform and stimulate your thinking - and help you build the highest quality code.$ Check price