apt Command in Linux

Learn via video courses
Topics Covered

Overview

The Advanced Packaging Tool, apt command in Linux, is a powerful command-line tool used for handling packages in Ubuntu/Debian-based systems. It provides powerful, consistent command-line interfaces for package management and takes care of dependencies automatically.

Syntax of apt Command in Linux

The basic syntax of the apt command in Linux is as follows:

Where:

  • options: Options are the optional flags that can be used with the apt command to modify its behavior. For example, '-y' is used to answer 'yes' to all prompts.
  • command: This is the action you want to perform, such as install, remove, upgrade, etc.

Options in apt Command in Linux

  1. -y: This option is used to answer 'yes' to all prompts during the operation.

    For example -

    Output:

    The '-y' option instructs apt to proceed with all actions without asking for confirmation.

  2. --show-progress: This option is used to display the progress during the operation.

    For example -

    Output:

    The '--show-progress' option makes apt show a progress indicator during the operation.

  3. --fix-broken: This option attempts to correct a system with broken dependencies in place.

    For example -

    Output:

    The '--fix-broken' option commands apt to try and fix unresolved dependencies.

Example Usages

  • Installing a package.:

    Output:

    Explanation: The 'install' command is used to install a new package, in this case, Vim text editor.

  • Upgrading all upgradable packages.:

    Output:

    Explanation: The 'upgrade' command upgrades all the upgradable packages in the system.

Tips

  • Always use 'sudo apt update' before 'sudo apt upgrade' to ensure your package lists are up-to-date.

  • Use 'sudo apt autoremove' to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

Advanced Use Cases of apt Command in Linux

  • Use 'dist-upgrade' command to intelligently handle changing dependencies.:

    Output:

    Explanation: The 'dist-upgrade' command will upgrade your system by handling changing dependencies with new versions of packages.

  • Use 'full-upgrade' command which performs the function of upgrade but also removes installed packages if needed.:

    Output:

    Explanation: The 'full-upgrade' command performs the same function as 'upgrade' but will remove currently installed packages if necessary.

  • Hold a package using 'hold' command to prevent it from being automatically installed, upgraded or removed.:

    Output:

    Explanation: The 'hold' command is used to mark a package to hold back its installation or upgrade.

Conclusion

  • The apt command in Linux is a powerful tool for managing packages in Ubuntu and Debian-based systems.

  • It simplifies the process of installing, upgrading, and removing software packages.

  • Advanced options and commands allow fine-grained control over your system's software packages and dependencies.