今日在 Ubuntu20 上,使用 dpkg 安装 vim 编辑器时抛出 “dpkg: error: dpkg frontend lock is locked by another process”错误。如下:
snow@ubuntu:~$ sudo dpkg -P vim dpkg: error: dpkg frontend lock is locked by another process
上面错误信息大概意思是“dpkg 命令被其他进程锁定了”。
此时,我们可以使用“sudo apt-get install -f”命令查看具体是哪个文件将 dpkg 命令锁定了。如下:
snow@ubuntu:~$ sudo apt-get install -f E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 232324 (unattended-upgr) N: Be aware that removing the lock file is not a solution and may break your system. E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
根据提示信息可知 dpkg 被“/var/lib/dpkg/lock-frontend”文件锁定,那么我们就删除该文件。如下:
snow@ubuntu:~$ sudo rm /var/lib/dpkg/lock-frontend
成功删除“/var/lib/dpkg/lock-frontend”文件后,使用 apt-get install 试试能够使用了。如下:
snow@ubuntu:~$ sudo apt-get install tree E: Could not get lock /var/lib/dpkg/lock. It is held by process 232324 (unattended-upgr) N: Be aware that removing the lock file is not a solution and may break your system. E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
apt-get 抛出了“/var/lib/dpkg/lock”锁定文件,删除该文件再试。如下:
snow@ubuntu:~$ sudo rm /var/lib/dpkg/lock
再次,试试安装 tree。如下:
snow@ubuntu:~$ sudo apt-get install tree Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be upgraded: tree 1 upgraded, 0 newly installed, 0 to remove and 198 not upgraded. Need to get 43.0 kB of archives. After this operation, 6,144 B of additional disk space will be used. Get:1 https://us.archive.ubuntu.com/ubuntu focal/universe amd64 tree amd64 1.8.0-1 [43.0 kB] Fetched 43.0 kB in 37s (1,153 B/s) (Reading database ... 189840 files and directories currently installed.) Preparing to unpack .../tree_1.8.0-1_amd64.deb ... Unpacking tree (1.8.0-1) over (1.6.0-1) ... Setting up tree (1.8.0-1) ... Processing triggers for man-db (2.9.1-1) ...
问题解决了,仅供参考!