APT GET and APT CACHE
This article explains how quickly you can learn to install, remove, update and search software packages using apt-get and apt-cache commands from the command line. This article provides some useful commands that will help you to handle package management in Debian/Ubuntu based systems.
What is apt-get?
The apt-get utility is a powerful and free package management command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages, removing existing software packages, upgrading of existing software packages and even used to upgrading the entire operating system.
What is apt-cache?
The apt-cache command line tool is used for searching apt software package cache. In simple words, this tool is used to search software packages, collects information of packages and also used to search for what available packages are ready for installation on Debian or Ubuntu based systems.
apt-cache : Five Useful Commands
1. How Do I List All Available Packages?
- To list all the available packages, type the following command.
$ apt-cache pkgnames
2. How Do I Find Out Package Name and Description of Software?
- To find out the package name and with it description before installing, use the ‘search‘ flag. Using “search” with apt-cache will display a list of matched packages with short description. Let’s say you would like to find out description of package ‘vsftpd‘, then command would be.
$ apt-cache search vsftpd
- To find and list down all the packages starting with ‘vsftpd‘, you could use the following command.
$ apt-cache pkgnames vsftpd
3. How Do I Check Package Information?
- For example, if you would like to check information of package along with it short description say (version number, check sums, size, installed size, category etc). Use ‘show‘ sub command as shown below.
$ apt-cache show netcat
4. How Do I Check Dependencies for Specific Packages?
- Use the ‘showpkg‘ sub command to check the dependencies for particular software packages. whether those dependencies packages are installed or not. For example, use the ‘showpkg‘ command along with package-name.
$ apt-cache showpkg vsftpd
5. How Do I Check statistics of Cache
- The ‘stats‘ sub command will display overall statistics about the cache. For example, the following command will display Total package names is the number of packages have found in the cache.
$ apt-cache stats
apt-get : Twenty Useful Commands
1. How to Update System Packages
- The ‘update‘ command is used to resynchronize the package index files from the their sources specified in /etc/apt/sources.list file. The update command fetched the packages from their locations and update the packages to newer version.
$ sudo apt-get update
2. How to Upgrade Software Packages
- The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages which are not already installed neither retrieved and installed to satisfy upgrade dependencies.
$ sudo apt-get upgrade
- However, if you want to upgrade, unconcerned of whether software packages will be added or removed to fulfill dependencies, use the ‘dist-upgrade‘ sub command.
$ sudo apt-get dist-upgrade
3. How Do I Install or Upgrade Specific Packages?
- The ‘install‘ sub command is tracked by one or more packages wish for installation or upgrading.
$ sudo apt-get install netcat
4. How I can Install Multiple Packages?
- You can add more than one package name along with the command in order to install multiple packages at the same time. For example, the following command will install packages ‘nethogs‘ and ‘goaccess‘.
$ sudo apt-get install nethogs goaccess
5. How to Install Several Packages using Wildcard
- With the help of regular expression you can add several packages with one string. For example, we use * wildcard to install several packages that contains the ‘*name*‘ string, name would be ‘package-name’.
$ sudo apt-get install '*name*
6. How to install Packages without Upgrading
- Using sub ‘–no-upgrade‘ command will prevent already installed packages from upgrading.
$ sudo apt-get install packageName --no-upgrade
7. How to Upgrade Only Specific Packages
- The ‘–only-upgrade‘ command do not install new packages but it only upgrade the already installed packages and disables new installation of packages.
$ sudo apt-get install packageName --only-upgrade
8. How Do I Install Specific Package Version?
- Let’s say you wish to install only specific version of packages, simply use the ‘=‘ with the package-name and append desired version.
$ sudo apt-get install vsftpd=2.3.5-3ubuntu1
9. How Do I Remove Packages Without Configuration
- To un-install software packages without removing their configuration files (for later re-use the same configuration). Use the ‘remove‘ command as shown.
$ sudo apt-get remove vsftpd
10. How Do I Completely Remove Packages
- To remove software packages including their configuration files, use the ‘purge‘ sub command as shown below.
$ sudo apt-get purge vsftpd
- Alternatively, you can combine both the commands together as shown below.
$ sudo apt-get remove --purge vsftpd
11. How I Can Clean Up Disk Space
- The ‘clean‘ command is used to free up the disk space by cleaning retrieved (downloaded) .deb files (packages) from the local repository.
$ sudo apt-get clean
12. How Do I Download Only Source Code of Package
- To download only source code of particular package, use the option ‘–download-only source‘ with ‘package-name’ as shown.
$ sudo apt-get --download-only source vsftpd
13. How Can I Download and Unpack a Package
- To download and unpack source code of a package to a specific directory, type the following command.
$ sudo apt-get source vsftpd
14. How Can I Download, Unpack and Compile a Package
- You can also download, unpack and compile the source code at the same time, using option ‘–compile‘ as shown below.
$ sudo apt-get --compile source goaccess
15. How Do I Download a Package Without Installing
- Using ‘download‘ option, you can download any given package without installing it. For example, the following command will only download ‘nethogs‘ package to current working directory.
$ sudo apt-get download nethogs
16. How Do I Check Change Log of Package?
- The ‘changelog‘ flag downloads a package change-log and shows the package version that is installed.
$ sudo apt-get changelog vsftpd
17. How Do I Check Broken Dependencies?
- The ‘check‘ command is a diagnostic tool. It used to update package cache and checks for broken dependencies.
$ sudo apt-get check
18. How Do I Search and Build Dependencies?
- This ‘build-dep‘ command searches the local repositories in the system and install the build dependencies for package. If the package does not exists in the local repository it will return an error code.
$ sudo apt-get build-dep netcat
19. How I Can Auto clean Apt-Get Cache?
- The ‘autoclean‘ command deletes all .deb files from /var/cache/apt/archives to free-up significant volume of disk space.
$ sudo apt-get autoclean
20. How I Can Auto remove Installed Packages?
- The ‘autoremove‘ sub command is used to auto remove packages that were certainly installed to satisfy dependencies for other packages and but they were now no longer required. For example, the following command will remove an installed package with its dependencies.
$ sudo apt-get autoremove vsftpd