Linux apt-get command

Apt-get is a command-line that helps to handle the packages in Linux. Its major task is to assist in retrieving data and packages from trusted sources for purposes of installation, update, and removal of the package and any related dependencies. Advanced packaging Tool is the full name of TP.

Linux apt-get command

The Debian, Ubuntu, and Linux Mint operating systems come preinstalled with the apt-get command and other essential APT utilities.

Syntax of Apt-get command

apt-get [-asqdyfmubV] [-o=config_string] [-c=config_file] 
       [-t=target_release] [-a=architecture] 
       { update | upgrade | dselect-upgrade | dist-upgrade |
       install pkg [{=pkg_version_number | /target_release}]... |
       remove pkg... | purge pkg... |
       source pkg [{=pkg_version_number | /target_release}]... |
       build-dep pkg [{=pkg_version_number | /target_release}]... |
       download pkg [{=pkg_version_number | /target_release}]... |
       check | clean | autoclean | autoremove | {-v | --version} |
       {-h | --help}}

Some most popular commands

1. Update: The package index files are once more synchronized from their sources with the help of using below command. Before you upgrade or dist-upgrade, you must run an update.

Updates information about available new and updated packages by resynchronizing the local index of package files. The locations listed in /etc/apt/sources.list are where the indexes are downloaded from.

apt-get update

2. Upgrade: Installing the latest versions of all currently installed packages on the system using the sources provided in /etc/apt/sources.list. A package is fetched and upgraded if a new version is available when it is already installed. Installed packages cannot be removed, and neither can uninstalled packages be recovered. New versions of presently installed packages won't be upgraded unless another package's install status is altered; instead, they will stay at their existing state.

It is usually advisable to update first so that apt-get is aware of the latest package releases.

apt-get upgrade

3. Deselect upgrade: This is used in conjunction with the deselect Debian packaging tool. It observes the modifications made by deselecting to the Status field of the packages that are now accessible and takes any necessary steps to bring about that status.

apt-get deselect-upgrade

4. Dist upgrade: This command handles upgrading and dealing with dependencies that change as a result of new package versions. If necessary, the apt-get command will try to update crucial packages at the expense of less crucial ones. During this process, other packages might also be removed.

Therefore, the dist-upgrade command can get rid of some packages.

The list of places from which package files will be retrieved can be found in the /etc/apt/sources.list file. For a system that alters the default settings for certain packages, see also apt preferences.

apt-get dist-upgrade

