This tutorial explains the steps required to update Ubuntu 18.04 and also clean the older packages which are not required anymore. The same commands can be used for older versions of Ubuntu.
Update
The update command updates the list of available packages and versions. It does not make any changes to the installed packages, nor install any new packages. The command can be used as shown below.
# Update directly apt-get update
# Update using sudo sudo apt-get update
Upgrade
The packages installed on Ubuntu can be updated using below mentioned commands. These will update all the packages having a newer version as compared to the installed version.
# Upgrade directly apt-get upgrade
# Upgrade using sudo sudo apt-get upgrade
# OR
# Upgrade directly apt-get dist-upgrade
# Upgrade using sudo sudo apt-get dist-upgrade
The major difference between the commands upgrade and dist-upgrade is that upgrade simply install the newer version of the packages already installed on the system, but dist-upgrade not only install the newer version, it also remove or install new packages as part of the package update.
If we install a package using an upgrade and it needs to either remove or install other packages, the update will be held back without making changes to other packages. We can later use the command dist-upgrade to complete the update process after making sure that the changes won't bring any major issue.
Autoclean
The command
# Update directly apt-get autoclean
# Update using sudo sudo apt-get autoclean
Autoremove
The command
# Update directly apt-get autoremove
# Update using sudo sudo apt-get autoremove
# OR apt-get --purge autoremove
Using purge will also remove the files associated with the package.
These are the commands required to update the packages installed on the system.