问题
我在进行apt upgrade
时,本地的命令行工具崩溃了,重新ssh连接到服务器后,再次执行apt upgrade
后,报错:
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 528443 (apt)
这意味着在之前的 apt
进程未正常退出时,系统的锁文件(/var/lib/dpkg/lock-frontend
)仍然存在。这个锁文件是用来防止多个 apt
或 dpkg
进程同时运行的,因为它们不能同时对包管理数据库进行修改。
解决
- 先查看
apt
进程是否还在运行
ps aux | grep apt
ps
(Process Status)用于查看系统进程信息,aux
是它的参数组合:a
:显示所有用户的进程(而不仅是当前终端)u
:以用户友好的格式显示(包含 CPU、内存占用等)x
:显示没有控制终端的进程(如后台服务)
|
(管道符)将ps aux
的输出传递给grep apt
,grep
会筛选包含apt
的行
我这里输出如下:
root 528441 0.0 0.2 11716 4452 ? S 09:46 0:00 sudo apt upgrade root 528442 0.0 0.0 11716 884 ? Ss 09:46 0:00 sudo apt upgrade root 528443 0.2 1.9 98724 40244 ? S 09:46 0:02 apt upgrade root 549213 0.0 0.1 6612 2344 pts/3 S+ 10:08 0:00 grep —color=auto apt
- 说明
apt
进程还在运行,但是我确定这个进程是被挂起了,所以手动杀掉
sudo kill -9 528443
- 然后再次输入
apt upgrade
,输出如下:
E: dpkg was interrupted, you must manually run ‘dpkg —configure -a’ to correct the problem.
需要执行sudo dpkg --configure -a
来确保包管理数据库没有损坏
然后apt
命令就可以正常使用了