![Debian/Ubuntu - 如何删除 /var/cache/apt 结构后恢复它?](https://linux22.com/image/505082/Debian%2FUbuntu%20-%20%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4%20%2Fvar%2Fcache%2Fapt%20%E7%BB%93%E6%9E%84%E5%90%8E%E6%81%A2%E5%A4%8D%E5%AE%83%EF%BC%9F.png)
我的 Ubuntu 服务器上空间不足,因此我执行了这个命令来节省空间
sudo rm -rf /var/cache/apt/archives
但是现在当我尝试使用 apt 做事时,我收到以下错误:
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
还有类似的东西
Archive directory /var/cache/apt/archives/partial is missing.
显然,我删除了一些目录结构。有没有什么方法可以做apt-get rebuild-var-tree
类似的事情?
答案1
你需要两样东西:
sudo mkdir -p /var/cache/apt/archives/partial
sudo touch /var/cache/apt/archives/lock
sudo chmod 640 /var/cache/apt/archives/lock
通常,手动删除此目录不是一个好主意。要彻底清除档案,请使用:
sudo apt-get clean
答案2
对于新的 APT 版本,完整的解决方案如下:
sudo mkdir -m 0700 /var/cache/apt/archives/partial
sudo chown _apt:root /var/cache/apt/archives/partial