LoginSignup
0
1

More than 3 years have passed since last update.

コマンドラインで ubuntu の apt の取得先をミラーに変更する

Last updated at Posted at 2020-04-11

コマンドラインで ubuntu の apt の取得先をミラーに変更する

GUI による方法は こちら
改良版は こちら

変更先のミラーの情報

以下のファイルに ubuntu のミラーサイトの URL が記載されています。

以下が内容

http://linux.yz.yamagata-u.ac.jp/ubuntu/
http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/
http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu/
http://ftp.riken.jp/Linux/ubuntu/
http://ftp.jaist.ac.jp/pub/Linux/ubuntu/
http://ubuntu-ashisuto.ubuntulinux.jp/ubuntu/
http://ubuntutym.u-toyama.ac.jp/ubuntu/
http://archive.ubuntu.com/ubuntu/

処理内容

/etc/apt/sources.list に記載されている以下の URL を上記に記載されている URL のどれかに sed で書き換える。

http://security.ubuntu.com/ubuntu
http://us.archive.ubuntu.com/ubuntu/

実際の例 (http://ftp.riken.jp/Linux/ubuntu の場合)

例として http://ftp.riken.jp/Linux/ubuntu に書き換える場合を説明します。

sed で | を使う場合には拡張形式の正規表現を使用するので -r を指定します。

sudo sed -i.bak -r 's!http://(security|us.archive).ubuntu.com/ubuntu!http://ftp.riken.jp/Linux/ubuntu!' /etc/apt/sources.list

/etc/apt/sources.list の差分

test@ubuntu:~$ diff /etc/apt/sources.list.bak /etc/apt/sources.list
5,6c5,6
< deb http://us.archive.ubuntu.com/ubuntu/ eoan main restricted
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan main restricted
---
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan main restricted
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan main restricted
10,11c10,11
< deb http://us.archive.ubuntu.com/ubuntu/ eoan-updates main restricted
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan-updates main restricted
---
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan-updates main restricted
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan-updates main restricted
16,19c16,19
< deb http://us.archive.ubuntu.com/ubuntu/ eoan universe
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan universe
< deb http://us.archive.ubuntu.com/ubuntu/ eoan-updates universe
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan-updates universe
---
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan universe
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan universe
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan-updates universe
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan-updates universe
26,29c26,29
< deb http://us.archive.ubuntu.com/ubuntu/ eoan multiverse
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan multiverse
< deb http://us.archive.ubuntu.com/ubuntu/ eoan-updates multiverse
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan-updates multiverse
---
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan multiverse
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan multiverse
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan-updates multiverse
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan-updates multiverse
36,37c36,37
< deb http://us.archive.ubuntu.com/ubuntu/ eoan-backports main restricted universe multiverse
< # deb-src http://us.archive.ubuntu.com/ubuntu/ eoan-backports main restricted universe multiverse
---
> deb http://ftp.riken.jp/Linux/ubuntu/ eoan-backports main restricted universe multiverse
> # deb-src http://ftp.riken.jp/Linux/ubuntu/ eoan-backports main restricted universe multiverse
46,51c46,51
< deb http://security.ubuntu.com/ubuntu eoan-security main restricted
< # deb-src http://security.ubuntu.com/ubuntu eoan-security main restricted
< deb http://security.ubuntu.com/ubuntu eoan-security universe
< # deb-src http://security.ubuntu.com/ubuntu eoan-security universe
< deb http://security.ubuntu.com/ubuntu eoan-security multiverse
< # deb-src http://security.ubuntu.com/ubuntu eoan-security multiverse
---
> deb http://ftp.riken.jp/Linux/ubuntu eoan-security main restricted
> # deb-src http://ftp.riken.jp/Linux/ubuntu eoan-security main restricted
> deb http://ftp.riken.jp/Linux/ubuntu eoan-security universe
> # deb-src http://ftp.riken.jp/Linux/ubuntu eoan-security universe
> deb http://ftp.riken.jp/Linux/ubuntu eoan-security multiverse
> # deb-src http://ftp.riken.jp/Linux/ubuntu eoan-security multiverse

software-properties-gtk を起動して反映されているか確認する。(オプション)

image.png

ミラーの設定が反映されている。

image.png

0
1
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
0
1