1 How to Fix ‘E: Could not get lock /var/lib/dpkg/lock’ Error in Ubuntu Linux

resloved page

use the following command see what thread take the apt:

1
$ ps aux | grep -i apt
1
2
3
4
5
root@ubuntu:/home/root123# ps aux | grep -i apt
root 3495 0.0 0.8 227104 33796 ? SNl 06:32 0:00 /usr/bin/python3 /usr/sbin/aptd
root 7697 0.0 0.0 4508 744 ? Ss 06:38 0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
root 7706 0.0 0.0 4508 1696 ? S 06:38 0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install
root 10067 0.0 0.0 21292 1088 pts/18 S+ 06:41 0:00 grep --color=auto -i apt

at line 3, you will see the program apt.systemd.daily install, it’s means, you are locked.

Well, it is simple to handle it, you just use the following command to kill this program, the problem is solved.

1
$ kill 7697

After that, you can install any software you want. For example, I am trying to install vim.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
root@ubuntu:/home/root123# apt install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
vim-common vim-runtime vim-tiny
Suggested packages:
ctags vim-doc vim-scripts vim-gnome-py2 | vim-gtk-py2 | vim-gtk3-py2 | vim-athena-py2 | vim-nox-py2 indent
The following NEW packages will be installed:
vim vim-runtime
The following packages will be upgraded:
vim-common vim-tiny
2 upgraded, 2 newly installed, 0 to remove and 629 not upgraded.
Need to get 6,205 kB/6,754 kB of archives.
After this operation, 30.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 vim-runtime all 2:7.4.1689-3ubuntu1.5 [5,169 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 vim amd64 2:7.4.1689-3ubuntu1.5 [1,036 kB]
Fetched 6,205 kB in 3s (1,965 kB/s)
(Reading database ... 178388 files and directories currently installed.)
Preparing to unpack .../vim-tiny_2%3a7.4.1689-3ubuntu1.5_amd64.deb ...

Progress: [ 0%] [..........................................................................................................]
Unpacking vim-tiny (2:7.4.1689-3ubuntu1.5) over (2:7.4.1689-3ubuntu1.2) ....................................................]
...

Now, I can use vim free.

2 Reference

All the answer is from this page.

写在最后

欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
微信公众号