To update all installed packages to their latest versions, including security updates, on Ubuntu 22.04 or 20.04, you can use the following command:
sudo apt update && sudo apt upgrade -y
This command first updates the package lists, then upgrades all currently installed packages to their latest versions. The -y
flag is used to automatically answer yes to any prompts during the upgrade process.
You can also use the command below if you only want to install security updates:
sudo apt update && sudo apt upgrade -y --only-upgrade
You can also use the command below for a more precise security update:
sudo apt update && sudo apt dist-upgrade -y
It is also recommended to run a command for cleaning the package manager’s cache after an update:
sudo apt autoclean && sudo apt autoremove
It will remove all the packages that are no longer needed by your system.
It is also a good practice to reboot your system after the updates have been installed, to ensure that any changes that may have been made to system files take effect.