문제
다음과 같이 Waiting for cache lock 에러가 발생하고 업데이트가 정상적으로 진행이 안되는 문제가 발생했다.
root@taking:~/ # apt install unrar -y
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 15973 (unattended-upgr)... 11s
^Citing for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 15973 (unattended-upgr)... 19s
해결방법
apt 내 lock 파일이 존재하기 때문에 발생한다. 다른 세션에서 apt를 점유하고 있는 경우가 아니라면 lock 파일을 제거해주어 문제를 해결하면 된다.
# lock 파일 제거
rm /var/lib/apt/lists/lock
rm /var/cache/apt/archives/lock
rm /var/lib/dpkg/lock*
# 패키지 업데이트
dpkg --configure -a
apt update
해결 후
lock 파일 제거 후, 다시 apt update 및 패키지 인스톨을 진행하면 다음과 같이 정상적으로 설치가 진행되는 것을 볼 수 있다.
root@taking:~/# apt install unrar -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
unrar
0 upgraded, 1 newly installed, 0 to remove and 78 not upgraded.
Need to get 113 kB of archives.
After this operation, 406 kB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu focal/multiverse amd64 unrar amd64 1:5.6.6-2build1 [113 kB]
Fetched 113 kB in 1s (78.7 kB/s)
Selecting previously unselected package unrar.
(Reading database ... 147886 files and directories currently installed.)
Preparing to unpack .../unrar_1%3a5.6.6-2build1_amd64.deb ...
Unpacking unrar (1:5.6.6-2build1) ...
Setting up unrar (1:5.6.6-2build1) ...
update-alternatives: using /usr/bin/unrar-nonfree to provide /usr/bin/unrar (unrar) in auto mode
Processing triggers for man-db (2.9.1-1) ...