📦

Ubuntuのapt mirrorの設定って結局どうすればいいの?

2022/11/02に公開
1

TL;DR

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

解説

基本的には、/etc/apt/sources.listを開いてhttp://archive.ubuntu.com/ubuntu/を適当なミラーのURLに置き換えれば良い。

ただし、/etc/apt/sources.listに書かれているarchive.ubuntu.comのURLは環境によって多少異なる。頭部にjp.がついていたり、末尾に/がついていなかったりする。
なので、それらの場合にも対応できる正規表現にしている。

ミラーサーバーには https://launchpad.net/ubuntu/+archivemirrors に記載されていたicscoe.jpを採用した。かなり速い。
ICSCoEはIPAの産業サイバーセキュリティセンターという組織らしい。ただしウェブサイトのどこにもミラーサーバー運用に関する情報が見つからないので、信頼性には多少の不安があるかもしれない。

注意

/etc/apt/sources.listを書き換えるときは以下の点に気をつける。

  • バックアップを必ず取ること
  • security.ubuntu.comを書き換えないこと
  • apt-mirror (mirror://mirrors.ubuntu.com/mirrors.txt)は個人的にはおすすめしない
    • mirrors.ubuntu.comは地理的に近いミラーサーバーをいくつか返す
    • しかし地理的に近いからといってダウンロードが速いとは限らない
    • 不安定なサーバーを引くこともある
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