LoginSignup
17
10

More than 1 year has passed since last update.

[WSL2 Ubuntu22.04] sudo apt update時のエラー

Last updated at Posted at 2022-11-20

実行環境

Ubuntu22.04LTS(WSL2)

エラー内容

zsh(ubuntu)
$ sudo apt update
Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 https://download.docker.com/linux/ubuntu jammy InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 https://download.docker.com/linux/ubuntu jammy InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 https://download.docker.com/linux/ubuntu jammy InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:1 http://archive.ubuntu.com/ubuntu jammy InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:3 https://download.docker.com/linux/ubuntu jammy InRelease
  Temporary failure resolving 'download.docker.com'
Err:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/InRelease  Temporary failure resolving 'download.docker.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

error_message

やったこと

古いレポジトリがupdate時に参照されるリストに残留していないか確認

この質問を参考に

zsh(Ubuntu)
$ grep -nvr "^#" /etc/apt/ | grep impish
grep: /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg: binary file matches
grep: /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg: binary file matches
grep: /etc/apt/keyrings/docker.gpg: binary file matches

$ grep -nvr "^#" /etc/apt/ | grep archive.ubuntu.com
grep: /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg: binary file matches
grep: /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg: binary file matches
grep: /etc/apt/keyrings/docker.gpg: binary file matches
/etc/apt/sources.list:3:deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
/etc/apt/sources.list:8:deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
/etc/apt/sources.list:14:deb http://archive.ubuntu.com/ubuntu/ jammy universe
/etc/apt/sources.list:16:deb http://archive.ubuntu.com/ubuntu/ jammy-updates universe
/etc/apt/sources.list:24:deb http://archive.ubuntu.com/ubuntu/ jammy multiverse
/etc/apt/sources.list:26:deb http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse
/etc/apt/sources.list:34:deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

こんな感じでgrep検索をかけてみたものの、元の質問と自分のエラーは原因が違いそうだと思い何も変更せず。

エラーに表示されているURLのドメインがhttp://in.archive.ubuntu.com/となっている場合、sources.listhttp://archive.ubuntu.com/ubuntuと変更すると治る場合があるらしい(参考)が、自分の場合は元々http://archive.ubuntu.com/であったため関係なかった。

wslのdateが正しく設定されていることを確認

この記事を参考にUbuntuの日時がWindowsと一致していることを確認した。

zsh(Ubuntu)
$ date
# 出力が現在の日時と一致していることを確認、一致していなければ

自分の環境では一致していたため何も操作は必要なかったが、日時のズレがあった場合この記事を参考に進めると解決するかもしれない。

/etc/wsl.confの書き換え

Google検索した際に出てきた複数の記事を参考に、/etc/wsl.conf

/etc/wsl.conf
[network]
generateResolvConf = false

このように書き足してみたが、効果はなかった。
改めて書くほどのことではないが、編集する時は

zsh(Ubuntu)
# vimを使う場合
vim /etc/wsl.conf
# nanoを使う場合
nano /etc/wsl.conf

など任意のエディターで編集できる。

解決策

zsh(Ubuntu)
$ echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null
$ sudo apt update
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (221 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

これで、GoogleのDNSサーバー(8.8.8.8)を/etc/resolv.confで指定する。
実際に下のように内容を確認すると、正しく指定されていることがわかる。

zsh(Ubuntu)
$ cat /etc/resolv.conf
nameserver 8.8.8.8

それでも治らない場合

自分の環境ではこれで解決したが、8.8.8.8(GoogleのDNSサーバー)では解決しない場合があるようである。
その場合はWSLにてapt update時の『Temporary failure resolving ~』を解決する方法も参照するといいかもしれない。

参考にしたサイト

17
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
10