有的时候使用apt下载会出现问题,显示正在等待缓存锁,怎么都无法下载东西:
$ sudo apt install tree
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is he^C by process 3424 (unattended-upgr)... 1s
linux下载官方软件安装包时由于没有镜像速度很慢,如果意外退出下载,第二次进入下载的时候缓存会被锁住。
我们可以使用命令来“解锁”,其实也就是将代表缓存锁的文件删除:
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/cahe/apt/archives/lock
sudo rm /var/lib/dpkg/lock
发现删除以后安装还是报错:
unable to lock directory /var/cache/apt/archives/
试试看重新打开一下终端:
E: Could not get lock /var/cache/apt/archives/lock. It is held by process 3424 (unattended-upgr)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to lock directory /var/cache/apt/archives/
竟然还是不错。
正当一筹莫展的时候,摆弄了一下终端,再次重新打开,竟然就可以安装了:
$ sudo apt install tree
[sudo] password for mugpeng:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
tree
0 to upgrade, 1 to newly install, 0 to remove and 243 not to upgrade.
Need to get 43.0 kB of archives.
After this operation, 115 kB of additional disk space will be used.
Get:1 http://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 tree amd64 1.8.0-1 [43.0 kB]
Fetched 43.0 kB in 0s (313 kB/s)
Selecting previously unselected package tree.
(Reading database ... 183449 files and directories currently installed.)
Preparing to unpack .../tree_1.8.0-1_amd64.deb ...
Unpacking tree (1.8.0-1) ...
Setting up tree (1.8.0-1) ...
Processing triggers for man-db (2.9.1-1) ...
真够玄学的啊。
看来每次删除了“缓存锁”后,还是要多退出终端几次。