Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu 20.04 apt-get update fails - cannot get apt lists lock #366

Open
atheiman opened this issue Jun 23, 2023 · 1 comment · May be fixed by #431
Open

Ubuntu 20.04 apt-get update fails - cannot get apt lists lock #366

atheiman opened this issue Jun 23, 2023 · 1 comment · May be fixed by #431

Comments

@atheiman
Copy link

atheiman commented Jun 23, 2023

Installing docker on AWS EC2 on an Ubuntu 20.04.6 AMI using https://get.docker.com/ is failling for me with the below error:

+ sudo -E sh -c apt-get-update -qq >/dev/null
E; Could not get lock /var/lib/apt/lists/lock. It is held by process 2023 (apt-get)
E: Unable to lock directory /var/lib/apt/lists/

Looks like as of apt 1.9.11 there is an option to wait for the lock to be released rather than failing immediately: apt-get -o DPkg::Lock::Timeout=60 install FOO.

Could -o DPkg::Lock::Timeout=120 be added to any apt-get commands?

This can be used for apt version checking and adding the arg if apt version > 1.9:

APT_VERSION="$(apt --version | tr ' ' '\n' | grep -E '[0-9]+\.[0-9]+\.[0-9]+')"
APT_ARGS=""
 
if [ "$(echo $APT_VERSION | cut -d '.' -f 1)" -gt 1 ]; then
  # apt version 2.0 or newer
  APT_ARGS="-o DPkg::Lock::Timeout=120"
elif [ "$(echo $APT_VERSION | cut -d '.' -f 2)" -gt 9 ]; then
  # apt version 1.10 or newer
  APT_ARGS="-o DPkg::Lock::Timeout=120"
fi
 
echo "APT_ARGS: '$APT_ARGS'"
echo apt-get $APT_ARGS update -q
apt-get $APT_ARGS update -q
@easy-and-simple
Copy link

Reboot and try again.
This issue happens if packet manager is opened by some reason

@oreze oreze linked a pull request Jul 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants