Could not get lock /var/lib/dpkg/lock - open 解决方法

无法获得锁 /var/lib/dpkg/lock

E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)

当你执行sudo apt-get XXX这种命令时出现类似下面的输出错误:

E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

或者:

E: Could not ge lock /var/lib/apt/lists/lock - open (11: Resource temporarily
unavailable)
E: Unable to lock directory /var/lib/apt/lists/ 
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) 
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

解释

出现这个问题的原因是,还有一个线程在使用apt-get进行下载的操作。但是奇怪的是,我就是没有找到其他使用了apt-get指令的终端界面。那么如何解决这个问题呢,难道要重新启动电脑吗,重启电脑是可以解决这个问题,但是我接下来教你的方法,才是真正的解决方法。

解决办法

先搜索所有运行着的线程

ps -A | grep apt-get

你会得到类似下面的输出:

root        752  0.0  0.0   4508  1628 ?        Ss   01:13   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily
_apt       2098  0.1  0.1  49572  5524 ?        S    01:18   0:06 /usr/lib/apt/methods/http
aobo       4425  0.0  0.0  18484   980 pts/1    S+   02:13   0:00 grep --color=auto apt

第2列就是线程号(kill processnumber)。我们将apt相关的进程给关闭掉,需要使用sudo权限:

# sudo kill processnumber
sudo kill 2098

输出:

bash: kill: (2098) - Operation not permitted

现在关闭当前终端,再重新开一个终端,sudo apt-get命令就可以使用了。


参考网站:
http://askubuntu.com/questions/15433/unable-to-lock-the-administration-directory-var-lib-dpkg-is-another-process
http://askubuntu.com/questions/452638/how-can-i-solve-unable-to-lock-the-administration-directory-var-lib-dpkg

你可能感兴趣的:(Ubuntu,Ubuntu-err,Linux)