Ubuntu – Is there any command to list “local” packages? like in Synaptic GUI

aptaptitudedpkgpackage-management

I used to look for local packages using Synaptic. Those packages which are locally installed but have no exact match in the current active repositories. As it is explained in this post: What does “local or obsolete” mean in Synaptic.

I finds that feature very helpful when it comes to debugging unmet dependencies issues. While I know how to get list of obsolete packages, I couldn't find a way for local packages.

So, is there any equivalent command line that lists all local packages?

Note to explain idioms I used.

  • orphan package: installed automatically as dependency, then dependent was removed.
  • obsolete package: installed but no package with same (name,architecture) in the repository.
  • local package: installed but no package with same (name,architecture,version) in the repository.

So I don't mean the all installed packages.

Test Case

  1. Synaptic → Menu:Settings → Repositories → Updates: Enable Unsupported Updates (backports) (Note: I use it as PPA example)
  2. Reload package lists
  3. Search for debhelper, select it. Menu:Packages → Force Version …: Select and install the version from backports (Usually the highest version)
  4. Menu:Settings → Repositories → Updates: Disable Unsupported Updates (backports) (Note: I use it as PPA example)
  5. Reload package lists

Compare now between these two lists:

  1. Synaptic → SideBar:Status → Installed (local & obsolete)

    Synaptic - local & obsolete packages

  2. aptitude search '~o'

    user@user-vb:~$ aptitude search '~o'
    i A linux-headers-4.15.0-19                          - Header files related to Linux kernel version 4.15.0        
    i A linux-headers-4.15.0-19-generic                  - Linux kernel headers for version 4.15.0 on 64 bit x86 SMP  
    i A linux-image-4.15.0-19-generic                    - Signed kernel image generic                                
    i A linux-modules-4.15.0-19-generic                  - Linux kernel extra modules for version 4.15.0 on 64 bit x86
    i A linux-modules-extra-4.15.0-19-generic            - Linux kernel extra modules for version 4.15.0 on 64 bit x86
    user@user-vb:~$ 
    

Best Answer

Find installed packages that does not originate from any source.list or cannot be downloaded.

$ aptitude search \
  '?narrow(?or(!?origin(), ?obsolete), ?installed)'

Or short form:

$ aptitude search '~S (!~O|~o)  ~i'
  • ?narrow(filter, pattern)
    Select packages which matches both filter and pattern.
  • ?or(pattern, pattern)
    Matches any of the patterns or both.
  • ?origin(pattern)
    Select packages with given origin.
  • ?obsolete
    Matches installed packages that cannot be downloaded.
  • ?installed
    Select installed packages.
  • ?not(pattern) or !
    Select any package not matching the pattern.