5. Install: To install or upgrade packages, use below command. It is followed by the names of any further packages the user wants to install. The appropriate packages will also be downloaded and installed together with all of their dependencies. By adding the desired version number and a "equals" sign to the package name, the user can also select the desired version. Additionally, the user can choose a certain distribution by adding a forward slash to the package name, followed by the version or archive name (such as "stable," testing," or "unstable"). Both of these methods for version selection should be utilized carefully because they have the potential to downgrade the programs.

apt-get install [...PACKAGES]

6. Remove: This is comparable to installing, but removes the packages as opposed to installing them. No configuration files produced by the software are deleted.

apt-get remove [...PACKAGES]

7. Purge: The packages are removed together with any associated configuration files by this command.

apt-get purge [...PACKAGES]

8. Check: The package cache is updated with this command, which also looks for broken dependencies.

apt-get check

9. Download: The specified binary package is downloaded in the current directory with this command.

apt-get download [...PACKAGES]

10. Clean: This operation clears the local repository of all retrieved package files. Everything excluding the lock file is removed from /var/cache/apt/archives/partial/ and /var/cache/apt/archives/.

apt-get clean

11. Autoremove: When automated packages that are installed to meet the dependencies of other packages are no longer required, the autoremove command is used to get rid of them.

apt-get autoremove

12. Source: To choose which source package to retrieve, APT will look at the currently installed packages. In accordance with any default releases specified using the APT::Default-Release option, the -t option, or per package using the pkg/release syntax, the most recent version of that source package will then be located and downloaded into the current directory.

By using deb-src lines in the sources. List file and source packages are tracked independently from binary packages.

When the —compile option is used, the package will be built using dpkg-build package to produce a binary.deb for the architecture supplied by the —host-architecture option. Using the —download-only option prevents the source package from being unpacked.

Similar to the method used for package files, a specific source version may be requested by prefixing the source name with an equals sign before the version to fetch. This automatically activates the APT::Get::Only-Source option and allows for accurate matching of the source package name and version.

Be aware that source packages are downloaded to the current directory as source tarballs rather than being installed and recorded in the dpkg database like binary packages are.

13. Changelog: Downloads a package changelog and uses a sensible pager to display it. The APT::Changelogs::Server variable specifies the server name and base directory. It shows the changelog for the installed version by default. The same arguments as for the install command can be specified, though.

Options:

–No-install-recommends: By selecting this option, the user instructs apt-get not regarding suggested packages as installation dependencies.

apt-get --no-install-recommends [...COMMAND]
  • –Install-suggests: The user instructs apt-get to take suggested packages into account when determining which dependencies to install by passing this option.
apt-get --install-suggests  [...COMM
  • -d or –download-only: The user instructs apt-get not to unpack or install the packages; instead, they should only be retrieved by passing this option.
apt-get -d [...COMMAND]
  • -f or –fix-broken: The user instructs apt-get to make an attempt to fix the system's faulty dependencies by passing this option.
apt-get -f [...COMMAND]
  • -m or –ignore-missing or –fix-missing: By passing this option, the user tells apt-get how to treat the result and disregard any missing packages (packages that can't be retrieved or fail the integrity check).

apt-get -m [...COMMAND]

  • –no-download: The user can prevent apt-get from downloading by passing this command. The only.debs it should utilize are those it has previously downloaded, according to this.
apt-get  [...COMMAND]
  • -q or –quie: Apt-get generates output that is acceptable for logging when this option is supplied.
apt-get  [...COMMAND]
  • -s or –simulate or –just-print or –dry-run or –recon or –no-act: This option clearly states that nothing should be done. Instead, a simulation of what would happen if the system as it is now were to continue is run.
apt-get -s [...COMMAND]
  • -y or –yes or –assume-yes: The user may occasionally be asked a yes/no question while the apt-get command is running. With this option, it is defined that it should run automatically and presume "yes" for all questions.
apt-get -y [...COMMAND]
  • –assume-no: Apt-get assumes "no" for all prompts when this option is selected.
apt-get --assume-no [...COMMAND]
  • –no-show-upgraded: This setting prevents apt-get from displaying a list of every package that has to be upgraded.
apt-get --no-show-upgraded [...COMMAND]
  •   -V or –verbose-versions: With this option, apt-get will show user-friendly progress in the terminal window while the packages are installed, deleted, or upgraded.
apt-get -V [...COMMAND]
  • –Show-progress: With this selection, apt-get will display user-friendly progress during the installation, removal, or upgrade of the packages in the terminal window.
apt-get --show-progress [...COMMAND]
  • -b or –compile or –build: This setting instructs apt-get to build the source packages it downloads.
apt-get -b [...COMMAND]
  • –no-upgrade: If the packages are already installed, apt-get won't allow them to be upgraded.
apt-get --no-upgrade [...COMMAND]
  • –Only-upgrade: With this selection, apt-get won't install any new packages; it will only upgrade the existing packages.
apt-get --only-upgrade [...COMMAND]
  • –reinstall: When using this option, apt-get updates any already installed packages to the most recent versions.
apt-get --reinstall [...COMMAND]
  • –Auto-remove or –autoremove: This option functions as the autoremove command when executing the install or remove command with apt-get.
apt-get install/remove --autoremove [...PACKAGES]
  • -h or –help: A brief usage summary is shown by apt-get using this option.
apt-get -h

Output

  1. -v or –version: The current version number of apt-get is displayed using this option.
apt-get  [...COMMAND]
Linux apt-get command

Output

Linux apt-get command

Note: - The apt-get command returns zero (zero) for successful executions and one hundred (one hundred) for errors.