美文网首页linux运维
关于Ubuntu中Could not get lock /var

关于Ubuntu中Could not get lock /var

作者: 留个念想给昨天 | 来源:发表于2019-11-27 08:58 被阅读0次

    关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案

    1:我遇到的问题:

    在开机运行apt install vim 命令的时候,如下报错:

    image

    2:参考博客:

    在Ubuntu中,有时候运用sudo apt-get install 安装软件时,会出现一下的情况

    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?

    3:问题原因:主要是因为apt还在运行。

    4:解决方案:杀死所有的apt进程。

    1:查找所有apt相关的进程,并用命令杀死。

    hlp@hlp-Lenovo-G405:~$ ps afx|grep apt
     3284 pts/0    S+     0:00          \_ grep --color=auto apt
     2869 ?        Ss     0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
     2873 ?        S      0:00  \_ /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install
    
    hlp@hlp-Lenovo-G405:~$ sudo kill -9 2873
    hlp@hlp-Lenovo-G405:~$ sudo kill -9 2869
    

    2:删除锁定文件

    锁定的文件会阻止 Linux 系统中某些文件或者数据的访问,这个概念也存在于 Windows 或者其他的操作系统中。

    一旦你运行了 apt-get 或者 apt 命令,锁定文件将会创建于 /var/lib/apt/lists//var/lib/dpkg//var/cache/apt/archives/ 中。

    这有助于运行中的 apt-get 或者 apt 进程能够避免被其它需要使用相同文件的用户或者系统进程所打断。当该进程执行完毕后,锁定文件将会删除。

    所以:

    1:移除对应目录下的锁文件:

    2:强制重新配置软件包:

    3:更新软件包源文件:

    `hlp@hlp-Lenovo-G405:~$ sudo rm /var/lib/dpkg/lock`
    
    `hlp@hlp-Lenovo-G405:~$ sudo dpkg --configure -a`
    
    `hlp@hlp-Lenovo-G405:~$ sudo apt update`
    
    

    3:问题解决,执行apt install 命令成功。

    相关文章

      网友评论

        本文标题:关于Ubuntu中Could not get lock /var

        本文链接:https://www.haomeiwen.com/subject/htiewctx.html