Skip to content

Instantly share code, notes, and snippets.

@TeddyBear06
Last active March 1, 2022 22:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeddyBear06/f2524b8b2d0e15336c4f8463127f5332 to your computer and use it in GitHub Desktop.
Save TeddyBear06/f2524b8b2d0e15336c4f8463127f5332 to your computer and use it in GitHub Desktop.
Fix apt issues on Ubuntu 20.04 under WSL2

Fix apt-get update on Ubuntu 20.04 under WSL2

I recently cannot run a apt-get update resulting in a kind of - weird - temporary network issue...

Execute the following lines to adress this issue:

wget https://gist.githubusercontent.com/TeddyBear06/f2524b8b2d0e15336c4f8463127f5332/raw/cc54c875310d7be4e768bf6c50df496ac4294cbb/fix_apt_update_under_WSL.sh
chmod +x fix_apt_update_under_WSL.sh
sudo ./fix_apt_update_under_WSL.sh

Initial idea from Sundar Narasiman.

# Generate a file to avoid WSL to overwrite again and again /etc/resolv.conf file
echo "[network]" >> /etc/wsl.conf
echo "generateResolvConf = false" >> /etc/wsl.conf
# Set /etc/resolv.conf new content (use your favorite DNS resolver)
echo "nameserver 8.8.8.8" > /etc/resolv.conf
# Protect /etc/resolv.conf from overwriting (see https://man.archlinux.org/man/chattr.1.en)
chattr -f +i /etc/resolv.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment