Notes on APT Commands in Linux

  • Introduction to APT

  • APT (Advanced Package Tool) is a command-line tool used for managing packages on Debian-based systems such as Debian, Ubuntu, and Linux Mint.

  • It allows users to install, update, and remove software packages easily.

  • Initial Setup

  • To use APT commands, you typically need superuser (root) access. Use sudo before commands to execute as root.

  • Example: sudo apt update refreshes the package index, ensuring you have the latest list of software available from repositories.

  • Updating Package Index

  • The command apt update:

    • Connects to defined repositories and retrieves the latest package lists.
    • Does not install or upgrade any packages - it simply updates the index.
  • Installing Packages

  • To install a package, use the command:

    • sudo apt install <package_name> (e.g., sudo apt install tmux).
  • Dependencies: APT automatically installs any additional packages required for the main package to work.

  • Confirmation: You will be prompted to confirm installation (Y/n). Capital Y is the default option.

  • Installing Multiple Packages

  • You can install multiple packages at once by adding their names in the same command:

    • Example: sudo apt install package1 package2 package3.
  • Removing Packages

  • To remove a package, the command is:

    • sudo apt remove <package_name> (e.g., sudo apt remove htop).
  • Confirmation of removal is required.

  • Searching for Packages

  • If you are unsure of the exact package name, use:

    • apt search <keyword> (e.g., apt search vim).
  • This will list all packages matching the keyword, helping to identify the correct package to install.

  • Updating Installed Packages

  • To update all installed packages to their latest versions:

    • First run sudo apt update to refresh the index.
    • Then, use sudo apt upgrade to apply updates.
    • Alternatively, sudo apt dist-upgrade can be used to upgrade packages that involve changes in dependencies as well.
  • APT Upgrade vs Dist-Upgrade

  • apt upgrade: Upgrades installed packages:

    • Does not install or remove packages, only upgrades existing ones.
  • apt dist-upgrade: Upgrades installed packages but also handles dependency changes:

    • Installs or removes packages as necessary to perform the upgrades.
  • Managing Sources

  • APT sources are specified in /etc/apt/sources.list.

  • Editing this file allows you to add new repositories; be cautious as incorrect entries can hinder package management.

  • Adding non-free at the end of repository lines allows installation of packages without open-source licenses.

  • After changes, always run sudo apt update to refresh the package index.

  • Conclusion

  • Mastering APT provides powerful tools for managing packages on Debian-based systems.

  • Commands for installation, removal, updates, and source management are straightforward and efficient.

  • Engage with more learning materials for deeper insights into Linux commands and functionalities.