LoginSignup
156
162

More than 5 years have passed since last update.

apt-getの利用リポジトリを日本サーバーに変更する

Last updated at Posted at 2014-12-20

vagrantで使おうとしているBoxのapt-get利用リポジトリがUSになっている場合がよくある。

$ sudo apt-get update
Hit http://security.ubuntu.com trusty-security Release.gpg
Get:1 http://us.archive.ubuntu.com trusty Release.gpg [933 B]
Hit http://security.ubuntu.com trusty-security Release
Get:2 http://us.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://security.ubuntu.com trusty-security/main Sources

なので、日本サーバにしてしまう。

# IIJにしたいとき
$ sudo sed -i.bak -e "s%http://us.archive.ubuntu.com/ubuntu/%http://ftp.iij.ad.jp/pub/linux/ubuntu/archive/%g" /etc/apt/sources.list

# jaistにしたいとき
$ sudo sed -i.bak -e "s%http://us.archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list

vagrant up時に設定しておいてほしいときは、vagrantfileでshell provisionerを使えばよい。

  config.vm.provision "shell", inline: <<-SHELL
sudo sed -i.bak -e "s%http://us.archive.ubuntu.com/ubuntu/%http://ftp.iij.ad.jp/pub/linux/ubuntu/archive/%g" /etc/apt/sources.list
SHELL

dockerfileで FROM ubuntu なときは、us指定を外して

# IIJにしたいとき
$ sudo sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.iij.ad.jp/pub/linux/ubuntu/archive/%g" /etc/apt/sources.list

# jaistにしたいとき
$ sudo sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list

とする必要がある。

思い入れのあるサーバがある場合は下記から選べばよい。
- 日本国内のダウンロードサイト | Ubuntu Japanese Team
- Mirrors : Ubuntu(回線の太さから判断できる)

追記

sedコマンドをもっと簡単に書いた。

$ sudo sed -i.bak -e "s%http://[^ ]\+%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list
156
162
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
156
162