PR

[Ubuntu] 1行コマンドで高速リポジトリに変更する

様々なテストのために、毎度真新しいUbuntu 環境を用意している。

VMware Player では簡易インストールに対応しており、直ぐに環境ができあがる。だが、その後のupdate やinstall で待たされることがある。速度は90-170kbps 程度であり、もっと高速化できるはず。

Ubuntu (Linux)における,リポジトリとは,インターネット上にある,ソフトウェアの倉庫だと考え下さい。ユーザーは,ここから自由にソフトウェア,アプリケーションパッケージをダウンロードできます。(「リポジトリとは」より引用)

GUI 環境なら容易な操作でダウンロード元を日本に切り替えることができるが、Ubuntu Server を利用しているため、GUI 環境を用意すること自体に時間がかかる。当然CUI でも可能だが、まさかVi で丁寧に書き換えるとか、どこかにテキストを保存しておき、SSH 経由で書き換えるなんていうのも面倒だ。

そういえばと思いだしたのがsed コマンド。確か書き換えを行なってくれるコマンドだ。

スポンサードリンク

1行コマンドで高速リポジトリに変更する

柔軟な書き換えに対応していて、正規表現も可能だから「/etc/apt/sources.list」に記述されている「http://us.archive.ubuntu.com/ubuntu/」を「http://ftp.jaist.ac.jp/ubuntu/」に書き換えるなら「s/\/\/us.archive.ubuntu.com/\/\/ftp.jaist.ac.jp/g」とすればいい。しかもオプション「-i」を指定すればバックアップまでとってくれるという親切設計。

書き換えコマンド

ということで、次のコマンドを実行する:

$ sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp.jaist.ac.jp/g'  /etc/apt/sources.list

※ダウンロード元は「日本国内のダウンロードサイト | Ubuntu Japanese Team」あたりを参考に好みのものを(ほかに回線の太さなどが記載されたページもあったのだが見失ってしまった→あった:Mirrors : Ubuntu

速度は向上したか

実際に利用してみると少なくとも10倍以上の速度向上となった。が、それでも十分な速度が出ていないような気もする。選択しているサーバーが正しくないのか、混雑しているのか、多数で接続しているために割り当てられる帯域が少ないのかは不明だが、これまでよりは断然に高速化した。

書き換えられたファイルの内容

$ sudo cat /etc/apt/sources.list
#
# deb cdrom:[Ubuntu-Server 10.04.4 LTS _Lucid Lynx_ - Release i386 (20120214.2)]/ lucid main restricted

#deb cdrom:[Ubuntu-Server 10.04.4 LTS _Lucid Lynx_ - Release i386 (20120214.2)]/ lucid main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb http://ftp.jaist.ac.jp/ubuntu/ lucid main restricted
deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ftp.jaist.ac.jp/ubuntu/ lucid-updates main restricted
deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ftp.jaist.ac.jp/ubuntu/ lucid universe
deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid universe
deb http://ftp.jaist.ac.jp/ubuntu/ lucid-updates universe
deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ftp.jaist.ac.jp/ubuntu/ lucid multiverse
deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid multiverse
deb http://ftp.jaist.ac.jp/ubuntu/ lucid-updates multiverse
deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://ftp.jaist.ac.jp/ubuntu/ lucid-backports main restricted universe multiverse
# deb-src http://ftp.jaist.ac.jp/ubuntu/ lucid-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu lucid partner
# deb-src http://archive.canonical.com/ubuntu lucid partner

deb http://security.ubuntu.com/ubuntu lucid-security main restricted
deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted
deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe
deb http://security.ubuntu.com/ubuntu lucid-security multiverse
deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse

# この内容・方法が正しいかどうかは知らないから、各自のご判断でどうぞ

追記

2012.04.17 追記

リストア

うまくいかない時にバックアップファイルを戻す

sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list

OK

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ubuntutym.u-toyama.ac.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ubuntu-ashisuto.ubuntulinux.jp/g' /etc/apt/sources.list

NG

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp.yz.yamagata-u.ac.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp\.iij\.ad\.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp.kddilabs.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp.riken.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp.ne.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ftp.riken.go.jp/g' /etc/apt/sources.list

sudo sed -i".bak" -e 's/\/\/us.archive.ubuntu.com/\/\/ubuntu.mithril-linux.org/g' /etc/apt/sources.list

参考文献

コメント