13

Does anybody know why apt-file reports that the cache is empty even after running apt-file update and apt update?

[pop-os ~][I]% apt-file search /usr/lib/android-sdk/tools/bin/sdkmanager
E: The cache is empty. You need to run "apt update" first.
[pop-os ~][I]% apt-file update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
[pop-os ~][I]% sudo !!
sudo apt-file update
Hit:1 http://apt.pop-os.org/proprietary cosmic InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu cosmic InRelease          
Hit:3 http://us.archive.ubuntu.com/ubuntu cosmic-updates InRelease                           
Hit:4 http://ppa.launchpad.net/nextcloud-devs/client/ubuntu cosmic InRelease                 
Hit:5 http://us.archive.ubuntu.com/ubuntu cosmic-security InRelease      
Hit:6 http://repository.spotify.com stable InRelease                                         
Hit:7 http://us.archive.ubuntu.com/ubuntu cosmic-backports InRelease                         
Get:8 http://apt.pop-os.org/proprietary cosmic all Contents (deb) [102 kB]                   
Hit:9 http://ppa.launchpad.net/system76/pop/ubuntu cosmic InRelease                  
Get:10 http://us.archive.ubuntu.com/ubuntu cosmic amd64 Contents (deb) [40.9 MB]             
Get:11 http://apt.pop-os.org/proprietary cosmic i386 Contents (deb) [276 B]                  
Get:12 http://apt.pop-os.org/proprietary cosmic amd64 Contents (deb) [2,605 kB]              
Get:13 http://us.archive.ubuntu.com/ubuntu cosmic i386 Contents (deb) [40.2 MB]              
Get:14 http://us.archive.ubuntu.com/ubuntu cosmic-updates i386 Contents (deb) [5,178 kB]     
Get:15 http://us.archive.ubuntu.com/ubuntu cosmic-updates amd64 Contents (deb) [6,997 kB]    
Get:16 http://us.archive.ubuntu.com/ubuntu cosmic-security i386 Contents (deb) [3,784 kB]    
Get:17 http://us.archive.ubuntu.com/ubuntu cosmic-security amd64 Contents (deb) [5,296 kB]   
Get:18 http://us.archive.ubuntu.com/ubuntu cosmic-backports amd64 Contents (deb) [3,773 B]   
Get:19 http://us.archive.ubuntu.com/ubuntu cosmic-backports i386 Contents (deb) [3,772 B]    
Fetched 105 MB in 21s (4,952 kB/s)                                                           
Reading package lists... Done
Building dependency tree       
Reading state information... Done
148 packages can be upgraded. Run 'apt list --upgradable' to see them.
sudo -E apt-file update  20.30s user 1.16s system 95% cpu 22.585 total
[pop-os ~][I]% apt-file search /usr/lib/android-sdk/tools/bin/sdkmanager
E: The cache is empty. You need to run "apt update" first.
[pop-os ~][I]% apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
[pop-os ~][I]% sudo !!
sudo apt update
Hit:1 http://apt.pop-os.org/proprietary cosmic InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu cosmic InRelease                                   
Hit:3 http://us.archive.ubuntu.com/ubuntu cosmic-updates InRelease                           
Hit:4 http://us.archive.ubuntu.com/ubuntu cosmic-security InRelease                          
Hit:5 http://ppa.launchpad.net/nextcloud-devs/client/ubuntu cosmic InRelease                 
Hit:6 http://us.archive.ubuntu.com/ubuntu cosmic-backports InRelease     
Get:7 http://apt.pop-os.org/proprietary cosmic i386 Contents (deb) [276 B]                   
Hit:8 http://repository.spotify.com stable InRelease                                         
Get:9 http://apt.pop-os.org/proprietary cosmic all Contents (deb) [102 kB]                   
Hit:10 http://ppa.launchpad.net/system76/pop/ubuntu cosmic InRelease                 
Get:11 http://us.archive.ubuntu.com/ubuntu cosmic amd64 Contents (deb) [40.9 MB]       
Get:12 http://apt.pop-os.org/proprietary cosmic amd64 Contents (deb) [2,605 kB]              
Get:13 http://us.archive.ubuntu.com/ubuntu cosmic i386 Contents (deb) [40.2 MB]              
Get:14 http://us.archive.ubuntu.com/ubuntu cosmic-updates i386 Contents (deb) [5,178 kB]     
Get:15 http://us.archive.ubuntu.com/ubuntu cosmic-updates amd64 Contents (deb) [6,997 kB]    
Get:16 http://us.archive.ubuntu.com/ubuntu cosmic-security amd64 Contents (deb) [5,296 kB]   
Get:17 http://us.archive.ubuntu.com/ubuntu cosmic-security i386 Contents (deb) [3,784 kB]    
Get:18 http://us.archive.ubuntu.com/ubuntu cosmic-backports i386 Contents (deb) [3,772 B]    
Get:19 http://us.archive.ubuntu.com/ubuntu cosmic-backports amd64 Contents (deb) [3,773 B]   
Fetched 105 MB in 21s (4,963 kB/s)                                                           
Reading package lists... Done
Building dependency tree       
Reading state information... Done
148 packages can be upgraded. Run 'apt list --upgradable' to see them.
sudo -E apt update  20.24s user 1.15s system 95% cpu 22.470 total
[pop-os ~][I]% apt-file search /usr/lib/android-sdk/tools/bin/sdkmanager
E: The cache is empty. You need to run "apt update" first.
[pop-os ~][I]% sudo !!
sudo apt-file search /usr/lib/android-sdk/tools/bin/sdkmanager
E: The cache is empty. You need to run "apt update" first.

