update Command in Linux

Learn via video courses
Topics Covered

Overview

In the Linux operating system, staying updated is crucial for maintaining security and having access to the latest features. The update command for Linux plays a vital role in this. It allows users to update the system's package list, upgrade existing software packages, and install the latest patches.

Syntax of update Command in Linux

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

Where:

  • sudo: 'sudo' is a prefix that stands for 'SuperUser Do'. It provides administrative privileges, necessary for making changes to the system.
  • apt-get or apt: 'apt-get' or 'apt' is the package handling utility in Debian-based Linux distributions. It allows for operations like installing, upgrading, and removing software.
  • update: 'update' is the operation that updates the list of available packages and their versions, but it does not install or upgrade any packages.

Options in update Command in Linux

  1. --show-upgraded: This option will show a list of packages that are available for upgrade.

    For example -

    Output:

    This command lists the packages that can be upgraded on the system.

  2. --quiet: This option operates in a quiet mode, reducing the amount of output.

    For example -

    Output:

    This command updates the package list with less output to the terminal.

  3. --assume-yes: This option will automatically answer yes to prompts and run non-interactively.

    For example -

    Output:

    This command updates the package list without any interactive prompts.

Example Usages

  • Basic usage of the update command in Linux:

    Output:

    Explanation: This command fetches the list of available updates from the repositories and updates the local package index.

  • Using update command followed by upgrade:

    Output:

    Explanation: This command first updates the list of packages and then upgrades all the upgradable packages on the system.

Tips

  • Always use 'sudo' with the update command to avoid permission issues.

  • It's recommended to follow the 'update' command with the 'upgrade' command to install available updates.

  • Use the '--assume-yes' option for automatic script-based updates.

Advanced Use Cases of update Command in Linux

  • Using update command with -y option for non-interactive updates:

    Output:

    Explanation: This command updates the package list and assumes yes to all prompts, ideal for scripting purposes.

  • Update and upgrade in a single command with -y option:

    Output:

    Explanation: This command first updates the package list and then upgrades all the upgradable packages, assuming yes to all prompts.

  • Update, upgrade, and autoremove in a single command:

    Output:

    Explanation: This command not only updates and upgrades the packages but also removes unnecessary packages after upgrading.

Conclusion

  • The 'update' command for Linux is a fundamental command for system maintenance.

  • To update the package lists for upgrades and new package installations, use 'sudo apt-get update' or 'sudo apt update'.

  • For a complete system update, use the 'upgrade' command after the 'update' command.