The Problem
In Windows Subsystem for Linux (WSL) when running the command
sudo apt update
the following error appears for every package
“Temporary failure resolving ‘archive.ubuntu.com’”
and nothing is updated.
Furthermore, nothing can be installed using the command
sudo apt install <<PACKAGE-NAME>>
for the same reason.
The Process
A web search for the error led to a StackExchange question discussing the issue, which offered guidance on the problem.
The Solution
Temporary Solution
As this StackExchange answer points out, updating /etc/resolv.conf
by editing the nameserver line to
nameserver 8.8.8.8
resolves the issue, at least until WSL is restarted.
Durable Solution
As this other StackExchange answer points out, to make the solution more durable, some additional steps are required.
- Create the file
/etc/wsl.conf
. - Add the following to it and save.
[network]
generateResolvConf = false
- Shutdown WSL by opening a
cmd
terminal and running the following.
wsl --shutdown
- Restart WSL.
- If it exists, delete the
/etc/resolv.conf
because it’s most likely a link to another file. - Create a new
/etc/resolv.conf
file. - Add the following to it and save.
nameserver 8.8.8.8
The apt update and apt install processes (as well as other processes that need network name resolution) should now work.