CentOS 8 安装 Ruby 3

更新日期: 2023-01-31 阅读次数: 2487 字数: 337 分类: ruby

查看系统版本

> cat /etc/centos-release
CentOS Linux release 8.3.2011

安装 Ruby

我看本机 yum install ruby 默认安装的是 2.5 版本。 但是我想安装 3.0 版本的 ruby。

> dnf module reset ruby -y
> yum install @ruby:3.0
> ruby --version
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

参考: https://computingforgeeks.com/install-ruby-on-rhel-centos-rocky-linux/

换国内源镜像

执行 bundle install 时,会发现卡住不动了,猜测大概率是国内直连 rubygems 源网络不行。 所以尝试更换国内源:

bundle config mirror.https://rubygems.org https://gems.ruby-china.com

果然速度快多了。

如果是 gem install 卡住,配置:

gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

参考:https://gems.ruby-china.com/

安装 ruby-dev or ruby-devel 依赖

虽然 bundle install 可以顺畅的执行了,但是报错:

An error occurred while installing strscan (3.0.5), and Bundler cannot continue. Make sure that gem install strscan -v '3.0.5' --source 'https://rubygems.org/' succeeds before bundling.

手动执行:

gem install strscan -v '3.0.5'

报错:

Fetching strscan-3.0.5.gem
Building native extensions. This could take a while...
ERROR:  Error installing strscan:
ERROR: Failed to build gem native extension.
bundle config mirror.https://rubygems.org https://gems.ruby-china.com
/usr/bin/ruby -I /usr/share/rubygems -r ./siteconf20230130-648615-b8lo2f.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h
You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.
extconf failed, exit code 1
Gem files will remain installed in /usr/local/share/gems/gems/strscan-3.0.5 for inspection.
Results logged to /usr/local/lib64/gems/ruby/strscan-3.0.5/gem_make.out

看起来是需要安装 ruby-dev 或 ruby-devel。执行:

yum install ruby-devel

确认确实安装的是 ruby-devel 3.0.

再次执行 bundle install 就可以正常安装依赖了。

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式