Install rbenv, Ruby on CentOS
At first
Since I had a chance to install Rails on CentOS for the first time in a long time, I made a note of the procedure of installing rbenv, Ruby.
environment CentOS 7.3.1611
Lottery 1. Git 2. rbenv 3. ruby-build 4. .bash_profile 5. Packaging 6. ruby 7. Errors and Solutions 8. Points to note when installing Ruby with yum
1. Git
# インストール
$ sudo yum -y install git
# バージョン確認
$ git --version
2. rbenv
# rbenvインストール
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
# ディレクトリ確認
$ ls -d ~/.rbenv
3. ruby-build
# インストール
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# ディレクトリ確認
$ ls -d ~/.rbenv/plugins/ruby-build
4. .bash_profile
# 設定
$ echo '# rbenv' >> ~/.bash_profile
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# 確認
$ cat ~/.bash_profile
# 反映
$ exec $SHELL --login
5. Packaging
# rubyのインストールに必要なパッケージをインストール
$ sudo yum -y install bzip2 gcc openssl-devel readline-devel zlib-devel
# バージョン確認
$ bzip2 --version
$ gcc --version
$ yum list installed | grep openssl-devel
$ yum list installed | grep readline-devel
$ yum list installed | grep zlib-devel
6. ruby
# バージョン確認
$ rbenv --version
# インストールできるrubyのバージョンを確認
$ rbenv install --list
# rubyインストール
$ rbenv install <version>
# 切り替え可能なrubyのバージョンを確認
$ rbenv versions
# rubyのバージョンを切り替え
$ rbenv global <version>
# rubyのバージョンが切り替わったことを確認
$ ruby -v
7. Errors and Solutions
If there is a missing package, the installation of Ruby will fail, so install the package with reference to the error log.
If bzip2 is not installed
Error
BUILD FAILED (CentOS Linux 7 using ruby-build 20170523-29-gdb3e43a)
Inspect or clean up the working tree at /tmp/ruby-build.20170725093106.1536
Results logged to /tmp/ruby-build.20170725093106.1536.log
Last 10 log lines:
/tmp/ruby-build.20170725093106.1536 ~
warning: bzip2 not found; consider installing `bzip2` package
tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Resolution
# インストール
$ sudo yum -y install bzip2
# バージョン確認
$ bzip2 --version
If gcc is not installed
Error
BUILD FAILED (CentOS Linux 7 using ruby-build 20170523-29-gdb3e43a)
Inspect or clean up the working tree at /tmp/ruby-build.20170725093413.1634
Results logged to /tmp/ruby-build.20170725093413.1634.log
Last 10 log lines:
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20170725093413.1634/ruby-2.4.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
Resolution
# インストール
$ sudo yum -y install gcc
# バージョン確認
$ gcc --version
openssl-devel, readline-devel, zlib-devel is not installed
Error
BUILD FAILED (CentOS Linux 7 using ruby-build 20170523-29-gdb3e43a)
Inspect or clean up the working tree at /tmp/ruby-build.20170725093816.1958
Results logged to /tmp/ruby-build.20170725093816.1958.log
Last 10 log lines:
The Ruby openssl extension was not compiled.
The Ruby readline extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y openssl-devel readline-devel zlib-devel` to fetch missing dependencies.
Configure options used:
--prefix=/home/xxx/.rbenv/versions/2.4.1
LDFLAGS=-L/home/xxx/.rbenv/versions/2.4.1/lib
CPPFLAGS=-I/home/xxx/.rbenv/versions/2.4.1/include
Resolution
# インストール
$ sudo yum install -y openssl-devel readline-devel zlib-devel
# バージョン確認
$ yum list installed | grep openssl-devel
$ yum list installed | grep readline-devel
$ yum list installed | grep zlib-devel
If make is not installed
Resolution
# インストール
$ sudo yum install make
※ This section was supplemented by @Inp in the comment section and added
8. Points to note when installing Ruby with yum
You can also install Ruby with yum, but be careful because it installs a slightly older version
At the time of writing, it is ruby 2.0.0p648
to be installed, and it does not meet the version (2.2.2 or higher) required by Rails 5
# インストールされるバージョンを確認
$ yum list installed | grep ruby.x86_64
# インストール
$ sudo yum install -y ruby
# バージョン確認
$ ruby -v