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.