TranslateProject/sources/tech/20220712 List Upgradable Packages With apt Command in Ubuntu.md

7.4 KiB
Raw Blame History

List Upgradable Packages With apt Command in Ubuntu

The apt command is used for package management in Debian and Ubuntu. While you are probably already familiar with the install and remove options, apt provides a few extra features as well.

One of them is the ability to see all the upgradable packages on your system. And to display them, all you have to do is to use this command in the terminal:

apt list --upgradable

As you can notice, you dont even need sudo to list the updatable packages. It just lists the packages that can be updated. It doesnt update them.

In fact, the apt command adds this hint when you run the sudo apt update command to update the local package repository cache.

Fetched 1,243 kB in 17s (71.4 kB/s)           
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
30 packages can be upgraded. Run 'apt list --upgradable' to see them.

I dont recall any similar direct option in the older apt-get command to list all the upgradable packages. Thats one of the several new features apt has added on top of the older apt-get command.

Lets talk about it in a bit more detail.

Listing all the upgradable packages

What you should know here is that you only get to list the updates available through the APT package manager. So, if you have added PPAs or external repositories to your systems sources.list, youll see the updates from them.

But you wont get updates for AppImage, Flatpak, Snap or some other packaging formats here.

In other words, it works with apt packages only.

So, to list all the upgradable packages on your Ubuntu or Debian system, you should update the local package cache first:

sudo apt update

And then your system will be aware of the available package updates. The apt command tells you how many packages can be upgraded at the end of the update command:

The apt command shows the number of upgradable packages at the bottom of the apt update command output

To see what package can be upgraded, run the command:

apt list --upgradable

You should see an output like this:

[email protected]:~$ apt list --upgradable 
Listing... Done
apparmor/jammy-updates 3.0.4-2ubuntu2.1 amd64 [upgradable from: 3.0.4-2ubuntu2]
brave-browser/stable 1.40.113 amd64 [upgradable from: 1.40.107]
evolution-data-server-common/jammy-updates,jammy-updates 3.44.2-0ubuntu1 all [upgradable from: 3.44.1-0ubuntu2]
evolution-data-server/jammy-updates 3.44.2-0ubuntu1 amd64 [upgradable from: 3.44.1-0ubuntu2]

Listing all the upgradable packages

It lists all the upgradable packages in alphabetical order with the information on the currently installed version and the new available package version.

brave-browser/stable 1.40.113 amd64 [upgradable from: 1.40.107]

For example, It shows that I have Brave browser version 1.40.107 installed on the system, and version 1.40.113 is available.

What can you do with this information? Let me share a few things I can think of.

Upgrade all the packages

This is probably what most casual Ubuntu users do. You can upgrade all the upgradable packages with the following command:

sudo apt upgrade

It lists what packages will be upgraded and then asks to confirm the upgrade by pressing enter or Y.

Upgrade all packages

If you are sure about upgrading all the packages, you can skip the Do you want to continue part by giving it the go ahead by adding -y to the command.

sudo apt upgrade -y

Simulate an upgrade (but dont upgrade any packages)

This is what people did before the apt list command. With the simulate option, you dont actually make any changes. It just shows what packages will be installed or upgraded if you run the upgrade.

apt -s upgrade

You dont need to use sudo (even though I have used it in the screenshot below).

Running an upgrade simulation with apt command

Upgrade only the selected packages

If you are managing an Ubuntu server and you dont want to upgrade all the packages but only one of a few selected ones (like MySQL/Ngnix), you can do that easily with the apt command.

sudo apt --only-upgrade install package_name

Actually, if you run the apt install command on an already installed package for which an update is available, it will upgrade the package.

With the --only-upgrade flag, you ensure that a package is only upgraded (if it is already installed). It wont install the given package if it is not already installed.

You can also upgrade selected few packages by providing their name:

sudo apt --only-upgrade install package1 package2

You can also do the opposite and hold selected packages from the upgrade.

sudo apt-mark hold package_name

With that, the given package wont be upgraded when you upgrade all the system packages.

You can remove the hold with this command:

sudo apt-mark unhold package_name

Does it show the kernel upgrades?

This is kind of tricky.

When you run the apt list upgradable command it shows all the packages that can be upgraded.

But if there are new kernel versions available, they might not be shown since the kernel package name starts with linux-headers-x-y. Its because the system treats them as new packages, not an upgrade on already installed package linux-headers-a-b.

However, you would still see “linux-generic-hwe” kind of package in the list of upgradable packages. Because that package will be upgraded (with the newer kernel).

Conclusion

The ability to list upgradable packages is one of the several new features the apt command brought over the older apt-get command. For more on this topic, you can read my article explaining the difference between the apt and apt-get commands.

As a desktop user, I dont always check the packages that can be upgraded. I go for the upgrade straightaway. However, when I am managing a server, I prefer to see what updates are available and then decide whether or not I am going for an upgrade.

How about you? Do you see a good use for this feature for yourself?


via: https://itsfoss.com/apt-list-upgradable/

作者:Abhishek Prakash 选题:lkxed 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出