34

I'm trying to figure out a way to get a list of the packages that are no longer available in the repositories that I have enabled. This workstation has been through quite a few versions of Ubuntu and has had many 3rd party repositories added and removed. I'd like to get a list of software that I have from these removed repositories, so I can clean it up or add back the appropriate repositories.

0

7 Answers 7

36
aptitude search '~o'

Aptitude has some very powerful searching available. Unfortunately the syntax is a bit unwieldy and you have to dig past the manpage to find the documentation, but its worth it.

apt-show-versions can also be helpful:

apt-show-versions | grep 'No available version'
3
  • 1
    see a nice article about obsolete packages here: raphaelhertzog.com/2011/02/07/…
    – Lluís
    Mar 8, 2014 at 11:02
  • 3
    Another useful list is generated by apt-show-versions | grep "newer than version in archive"
    – Sean
    Jan 6, 2017 at 14:40
  • I think apt-show-versions is the best simply because the aptitude line is extremely counter-intuitive to remember. Every single time I need it I have to google it/look it up/save it/make a script/etc.
    – j riv
    Jun 17, 2018 at 7:40
21

Starting with Ubuntu 19.10 it is also possible to run

apt list ?obsolete

to get the list of obsolete packages.

For any release you could use the following Bash one-liner:

comm -23 <(dpkg-query -W -f '${db:Status-Abbrev}\t${Package}\n' | grep '^.[^nc]' | cut -f2 | sort) <(apt-cache dumpavail | sed -rn 's/^Package: (.*)/\1/p' | sort -u)

No need to install extra packages for this, plus this is relatively fast. This will also find partially installed packages (but will not find those that have only configuration files remaining; that could be changed easily, though). Note: this does not care of which architecture the packages are.

If you want to include packages that have a different version installed than what is available from the repositories, you could you one of the following:

Use modern apt:

 apt list --installed | awk -F/ '/\[installed,local\]/{print $1}'

As for Bionic (and maybe for earlier releases) there is yet another option:

ubuntu-support-status --show-unsupported

read the package names under "No longer downloadable:" section.

If you use Focal or later release, you can use

ubuntu-security-status --unavailable

instead; you can read the package names below text "packages are no longer available for download". This is not the fastest option. This command has been replaced later by

pro security-status --unavailable
2
  • 1
    ‘apt list --manual-installed | grep -v cosmic‘ shows false positives. This answer is much better! Sep 18, 2019 at 15:08
  • 1
    @TamusJRoyce, yes, I suppose so now after editing.
    – jarno
    Sep 18, 2019 at 16:18
9

To get a list of apps that are not in a Registered Repository or PPA do this:

sudo apt-get install apt-show-versions
apt-show-versions | grep 'No available version'

That should output text like this:

app1 1.0.0.14 installed: No available version in archive
app23 0.3.6 installed: No available version in archive
app332 7.0.9377 installed: No available version in archive

For me this worked and showed three apps I installed using DEB packages and weren't available in a Repo or PPA.

Do remember though that it's impossible to check for all programs, only the ones that went through dpkg. For instance, some apps are installed by simply extracting them into the correct folders, or others use a standalone installer bin or script. So the best way is for you yourself to keep a list of apps you installed via any method other than APT.

2
  • Works for all my local dpkg installed packages. One exception. It lists skype-bin, whereas apt-cache policy skype-bin clearly shows the Canonical partner repo. I'm not sure what is going on. Multiarch issue? Still +1 for apt-show-versions!
    – gertvdijk
    Jan 5, 2013 at 21:37
  • aptitude calls these 'obsolete' packages. See chronitis comment above.
    – Henk Poley
    Mar 5, 2013 at 16:54
7

If you have aptitude installed use,

aptitude search '?obsolete'

or its short form

aptitude search '~o'

Here it is a sample output

i A gcc-4.7-base - GCC, the GNU Compiler Collection (base package)
id  libdb4.7     - Berkeley v4.7 Database Libraries [runtime]
i   libudev0     - libudev shared library

