Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS apt install error = Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)

Using Amazon Linux AMI (2017.03.1) on a p2.xlarge instance, and attempting to sudo apt install {somepackage}, I get the following error:

Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)

I have already tried

sudo rm /var/lib/apt/lists/lock

and

sudo rm /var/cache/apt/archives/lock
like image 483
user3076252 Avatar asked Dec 14 '22 22:12

user3076252


2 Answers

Solution:

sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a
sudo apt install {somepackage}
like image 163
user3076252 Avatar answered Mar 01 '23 22:03

user3076252


  1. First look for that process by

sudo lsof /var/lib/dpkg/lock

  1. Then make sure the process is not running by

ps cax | grep PID #PID is the Process id e.g 1111

  1. If PID is shown(It's running) kill it {else go to step 5} by

sudo kill -9 PID

  1. Make sure the process is killed done by

sudo ps cax | grep PID

  1. Then remove the locked file by

sudo rm /var/lib/dpkg/lock

sudo rm /var/lib/dpkg/lock-frontend #optional

  1. Finally make dpkg fix its self by

sudo dpkg --configure -a

Reference From

like image 21
joash Avatar answered Mar 02 '23 00:03

joash