Distro is Pop!_OS (an Ubuntu derivative), but I couldn't find a Pop!_OS tag.

6
  • I'm getting this too. Did you solve it?
    – Paul Knopf
    Commented Apr 27, 2019 at 17:36
  • @PaulKnopf no, I never figured it out, unfortunately. Still looking for a solution.
    – jayhendren
    Commented Apr 27, 2019 at 22:11
  • This happened to me with a fresh installation of elementaryOS 5.0 (Freya) as well. Still trying to figure it out.
    – Kevin E
    Commented May 16, 2019 at 16:05
  • This issue magically went away on its own after some routine apt updates. I wasn't really paying too much attention so I'm not sure exactly which package updates fixed the issue, but everything's working now, so... yay, I guess?
    – jayhendren
    Commented May 16, 2019 at 17:04
  • 1
    Just ran into this issue again, four years later, on a different computer. On the bright side, one of the proposed solutions actually worked this time.
    – jayhendren
    Commented Jun 7, 2023 at 18:28

4 Answers 4

3

I was able to fix this on Pop!_OS 22.04 by clearing out /var/lib/apt/lists/ and then updating apt again:

sudo rm -rf /var/lib/apt/lists/*_*
sudo apt-get update
apt-file search sdkmanager

I found the hint here: https://unix.stackexchange.com/a/575356/243015

edit: After running apt-get install <foo> apt-file quit working again.

1
  • Ran into this issue again four years after I originally posted this question. This seemed to do the trick. Hopefully I won't have to do this again after every package install :)
    – jayhendren
    Commented Jun 7, 2023 at 18:29
1

Not a solution to the original problem, but I don't have enough reputation to comment...

I got this error as well and as an alternative it was suggested to use the Ubuntu package search: https://packages.ubuntu.com/search?keywords=search

I think a search at https://packages.ubuntu.com is nice, but I want to do this from the terminal. So I wrote a little Python CLI app called apt-search, that does the search query, parses the HTML and gives a nice output.

You can find it here: https://pypi.org/project/apt-search/

You can install it with pip / pipx and use it like

apt-search /usr/lib/android-sdk/tools/bin/sdkmanager
# No package found for file '/usr/lib/android-sdk/tools/bin/sdkmanager'!

apt-search sdkmanager
# sdkmanager: /usr/bin/sdkmanager
# sdkmanager: /usr/share/bash-completion/completions/sdkmanager
0

I can't explain why, but I did manage to get it to work. I was trying to run apt-file search metaflac - it did not work - I ran:

apt-file list google-chrome
apt-file -v search metaflac

and it just worked. I don't know whether it was the list command or asking for a verbose search that made it work so I thought I'd give you both.

-1

YMMV, The following resolved an issue like this for me.

You are doing:

sudo apt update
sudo apt-file update

But you are missing

sudo apt-get update

From the (more recent the OP) apt-file man page:

update:
This action that just calls apt update or apt-get update (depending on whether a tty is available).

The only advantage using this over a regular apt update or apt-get update directly is for the case where you have configured an apt-file specific configuration (via the Dir::Etc::apt-file-main configuration option). In that case, said configuration will be included automatically.

Feels to me like there is a bug with apt-file update in which it does not call apt-get update but actually relies on that database.

3
  • 1
    Running an apt-get update first does not resolve the issue.
    – jayhendren
    Commented Jun 7, 2023 at 18:25
  • I think you're on to something—running an extra sudo apt update did appear to fix this problem for me. However, you might be misunderstanding that sudo apt update and sudo apt-get update do the same thing, as far as I know, apt being more or less just a friendlier wrapper around apt-get and apt-cache.
    – Kevin E
    Commented Jan 11 at 17:48
  • I also agree that this looks like a bug in apt-file itself.
    – Kevin E
    Commented Jan 11 at 17:50

You must log in to answer this question.

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