CentOS 7.9にRuby 2.7.5をインストールする

環境
# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

Rubyのインストールの方法
1.必要なパッケージをインストールします

# sudo yum -y install git bzip2 gcc gcc-c++ openssl-devel readline-devel zlib-devel

2.rbenvをインストールします

# git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
Cloning into '/root/.rbenv'...
remote: Enumerating objects: 2993, done.
remote: Counting objects: 100% (97/97), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 2993 (delta 51), reused 43 (delta 22), pack-reused 2896
Receiving objects: 100% (2993/2993), 602.00 KiB | 0 bytes/s, done.
Resolving deltas: 100% (1860/1860), done.

ruby-buildプラグインをインストールします

# git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Cloning into '/root/.rbenv/plugins/ruby-build'...
remote: Enumerating objects: 11955, done.
remote: Counting objects: 100% (648/648), done.
remote: Compressing objects: 100% (256/256), done.
remote: Total 11955 (delta 416), reused 536 (delta 346), pack-reused 11307
Receiving objects: 100% (11955/11955), 2.52 MiB | 0 bytes/s, done.
Resolving deltas: 100% (7883/7883), done.

確認

# ls ~/.rbenv/plugins/ruby-build/bin
rbenv-install  rbenv-uninstall  ruby-build

環境パスを「.bash_profile」に追加します

# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
# echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# exec $SHELL -l

3.rbenvバージョンを確認します

# rbenv --version
rbenv 1.2.0-6-g304cb7b

4.インストールできるrubyのバージョンを確認します

# rbenv install --list
2.6.9
2.7.5
3.0.3
3.1.0
jruby-9.3.2.0
mruby-3.0.0
rbx-5.0
truffleruby-21.3.0
truffleruby+graalvm-21.3.0

Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all / -L' to show all local versions.

5.ruby2.7.5をインストールします

# rbenv install 2.7.5
Downloading ruby-2.7.5.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.5.tar.bz2
Installing ruby-2.7.5...
Installed ruby-2.7.5 to /root/.rbenv/versions/2.7.5

# rbenv global 2.7.5
rubyのバージョンを確認します
# ruby -v
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]

CentOS 7

Posted by arkgame