📦

Ubuntuの日本国内向けapt mirror設定2026

に公開
2025/12/19
4件

結論

Ubuntu 24.04以降

sudo sed -i.bak -E \
  '/^URIs:/ {
    N; /Suites:.*-security/! {
      s@http://(jp\.)?archive\.ubuntu\.com/ubuntu/?@http://ftp.udx.icscoe.jp/Linux/ubuntu/@;
      s@http://(jp\.)?ports\.ubuntu\.com/ubuntu-ports/?@http://ftp.udx.icscoe.jp/Linux/ubuntu-ports/@;
    }
  }' \
  /etc/apt/sources.list.d/ubuntu.sources

※ Ubuntu 24.04以降であっても、/etc/apt/sources.list.d/ubuntu.sourcesが存在しないことを示すエラーが発生した場合は以下のコマンドを試す。

Ubuntu 23.10以前(20.04, 22.04等)

sudo sed -i.bak -E \
  -e '/-security/!s@http://(jp\.)?archive\.ubuntu\.com/ubuntu/?@http://ftp.udx.icscoe.jp/Linux/ubuntu/@g' \
  -e '/-security/!s@http://(jp\.)?ports\.ubuntu\.com/ubuntu-ports/?@http://ftp.udx.icscoe.jp/Linux/ubuntu-ports/@g' \
  /etc/apt/sources.list

解説

UbuntuのaptリポジトリのURLは、Ubuntu 24.04以降では/etc/apt/sources.list.d/ubuntu.sources、23.10以前では/etc/apt/sources.listに書かれている。デフォルトで設定されているhttp://archive.ubuntu.com/ubuntu/を適当なミラーのURLに置き換えれば良い。

ただし、書き換えに当たっては注意すべき点がいくつかある。

  • VPSやクラウド環境のUbuntuイメージではURLが多少異なっている場合がある。頭にjp.がついていたり、末尾に/がついていなかったりする。
  • i386とamd64以外のアーキテクチャを使っている場合は、デフォルトでports.ubuntu.comが設定されている。書き換える際もそれに対応したミラーのURLを設定する必要がある。
  • セキュリティアップデートが配信されるsecurityポケットのURLは書き換えてはいけない。セキュリティアップデートの適用が遅れる原因になる。詳細は https://jyn.jp/what-is-security-ubuntu-com/ を参照。
    • i386やarm64の場合はsecurity.ubuntu.comを書き換えないようにすれば問題ない。それ以外のアーキテクチャではsecurityポケットもports.ubuntu.comから配信されるため、スイートに-securityが含まれるものを除外する必要がある。

ミラーサーバーの選択

Ubuntu向けの公開ミラーサーバーの一覧は以下のページに記載されている。

https://launchpad.net/ubuntu/+archivemirrors

この記事ではIPAの産業サイバーセキュリティセンターによって運用されているftp.udx.icscoe.jpを選んだ。私の知る限り日本国内で最速のミラーサーバーで、2022年頃から公開されている。

https://ftp.udx.icscoe.jp/

なお、ミラーサーバーを自動的に選択するapt-mirror (mirror://mirrors.ubuntu.com/mirrors.txt)も存在するが、不安定なサーバーを引くことがあるのでおすすめできない。

GitHubで編集を提案

Discussion

GimletGimlet

Ubuntu 24.04からは/etc/apt/sources.list.d/ubuntu.sourcesに移ったようです。
/etc/apt/sources.list

# Ubuntu sources have moved to /etc/apt/sources.list.d/ubuntu.sources

/etc/apt/sources.list.d/ubuntu.sources

Types: deb
URIs: http://jp.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

なので、24.04でやる場合、以下のようになります。

sudo sed -i.bak -r 's@http://(jp\.)?archive\.ubuntu\.com/ubuntu/?@https://ftp.udx.icscoe.jp/Linux/ubuntu/@g' /etc/apt/sources.list.d/ubuntu.sources
2
CiffeliaCiffelia

ありがとうございます。本文に反映させていただきました。

1
uu5007mpuu5007mp

proxmoxを使ってるのですがコンテナ版(LXC)だと/etc/apt/sources.listのままのようです

# cat /etc/apt/sources.list
deb https://ftp.udx.icscoe.jp/Linux/ubuntu/ oracular main restricted universe multiverse

deb https://ftp.udx.icscoe.jp/Linux/ubuntu/ oracular-updates main restricted universe multiverse

deb https://ftp.udx.icscoe.jp/Linux/ubuntu/ oracular-security main restricted universe multiverse

# cat /etc/apt/sources.list.d/ubuntu.sources
cat: /etc/apt/sources.list.d/ubuntu.sources: そのようなファイルやディレクトリはありません```
3