LoginSignup
6
5

More than 5 years have passed since last update.

proxy環境でも行ける Ruby最新版インストール

Last updated at Posted at 2018-07-02

Rbenvのインストール

まず先にRubyのバージョンを管理するrbenvというツールと
Rubyの最新バージョンのリポジトリ?(ruby-build)をダウンロードします。

ダウンロードと環境の設定

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

次に環境の設定を一番下に追記
$ vi ~/.bashrc
Macなら
$ vi ~/.bash_profile
zshの方は
$ vi ~/.zsh_aliases

~/.zsh_aliases
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

ちゃんと動くか確認

$ rbenv --version
rbenv 1.1.1-37-g1c772d5

Rubyをインストールする

それでは、インストールしていきます。

インストール可能な最新バージョンを見る

$ rbenv install -l
...
2.5.0
2.5.1
2.6.0-dev
2.6.0-preview1
2.6.0-preview2
...

この時安定の最新バージョンは、2.5.1でした。

インストールする

$ rbenv install 2.5.1

インストールでproxyの方はエラーが出たかもしれない。

proxyの設定

まずgitとcurlとwgetのプロキシ設定を行う

git

$ git config --global http.proxy http://[proxy.example.com]:8080
$ git config --global https.proxy http://[proxy.example.com]:8080

curl

$ vim ~/.curlrc
proxy-user="[id]:[pass]"
proxy="http://[proxy.example.com]:8080"

wget

$ sudo vim /etc/wgetrc

一番最後の行に足す

# proxy
https_proxy = http://[id]:[pass]@[proxy.example.com]:8080/
http_proxy = http://[id]:[pass]@[proxy.example.com]:8080/
ftp_proxy = http://[id]:[pass]@[proxy.example.com]:8080/
$ rbenv install 2.5.1
Downloading ruby-2.5.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2
error: failed to download ruby-2.5.1.tar.bz2

proxyエラーの結論

色々探した結果「ruby-build」のデフォルト設定に問題がある
修正します。

vim ~/.rbenv/plugins/ruby-build/bin/ruby-build
http_head_curl() {
  curl -qsILf ${CURL_OPTS} "$1" >&4 2>&1
}

http_get_curl() {
  curl -q -o "${2:--}" -sSLf ${CURL_OPTS} "$1"
}

この設定のオプション-qを消します。

http_head_curl() {
  curl -sILf ${CURL_OPTS} "$1" >&4 2>&1
}

http_get_curl() {
  curl -o "${2:--}" -sSLf ${CURL_OPTS} "$1"
}

もう一度実行

一応更新

$ rbenv rehash

インストール

$ rbenv install 2.5.1

待ち時間は、少し長め
エラーが出なければ待っておけばいい。

最後の設定

インストールされているか確認

$ rbenv versions
2.5.1

常時使用するバージョンを設定する

$ rbenv global 2.5.1
$ rbenv versions
* 2.5.1 (set by /home/master/.rbenv/version)

globalで設定したバージョンに「*」が出ていれば完了

確認する

$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
6
5
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
6
5