0

On an ordinary AWS Ubuntu instance, I see exactly this:

enter image description here

I believe the three possible commands involved are

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade

So there are 21 possible permutations.

In spite of searching the vast discussion on this (try it) I cannot find the definitive answer!

What is the correct permutation?

  • Which commands
  • in which order,

definitively should one enter in that situation?

4
  • On my Linux systems (Ubuntu and Kali) I do the first command (sudo apt-get update) to get a list of updates, allow it to finish, and then to the second command (sudo apt-get upgrade) to do the download and update. That works well for me.
    – anon
    Commented Feb 25, 2020 at 13:23
  • There isn’t a correct or incorrect order.
    – Ramhound
    Commented Feb 25, 2020 at 13:28
  • @Ramhound , you're probably an expert and that's perhaps obvious to you. But. If you search on this, there is a HUGE amount of debate about whether that is true or not. Also, it is unclear if all three are even needed. Hence the question!
    – Fattie
    Commented Feb 25, 2020 at 13:31
  • It's astonishing there are no experts with opinions on this !
    – Fattie
    Commented Feb 26, 2020 at 13:20

1 Answer 1

1

I often use this command to update my Ubuntu:

sudo apt update && sudo apt upgrade -y

Here is the detailed information from the source:

It will ask for a password. You can use your account’s password. You won’t see characters on the screen while typing, so keep on typing your password and hit enter. This will update the packages in Ubuntu.

Now let me explain the above command.

It’s actually not a single command, it’s a combination of two commands. The && is a way to combine two commands such that the second command runs only when the previous command ran successfully.

The “-y” in the end automatically enters “yes” when the command “apt upgrade” ask for your confirmation before installing updates.

Note that you can also use the two commands separately, one by one:

sudo apt update
sudo apt upgrade

It will take a little longer, because you have to wait for one command to finish and then enter the second command.

Explanation: sudo apt update

This command updates the local database of available packages. If you don’t run this command, the local database won’t be updated and your system will not know if there are any new versions of packages available.

This is why, when you run the “sudo apt update” command, you’ll see lots of URLs in the output. The command fetches the package information from the respective repositories (the URLs you see in the output).

enter image description here

At the end of the command, it tells you how many packages can be upgraded. You can see these packages by running the following command:

apt list --upgradable

Explanation: sudo apt upgrade

This command matches the versions of installed packages with the local database. It collects all of them, and then it will list those packages that have a newer version available. At this point, it will ask if you want to upgrade the installed packages to the newer version.

You can type “yes,” or “y,” or just press enter to confirm the installation of updates.

So the bottom line is that “sudo apt update” checks for the availability of new package versions, while “sudo apt upgrade” actually installs the new versions.

upgrade upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.

dist-upgrade

dist-upgrade in addition to performing the function of upgrade,
also intelligently handles changing dependencies with new versions
of packages; apt-get has a "smart" conflict resolution system, and
it will attempt to upgrade the most important packages at the
expense of less important ones if necessary. So, dist-upgrade
command may remove some packages. The /etc/apt/sources.list file
contains a list of locations from which to retrieve desired package
files. See also apt_preferences(5) for a mechanism for overriding
the general settings for individual packages.

Source: How To Update Ubuntu With Command Line And Software Updater

2
  • this really does not address sudo apt-get dist-upgrade
    – Fattie
    Commented Feb 26, 2020 at 10:44
  • dist-upgrade in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary. So, dist-upgrade command may remove some packages. The /etc/apt/sources.list file contains a list of locations from which to retrieve desired package files. See also apt_preferences(5) for a mechanism for overriding the general settings for individual packages.
    – Mike D
    Commented Feb 26, 2020 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .