Buravo46's Note

学んだ事を書いていくブログです。

【Ruby】Ruby環境の構築

概要

Rubyが使える環境を構築する。
バージョンの切り替えや管理もできるように対応する。

本記事はRubyちょっと書いてみてよって言われたときの構築メモとなります。

手順

  • Rubyに必要なRPMのインストールやyumの更新
yum install -y git
yum install -y gcc-c++
yum install -y glibc-headers
yum install -y openssl-devel
yum install -y readline
yum install -y libyaml-devel
yum install -y readline-devel
yum install -y zlib
yum install -y zlib-devel
yum update -y
  • Rubyのバージョン管理ツールの導入
git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv
echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile
echo 'export PATH="${RBENV_ROOT}/bin:${PATH}"' >> /etc/profile
echo 'eval "$(rbenv init -)"' >> /etc/profile
source /etc/profile
rbenv --version
git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build
  • Rubyのインストール
rbenv install -l
rbenv install -v 2.3.4
rbenv rehash
rbenv global 2.3.4
ruby -v

トラブルシューティング

  • rbenvでのrubyインストールに失敗する
    CentOS7がデフォルトの状態だとインストールに失敗する。
[root@DotontoF ~]# rbenv install -v 2.3.4
[Sun Oct 01 18:17:51.025 2017] ruby -v/tmp/ruby-build.20171001111750.5532 ~
[Sun Oct 01 18:17:51.085 2017] Downloading ruby-2.3.4.tar.bz2...
[Sun Oct 01 18:17:51.085 2017] -> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.4.tar.bz2
[Sun Oct 01 18:17:51.577 2017] curl: (35) Peer reports incompatible or unsupported protocol version.
[Sun Oct 01 18:17:51.577 2017] error: failed to download ruby-2.3.4.tar.bz2
[Sun Oct 01 18:17:51.577 2017] 
[Sun Oct 01 18:17:51.577 2017] BUILD FAILED (CentOS Linux 7 using ruby-build 20170914-2-ge40cd1f)
[root@DotontoF ~]# cat /tmp/ruby-build.20171001111750.5532.log
/tmp/ruby-build.20171001111750.5532 ~
curl: (35) Peer reports incompatible or unsupported protocol version.

調べてみるとcurlのバージョンが古いので発生するみたいなので更新すると解決した。

yum update

参考サイト

https://altarf.net/computer/ruby/3925