Apt update on Ubuntu 16.04 hangs randomly every view updates.

Nothing I've tried can permanently fix it and I have no way to troubleshoot it.

The only solution I have is to create a shell script to apt clean && apt update. then it works.

echo -e '#!/bin/bash\nsudo apt clean && sudo apt update' | sudo tee /usr/bin/apt-update; sudo chmod +x /usr/bin/apt-update

Things I've done:

Switch to google DNS

Disable NetworkManager managed DNS

sudo sed -i -e 's/^dns=dnsmasq/#dns=dnsmasq/' /etc/NetworkManager/NetworkManager.conf

Add Google DNS to DHCP Client (dhcp will prepend google DNS to /etc/resolv.conf)

echo 'prepend domain-name-servers 8.8.4.4;' | sudo tee -a /etc/dhcp/dhclient.conf

echo 'prepend domain-name-servers 8.8.8.8;' | sudo tee -a /etc/dhcp/dhclient.conf

Restart NetworkManager

systemctl restart NetworkManager.service

edit apt config

Some repos have issues with http/1.1 pipelining.

Try the following:

echo 'Acquire::http::Pipeline-Depth "0";' | sudo tee /etc/apt/apt.conf.d/99pipelining-off


Sometimes its hard to see which repos are failing because of long timeouts

reduce the timeouts with

echo 'Acquire::http::Timeout "5";' | sudo tee /etc/apt/apt.conf.d/99reduce-timeout


Force IP V4 to disable attempting to resolve IP V6

echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4

create script for apt-update

Apt-get update often hangs/fails. the work around for this is to always apt clean before apt update

This command creates a script called apt-update that does just this and should be used instead of apt-get update or apt update

echo -e '#!/bin/bash\nsudo apt clean && sudo apt update' | sudo tee /usr/bin/apt-update; sudo chmod +x /usr/bin/apt-update

enable automatic mirror switching

sudo sed -i -e 's/deb http:\/\/il.archive.ubuntu.com\/ubuntu\//deb mirror:\/\/mirrors.ubuntu.com\/mirrors.txt/' sources.list

enable partner repo

sudo sed -i.bak "/^# deb .*partner/ s/^# //" /etc/apt/sources.list


I tried editing the clean policy

echo 'DSELECT::Clean "always";' | sudo tee /etc/apt/apt.conf.d/99DselectAlwaysClean

echo 'APT::Get::Clean=always;' | sudo tee /etc/apt/apt.conf.d/99AlwaysClean

I even tried adding Post update and Pre update commands with

echo 'APT::Update::Post-Invoke {"/usr/bin/apt apt clean || exit 0"};' | sudo tee /etc/apt/apt.conf.d/99PostUpdateClean

echo 'APT::Update::Pre-Invoke {"/usr/bin/apt clean || exit 0"};' | sudo tee /etc/apt/apt.conf.d/99PreUpdateClean

these 2 commands are actually problematic because they seem to try to steal lock or something. In the end I deleted them.

How can I permanently resolve this issue without resorting to hacks like a shell script that does apt clean && apt update?

How can I troubleshoot this issue?

share|improve this question
    
Are you sure the hang is unrelated to any external event? Did you check to see if there is a drop off or interruption in the bandwidth/connection and then a failure to reconnect? – bu5hman Nov 29 '17 at 13:20

Try adding this to your /etc/hosts file:

127.0.1.1    yourhostname

I am also assuming that there are no issues with your /etc/hostname file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.