The first character of each line indicates the current state of the package. The most common states are:

  • p, meaning that no trace of the package exists on the system,
  • c, meaning that the package was deleted but its configuration files remain on the system,
  • i, meaning that the package is installed, and
  • v, meaning that the package is virtual.

The second character indicates the stored action to be performed on the package, if any, otherwise a blank space is displayed. The most common actions are:

  • i, meaning that the package will be installed,
  • d, meaning that the package will be deleted, and
  • p, meaning that the package and its configuration files will be removed.

If the third character is A, the package was automatically installed.

For a complete list of the possible state and action flags, see the section Accessing Package Information in the aptitude reference guide.

6
  • 1
    aptitude search ?obsolete may work in bash, but you should use aptitude search '?obsolete'
    – A.B.
    Jul 1, 2015 at 18:28
  • could you add some detail on parsing the output?
    – Elder Geek
    Jul 2, 2015 at 1:54
  • Is '?obsolete' different from '~o'?
    – Sean
    Jul 2, 2015 at 18:20
  • @Sean No, they are not different. ~o is the short form for ?obsolete indeed. Jul 2, 2015 at 23:00
  • The quotes are parsed out by the shell. I think what A.B. meant is that you shouldn't pass weird character unescaped on the command line because you don't know what your shell is going to do with them.
    – Sean
    Jul 3, 2015 at 19:29
1

More info to investigate.

ubuntu-support-status 
echo "$(sudo apt-mark showmanual | wc -l) packages marked as 'manually installed'."

... ubuntu-support-status and apt-mark may require installation.

3
  • No need to use sudo with apt-mark showmanual.
    – jarno
    Sep 18, 2019 at 16:20
  • ubuntu-support-status lists the number of obsolete packages, but not the package names.
    – jarno
    Sep 18, 2019 at 16:47
  • 1
    Read the output of ubuntu-support-status --help
    – Hannu
    Sep 19, 2019 at 17:16
0

There may be a cleaner way, but off the top of my head you can do

dpkg -l | cut -f 3 -d ' ' > installed
xargs -n 1 --replace=X apt-cache search ^X$ < installed | cut -f 1 -d ' ' > available
diff installed available

Cleanup the first few lines of the installed file: it will have headers.

Bonus if anyone can fix my syntax highlighting...

6
  • 2
    if you are going to use the output of dpkg -l to get a list of installed packages, you should limit the results to lines with 'i' in the second column, as dpkg will also list packages which are not installed (perhaps removed but not purged). as an example, altering your first command to be dpkg -l | grep '^.[^i]' | cut -f 3 -d ' ' it would return a list of packages, which are NOT installed. (but once were)
    – stew
    Jan 24, 2012 at 19:46
  • 1
    also, apt-cache search someinstalledpackage will return something even if the package isn't available from a repo, so I don't believe this will work at all.
    – stew
    Jan 24, 2012 at 19:54
  • 1
    @stew I'll leave this up here to see if anybody reaches conclusions, but your answer is definitely far better. +1 to you. Jan 24, 2012 at 19:59
  • @stew dpkg -l | grep '^.[^i]' | cut -f 3 -d ' 'also prints some header lines.
    – jarno
    Sep 18, 2019 at 5:32
  • Even if this answer worked, it would be very slow as it would run apt-cache search for each package separately.
    – jarno
    Sep 18, 2019 at 16:56
-1

As mentioned apt-get search is not a good method to check if a package is still available. Additional I've added everything to just one line:

for i in `dpkg -l | grep '^i' | awk '{ print $2 }'`; do apt-cache show $i > /dev/null || echo $i; done
4
  • And why grep '^i'
    – A.B.
    Sep 22, 2015 at 11:24
  • @A.B. good point; that does not tell, if the package is installed, but that the package's desired action is to be installed. See man dpkg-query for more information.
    – jarno
    Sep 17, 2019 at 10:26
  • This is very slow
    – jarno
    Sep 17, 2019 at 11:42
  • apt-cache show does is neither good for checking if the package is availabe. If you disable the respective repository, and no other enabled repository has it, it still shows the package.
    – jarno
    Sep 21, 2019 at 10:18

You must log in to answer this question.

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