Apt-Get Update Is Slow Or Locked

You may see the error Could not get lock /var/lib/apt/lists/lock on the Machine executor when attempting to run apt, if there is a networking issue that is causing the Spin up environment step to keep the update process alive. 


Using the Docker executor if updating with apt update, this type of networking can be spotted in your step output, by looking at the download speed of each mirror, and identifying which is potentially causing the problem.

Screen_Shot_2019-04-05_at_10.46.50_AM.png

With Docker, you may not need to run apt update if you rebuild your image on a regular basis. Active convenience images maintained by CircleCi are rebuilt on a weekly basis.

 

Here are some options for working around slow or broken mirrors.

Wait for network

This command will kill any apt process that might be running in the background already, and then allow up to an hour to download the package(s) if need be.

This may not be ideal if you are on a Usage-based plan as this may significantly increase container time in the event of a networking issue.

However, this may be desired for critical applications where waiting on the network is preferred.

- run:
    no_output_timeout: 1h
    command: |
      set -e
    killall apt
      apt -q -y update
      apt -q -y install any packages here

 

Change mirrors

Sometimes official mirrors go down, are slow, or move to new URLs. If you have a known list of good mirrors, you can manually set them.

You can modify this example by replacing the sources with known good mirrors for your base distribution.

- run:
command: |
sudo rm /etc/apt/sources.list
echo "deb http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "Acquire::Check-Valid-Until false;" | sudo tee -a /etc/apt/apt.conf.d/10-nocheckvalid
echo 'Package: *\nPin: origin "archive.debian.org"\nPin-Priority: 500' | sudo tee -a /etc/apt/preferences.d/10-archive-pin
sudo apt-get update

Was this article helpful?
4 out of 10 found this helpful

Comments

0 comments

Article is closed for comments.