Use apt-get Command In Linux (Examples)

apt-get command in Linux is basically a command line utility that aids users to handle packages in Linux platforms. With the help of this command, the users can retrieve information and packages from various sources in order to install, upgrade and remove the packages, even their dependencies as well. So, let’s learn how to use apt-get command in Linux for various purposes.

Syntax to use apt-get command in Linux

apt-get [options] command

Commands available to use with apt-get command

In order to use apt-get command, there’s a number of available options which can be used for different purposes. Such options are here mentioned:

update: Using this command, the package index files and their sources can be synced again. It’s a recommended process that should be performed before performing an upgrade.

apt-get update

upgrade: This option is used to install the latest version of packages installed on system from its repositories. These sources are saved in a list file within /etc/apt/sources.list. So, running this command retrieves the new version of installed packages, and install them as well when available.

apt-get upgrade

dselect-upgrade: This option is basically used for following the modifications made by dselect to the Status field available packages and do necessary actions to realize the state.

apt-get dselect-upgrade

dist-upgrade: With the help of this option, the users can perform upgrade along with changing dependencies with new versions of packages as well. While using this option, it can sometimes may upgrade the important packages at priority, and may remove some of the packages as if seems unnecessary.

apt-get dist-upgrade

install: Obviously, it will be used to install or upgrade packages. Users can also specify the package (s) by using their names while installing them. Doing this will also download and install associated dependencies as well.

apt-get install [Packapge_name]

remove: this command can be used similar to install command as discussed before. The only difference is, it use to remove the packages despite installing them. However, removing packages with this command will not remove the configuration files.

apt-get remove [Package_name]

purge: As mentioned in in remove command option, the configuration files will not be removed, and this is usually performed by using purge command.

apt-get purge [Package_name]

check: Used for updating package cache and checking the dependencies which are broken.

apt-get check

download: Using this command, the users can download a specified package in current directory.

apt-get download [Package_name]

clean: Used for clearing out the local repository of retrieved package files. Basically, the command can remove everything rather than the files which are locked.

apt-get clean

autoremove: This command is basically used to remove the packages which are installed for satisfying dependencies of other packages, and then no longer required.

apt-get autoremove

Various options to use with apt-get command

  • -no-install-recommends: Lets the apt-get command to know to avoid considering recommended packages as dependency to install.
  • -install-suggests: Allows the apt-get command to consider suggested packages as dependencies to install.
  • -d | -download-only: Makes the apt-get to retrieve the packages but not to install or unpack them
  • -f | -fix-broken: Used for specifying apt-get to to correct the system with broken dependencies in place.
  • -m | -ignore-missing | -fix-missing: Used to specify that apt-get to ignore the missing packages and handle the result.
  • -no-download: Used for telling apt-get to use only .debs which has already downloaded, and not to download anything.
  • -q | -quiet: Specifies apt-get to produce output which is suitable for logging.
  • -s | -stimulate | -just-print | -dry-run | -recon | -no-act: Used for specifying that actions to perform. Just to do a stimulation f events which would occur based on current system without changing it.
  • -y | -yes | -assume-yes: Sets the apt-get command to assume “yes” for all prompts and should run without any manual interaction which are required sometimes.
  • -assume-no: Alike the option above, it will specify apt-get to assume no for all prompts.
  • -no-show-upgraded: Using this option, the apt-get will show no list of packages which are required to be upgraded.
  • -V | -verbose-versions: Displays the version information about upgraded and installed packages.
  • -show-progress: Sets the command to show user friendly progress in the terminal while the packages are being installed, removed, or upgraded.
  • -b | -build | compile: With this option, the aptget compiles or builds the downloaded source packages.
  • -no-upgrade: Tells the apt-get command to prevent the packages against being upgraded.
  • -only-upgrade: apt-get command will only upgrade the packages which are currently installed, and will not add more other packages.
  • -reinstall: reinstalls the already installed packages with their latest versions.
  • -autoremove | -auto-remove: This option also works similarly to autoremove command as discussed above.
  • -h | -help: Displays the help information regarding usage of apt-get command.
  • -v | -version: Displays the version details

It’s noteworthy to mention that if you are using apt-get command in Linux, then it will show 0 as results which indicates the command is executed successfully, otherwise it will show 100 to represent some errors occurred.