uBuntu apt update E: Could not get lock /var/lib/apt/lists/lock. 解決方法

安易にkillしてはいけません。 killは最後の手段です。 このエラーは、バックグラウンドでアプリのupdateやinstallやuninstallしている時に発生するようです。 なので、プロセスを見てみてそれらのプロセスがなくなるまで待ちます。 どうしても無くならなければ、まずRebootして、それでもだめならkillします。 

エラーが出たら

プロセス番号1998のaptdデーモンによってapt listをロック出来ないと言っています。 この様にエラーが出てきたら、

ichiri@ichiri-VPCF128FJ:~$ sudo apt update
[sudo] password for ichiri: 
Reading package lists... Done
E: Could not get lock /var/lib/apt/lists/lock. It is held by process 1998 (aptd)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to lock directory /var/lib/apt/lists/

プロセス確認

apt関係のプロセスを確認します。 プロセス番号1998のプロセスがありますね。 4回目の時にchromeが表示されています。 chromeをupdateしているのだと思ったので待ちます。 すると最後の行の様にaptのプロセスが無くなりました。

ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
root        1998  0.4  1.2 214912 105244 ?       SNl  07:59   0:02 /usr/bin/python3 /usr/sbin/aptd
root        2062  0.1  1.1 216036 90604 pts/1    SNs+ 08:00   0:00 /usr/bin/python3 /usr/sbin/aptd
root        2126  3.9  0.7  59804 58536 pts/2    DNs+ 08:00   0:19 /usr/bin/dpkg --status-fd 69 --no-triggers --unpack --auto-deconfigure --recursive /tmp/apt-dpkg-install-YYDvu6
ichiri      4720  0.0  0.0  18704  2884 pts/3    S+   08:08   0:00 grep --color=auto -i apt

ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
root        1998  0.4  1.2 214912 105244 ?       SNl  07:59   0:02 /usr/bin/python3 /usr/sbin/aptd
root        2062  0.1  1.1 216036 90572 pts/1    SNs+ 08:00   0:00 /usr/bin/python3 /usr/sbin/aptd
root        2126  3.9  0.7  60836 59536 pts/2    SNs+ 08:00   0:20 /usr/bin/dpkg --status-fd 69 --no-triggers --unpack --auto-deconfigure --recursive /tmp/apt-dpkg-install-YYDvu6
root        4843  0.0  0.0   6412   908 pts/2    SN+  08:09   0:00 dpkg-deb --fsys-tarfile /tmp/apt-dpkg-install-YYDvu6/26-snapd_2.58+20.04_amd64.deb
root        4844  1.0  0.0   6412   156 pts/2    SN+  08:09   0:00 dpkg-deb --fsys-tarfile /tmp/apt-dpkg-install-YYDvu6/26-snapd_2.58+20.04_amd64.deb
root        4845 54.0  0.1  14608  9760 pts/2    RN+  08:09   0:01 dpkg-deb --fsys-tarfile /tmp/apt-dpkg-install-YYDvu6/26-snapd_2.58+20.04_amd64.deb
ichiri      4847  0.0  0.0  18704  2820 pts/3    S+   08:09   0:00 grep --color=auto -i apt

ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
root        1998  0.4  1.2 214912 105244 ?       SNl  07:59   0:02 /usr/bin/python3 /usr/sbin/aptd
root        2062  0.1  1.1 216036 90304 pts/1    SNs+ 08:00   0:00 /usr/bin/python3 /usr/sbin/aptd
root        2126  3.9  0.7  60836 59536 pts/2    DNs+ 08:00   0:21 /usr/bin/dpkg --status-fd 69 --no-triggers --unpack --auto-deconfigure --recursive /tmp/apt-dpkg-install-YYDvu6
ichiri      5071  0.0  0.0  18704  2904 pts/3    S+   08:09   0:00 grep --color=auto -i apt

ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
root        1998  0.4  1.2 214912 105244 ?       SNl  07:59   0:02 /usr/bin/python3 /usr/sbin/aptd
root        2062  0.1  1.1 216036 90980 pts/1    SNs+ 08:00   0:00 /usr/bin/python3 /usr/sbin/aptd
ichiri      5491  1.7  0.8 33889132 71396 ?      Sl   08:09   0:00 /opt/google/chrome/chrome --type=utility --utility-sub-type=video_capture.mojom.VideoCaptureService --lang=en-US --service-sandbox-type=none --crashpad-handler-pid=2067 --enable-crash-reporter=, --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,i,5178545928118558922,13829472429222853926,131072
ichiri      5721  0.0  0.0  18704  2924 pts/3    S+   08:09   0:00 grep --color=auto -i apt

ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
root        1998  0.3  1.2 214912 105244 ?       SNl  07:59   0:02 /usr/bin/python3 /usr/sbin/aptd
root        2062  0.1  1.1 216036 90980 pts/1    SNs+ 08:00   0:00 /usr/bin/python3 /usr/sbin/aptd
ichiri      8960  0.0  0.0  18704  2868 pts/3    S+   08:10   0:00 grep --color=auto -i apt

ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
root        1998  0.3  1.2 214912 105244 ?       SNl  07:59   0:02 /usr/bin/python3 /usr/sbin/aptd
root        2062  0.1  1.1 216036 90980 pts/1    SNs+ 08:00   0:00 /usr/bin/python3 /usr/sbin/aptd
ichiri     10780  0.0  0.0  18704  2892 pts/3    S+   08:10   0:00 grep --color=auto -i apt


ichiri@ichiri-VPCF128FJ:~$ ps aux | grep -i apt
ichiri     43811  0.0  0.0  18704  2868 pts/3    S+   08:52   0:00 grep --color=auto -i apt

killせず無事updateできました。

ichiri@ichiri-VPCF128FJ:~$ sudo apt update
[sudo] password for ichiri: 
Hit:1 https://dl.google.com/linux/chrome/deb stable InRelease
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                                                                                       
Hit:3 http://archive.canonical.com/ubuntu focal InRelease                                                                                                       
Hit:4 http://jp.archive.ubuntu.com/ubuntu focal InRelease                      
Get:5 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/universe Sources [159 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [59.9 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [808 kB]
Get:10 http://jp.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [793 kB]   
Get:11 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages [586 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [160 kB]  
Get:13 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [94.8 kB] 
Get:14 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,424 kB]               
Get:15 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [17.2 kB]    
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [940 B]     
Get:17 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]        
Get:18 http://jp.archive.ubuntu.com/ubuntu focal-updates/restricted i386 Packages [30.5 kB]
Get:19 http://jp.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [1,662 kB]
Get:20 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1,034 kB]
Get:21 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [717 kB]
Get:22 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [409 kB]
Get:23 http://jp.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [25.1 kB]
Get:24 http://jp.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:25 http://jp.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [7,988 B]
Get:26 http://jp.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB]
Fetched 9,631 kB in 6s (1,658 kB/s)                                        
Reading package lists... Done
Building dependency tree       
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.

killする場合は

プロセスが無くならなくてどうしてもkillしたい場合は以下を実行します。 私はaptの挙動がわからないので、途中でのkillは怖くてしていません。

$ kill プロセス番号
$ kill -9 プロセス番号     // 強制的にプロセス終了します。

// プロセス番号が1998の場合は、
$ kill 1998
$ kill -9 1998

コメント

タイトルとURLをコピーしました