报错:E: Could not get lock /var/lib/dpkg/lock-frontend

2022年11月29日 | 分类: 【技术】

参考:https://askubuntu.com/questions/1249790/e-could-not-get-lock-var-lib-dpkg-lock-frontend-it-is-held-by-process-5200-a

Open your terminal and type:

ps -aux | grep -iE “apt”
ps -aux | grep -iE “apt-get”

输出:

root 60146 0.0 0.2 8932 5536 pts/2 S+ 07:49 0:00 sudo apt-get install redis-server
root 60147 0.0 0.0 8932 888 pts/3 Ss 07:49 0:00 sudo apt-get install redis-server
root 60148 0.3 3.2 72996 66620 pts/3 S+ 07:49 0:01 apt-get install redis-server

It will show the id of the process running apt. Kill it with:

sudo kill -9

sudo kill -9 60146

You could also kill all processes using apt with:

sudo killall apt apt-get

If these commands don’t work, you can also remove the files using rm:

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*

NOTE: Be careful with those commands. You could possibly end up with a broken system if you are careless.

Reconfigure the packages, and update:

sudo dpkg –configure -a
sudo apt-get update -y

Best of luck!