Debian/Ubuntu - How to restore /var/cache/apt structure after deleting it?
30,178
Solution 1
You need two things there:
sudo mkdir -p /var/cache/apt/archives/partial
sudo touch /var/cache/apt/archives/lock
sudo chmod 640 /var/cache/apt/archives/lock
Removing this directory manually is a bad idea generally. To clean archives cleanly, use:
sudo apt-get clean
Solution 2
For fresh APT versions, full solution looks like:
sudo mkdir -m 0700 /var/cache/apt/archives/partial
sudo chown _apt:root /var/cache/apt/archives/partial
Related videos on Youtube
Author by
Araejay
Updated on September 17, 2022Comments
-
Araejay over 1 year
I was running out of space on an Ubuntu server, so I did this command to save space
sudo rm -rf /var/cache/apt/archives
However now when trying to do things with apt, I get the following errors:
E: Could not open lock file /var/cache/apt/archives/lock - open (2 No such file or directory) E: Unable to lock the download directory
And things like
Archive directory /var/cache/apt/archives/partial is missing.
Clearly I have removed some directory structure. Is there some way to do a
apt-get rebuild-var-tree
or similar?-
hey over 14 yearsnot a 'proper' answer so it'll need to be a comment but next time you could try apt-get autoclean (or possibly apt-get clean)
-
-
mlebrun almost 13 yearsUnder debian, I think we should not use sudo. simply use: mkdir -p /var/cache/apt/archives/partial touch /var/cache/apt/archives/lock chmod 640 /var/cache/apt/archives/lock
-
Matt Ryall over 3 yearsIn Buster, apt can set up its own directory structure if you just create the root directory:
sudo mkdir -p /var/cache/apt
.