示例代码: Ubuntu下安装Git出现“无法获得锁”错误的解决方法
sudo apt-get install git Reading package lists... Done E: Could not get lock /var/lib/dpkg/lock I: Unable to lock the administration directory (var/lib/dpkg/), is another process using it?
解决步骤:
运行下面的命令,获取进程id: ps -A | grep apt
你会得到类似如下结果: user1@ubuntu:~$ ps -A |grep apt 2374 ? 00:00:00 apt.systemd.daily 2391 ? 00:00:00 apt.systemd.daily 2392 ? 00:00:00 /bin/sh /usr/lib/apt/apt.systemd.daily install 2400 ? 00:00:03 apt-get 2402 ? 00:00:00 dpkg
根据结果所示的PID杀掉正在使用锁的进程: sudo kill -9 PID
在上述示例中,需要执行如下命令,以关闭使用锁的 apt-get 进程: sudo kill -9 2400
确保安装的 Git 版本没有锁定,直接运行指令: sudo apt-get install git
安装命令应该现在应该可以正常执行了。