简体   繁体   English

Linux 操作系统(Ubuntu)

[英]Linux operating system ( Ubuntu)

I am tying sudo apt-get install gparted command on terminal but it is not working properly and showing this error.我正在终端上绑定sudo apt-get install gparted命令,但它无法正常工作并显示此错误。 What could be the problem?可能是什么问题呢?

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?

Restarting the system should solve the problem.重新启动系统应该可以解决问题。 If the restarting doesn't help, try this link如果重新启动没有帮助,请尝试此链接

You can delete the lock file with the following command:您可以使用以下命令删除锁定文件:

sudo rm /var/lib/apt/lists/lock

You may also need to delete the lock file in the cache directory您可能还需要删除缓存目录中的锁定文件

sudo rm /var/cache/apt/archives/lock

Try this:尝试这个:

sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock

for every results you get from about get process id and Kill it with (could be that only one will give you result - was my case)对于您从 about get process id 获得的每个结果并用它杀死它(可能只有一个会给您结果 - 是我的情况)

sudo kill -9 {process_id}

then remove locks:然后移除锁:

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

and finally run reconf for packages:最后为包运行 reconf:

sudo dpkg --configure -a

i got the same issue when i upgraded my 32-bit ubuntu16.04 to 64-bit configurations.当我将 32 位 ubuntu16.04 升级到 64 位配置时,我遇到了同样的问题。

You need to just delete the lock files in the directory /var/lib/dpkg/lock-frontend .this worked for me.您只需要删除目录 /var/lib/dpkg/lock-frontend 中的锁定文件。这对我有用。

And also i recommend you to just hit the sudo apt-get upgrade command to upgrade the packages you have to be latest ones.而且我建议您只需点击 sudo apt-get upgrade 命令来升级您必须是最新的软件包。

maybe you have another installation in course, because the last question "is another process using it?"也许你当然还有另一个安装,因为最后一个问题“是另一个进程在使用它吗?” or maybe you didn't noted the system is updating itself.或者您可能没有注意到系统正在自我更新。

I got these messages after I started removing my own service from my Ubuntu 16.04 LTS box (did sudo rm /etc/init.d/mysvc; sudo update-rc.d mysvc remove ), but forgot to kill the daemon that was spawned by mysvc .在我开始从我的 Ubuntu 16.04 LTS 盒子中删除我自己的服务后,我收到了这些消息( sudo rm /etc/init.d/mysvc; sudo update-rc.d mysvc remove ),但忘记杀死由mysvc So the removal of mysvc has not been completed.所以mysvc的删除还没有完成。 After I killed the daemon, these messages were gone.在我杀死守护进程后,这些消息消失了。 HTH, :)哈,:)

The error message thrown in Terminal is kinda sufficient in explaining the issue.终端中抛出的错误消息足以解释问题。 The dpkg has an exclusive lock and if you are not able to use it for now, there is another program / update / install currently using it. dpkg 有一个独占锁,如果您暂时无法使用它,则当前有另一个程序/更新/安装正在使用它。

The ideal way would be to leave it running and let it complete.理想的方法是让它运行并让它完成。 I would personally never kill the lock process to suspend whatever the heck is going on in background.我个人永远不会终止锁定进程来暂停后台正在发生的任何事情。

If you see it frequently, you may need to turn off automatic updates under Software & Updates .如果您经常看到它,您可能需要在软件和更新下关闭自动更新

Source : Fix : Could not get lock /var/lib/dpkg/lock来源:修复:无法获得锁/var/lib/dpkg/lock

This means some other process is running or while running some process you accidentally killed the terminal or due to network connection it got hanged in such cases you get this.这意味着一些其他进程正在运行,或者在运行某个进程时你不小心杀死了终端,或者由于网络连接它在这种情况下被挂起,你会得到这个。 Possible solutions.可能的解决方案。

First Login to the system from other terminal首先从其他终端登录系统

check查看

ps -a 

kill the process if you find any being used如果您发现任何正在使用的进程,则终止该进程

Second if first doesnt work, you need to remove the lock其次,如果第一个不起作用,您需要移除锁

sudo rm /var/lib/dpkg/lock

I had a similar thing happened to me when I was trying to do a当我试图做一个类似的事情时,我发生了类似的事情

sudo install python3.8

Which would give me the error message这会给我错误信息

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

Listing the running processes with the ps command, I noticed that there were some processes "stuck" on install.使用 ps 命令列出正在运行的进程,我注意到有一些进程在安装时“卡住”了。 Doing some research I learned that Ubuntu tries to do daily auto updates which locks these processes.通过一些研究,我了解到 Ubuntu 尝试进行每日自动更新以锁定这些进程。

$ ps aux | grep -i apt
root      1464  0.0  0.0   4624   772 ?        Ss   19:08   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
root      1484  0.0  0.0   4624  1676 ?        S    19:08   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install
imartinez  6172  0.0  0.0  21532  1152 pts/1    S+   19:16   0:00 grep --color=auto -i apt

Solution : To fix my problem all I did was open the Software Updater app in the Menu and install the latest Ubuntu upgrades through the GUI.解决方案:为了解决我的问题,我所做的就是在菜单中打开软件更新程序应用程序并通过 GUI 安装最新的 Ubuntu 升级。 This ended up unlocking the files and I was able to install python along with other software packages.这最终解锁了文件,我能够安装 python 和其他软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM