apt-get Command in Linux with Examples

The apt-get command is a command-line tool that is used to handle packages in Linux. This command handles the processes like retrieving the packages and information from authentic sources for upgradation, installation, and removal of packages along with their reliabilities. In this command “apt” stands for Advanced Packaging Tool. If the execution is successful, the apt-get command returns 0, and in case of an error, it returns decimal 100.

The syntax for the apt-get command:

apt-get [options] command
or
apt-get [options] install|remove pkg1 [pkg2 ...]
or
apt-get [options] source pkg1 [pkg2 ...]

Widely used commands with the apt-get command

If we do not use the -h option, then we have to use any one of the commands given below:

  • update: Before dist-upgrading and upgrading, we have to perform an update. If we again want to contemporize the package index files from their sources, then the update command is used.
apt-get update
  • upgrade: To install the latest version of the package that is currently being used on the user’s device, the upgrade command is used, and the latest version is installed from the sources those are listed in /etc/apt/sources.list. If new packages are available then the packages that had been already installed are recovered and installed. We know that before upgrading, the update has to be performed so that the apt-get command gets to know about new versions available.
apt-get upgrade
  • dselect-upgrade: The dselect-upgrade command is used with the Debian packaging tool, dselect. It checks the changes made to the status field of available packages by dselect, and it performs any mandatory operations to bring in that state.
apt-get dselect-upgrade
  • dist-upgrade: The dist-upgrade command is also used to perform the task of upgrading, and this command also manages to change holdings with the new version of packages. If it is important, the apt-get command will upgrade the important packages only, and some of the packages get removed in this process.
apt-get dist-upgrade
  • install: To upgrade or install the packages, the install command is used. With this command, the names of the packages that one wishes to install shouldbe provided. If the user wants any specific version to install, then the package name must be followed by an “equal” (=) sign, and the number of the version he desires. And if desired, then a specific distribution can also be selected by following the package name with a “forward slash” (/) and the archive or version name. The packages can be downgraded if any of these selection methodsare not used carefully.
apt-get install [...PACKAGES]
  • remove: The remove command is used when the user wants to remove the packages. It removes the packages but does not remove the presentation files created by the package.
apt-get remove [...PACKAGES]
  • purge: The purge command removes the packages along with the presentation files created by or related to the packages.
apt-get purge [...PACKAGES]
  • check: The check command checks for broken dependencies and update the package cache.
apt-get check
  • download: If we want to download any binary package in the given directory, then the download command is used.
apt-get download [...PACKAGES]
  • clean: To clear the local repository of the recovered package files, the clean command is used. Everything gets erased except the lock file forms /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.
apt-get clean
  • autoremove: Some packages get automatically installed to support some packages, and after that, they are not required, then to remove these kinds of unwanted packages the autoremove command is used.
apt-get autoremove

Some widely used options with the apt-get command

  • -no-install-recommends: By passing the-no-install-recommends option, the user can stop the apt-get command to consider suggested packages as a dependency to install.
apt-get --no-install-recommends [...COMMAND]
  • -install-suggests: By passing the -install-suggests option, the user gives the apt-get command, the authority to consider suggested packages as a dependency to install.
apt-get --install-suggests [...COMMAND]
  • -download-only or -d: By passing any one of the -download-only or -doptions, the user allows the apt-get command to only recover the package, but not install or unpack them.
apt-get -d [...COMMAND]
OR
apt-get -download-only [...COMMAND]
  • -fix-broken or -f: By passing any one of the -fix-broken or -f options, the user permits the apt-get command to correct the broken holdings in place, in the system.
apt-get -f [...COMMAND]
OR
apt-get -fix-broken [...COMMAND]
  • -fix-missing or -ignore-missing or -m: By passing any one of the -fix-missing or -ignore-missing or -moptions, the user lets the apt-get command know that to ignore the packages that could not be recovered and take care of the result.
apt-get -m [...COMMAND]
OR
apt-get -fix-missing [...COMMAND]
OR
apt-get -ignore-missing [...COMMAND]
  • -no-download: The -no-downloadoption is passed when the user does not want the apt-get command to download anything.
apt-get-no-download [...COMMAND]
  • -quiet or -q: After passing the -quiet or -qoption, the apt-get command only returns the output that is suitable for registering.
apt-get -quiet [...COMMAND]
OR
apt-get -q [...COMMAND]
  • -no-act or -recon or -dry-run or -just-print or -simulate or -s: This option is passed to ensure that no action should be taken, and perform cloning of events that would occur according to the existing system, but it does not alter the system.
apt-get -no-act [...COMMAND]
OR
apt-get -recon [...COMMAND]
OR
apt-get -dry-run [...COMMAND]
OR
apt-get -just-print [...COMMAND]
OR
apt-get -simulate [...COMMAND]
OR
apt-get -s [...COMMAND]
  • -yes or -assume-yes or -y: During the execution of the program, many times a condition is reached when the user is asked to select any one yes/no, so this option, by default assumes the input as yes for all the prompts, will run without any interaction with the user.
apt-get -yes [...COMMAND]
OR
apt-get -assume-yes [...COMMAND]
OR
apt-get -y [...COMMAND]
  • -assume-no: This option is passed to assume all the prompts as no.
apt-get --assume-no [...COMMAND]
  • -no-show-upgraded: This option is used to hide the list of all packages that have to be upgraded.
apt-get --no-show-upgraded [...COMMAND]
  • -verbose-versions: This option shows all the versions of the upgraded packages and installed packages.
apt-get -verbose-versions [...COMMAND]
  • -show-progress: This option shows the progress in the terminal when any package is being upgraded, installed, or removed.
apt-get --show-progress [...COMMAND]
  • -compile or -build: This option helps the apt-get command to compile the source packages that are being downloaded.
apt-get -compile [...COMMAND]
OR
apt-get -build [...COMMAND]
  • -autoremove or -auto-remove: When the install or remove command is used with the apt-get command, this option runs like the autoremove command.
apt-get install/remove --autoremove [...PACKAGES]
  • -h or -help: The apt-get command displays a short usage summary when used with this option.
apt-get -h

Output:

apt-get Command in Linux with Examples
  • --version or -v: The apt-get command displays the current version number when used with this option.
apt-get --version

Output:

apt-get Command in Linux with Examples