CentOS7.x升级ruby

 安装ruby

[root@1bf2de961f30 /]# yum install ruby -y

 查看版本

[root@1bf2de961f30 /]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
[root@1bf2de961f30 /]# 

 

修改ruby国内仓库

可以来提高访问速度

# 查看默认的仓库
[root@1bf2de961f30 /]# gem sources -l

*** CURRENT SOURCES ***

https://rubygems.org/

# 修改为阿里云仓库
[root@1bf2de961f30 /]# gem sources -a http://mirrors.aliyun.com/rubygems/ --remove https://rubygems.org/
http://mirrors.aliyun.com/rubygems/ added to sources
https://rubygems.org/ removed from sources

 

 

升级ruby到2.6

安装yum源

[root@1bf2de961f30 /]# yum install centos-release-scl-rh 
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package centos-release-scl-rh.noarch 0:2-3.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================
 Package                                           Arch                               Version                                     Repository                          Size
===========================================================================================================================================================================
Installing:
 centos-release-scl-rh                             noarch                             2-3.el7.centos                              extras                              12 k

Transaction Summary
===========================================================================================================================================================================
Install  1 Package

Total download size: 12 k
Installed size: 20 k
Is this ok [y/d/N]: y
Downloading packages:
centos-release-scl-rh-2-3.el7.centos.noarch.rpm                                                                                                     |  12 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : centos-release-scl-rh-2-3.el7.centos.noarch                                                                                                             1/1 
  Verifying  : centos-release-scl-rh-2-3.el7.centos.noarch                                                                                                             1/1 

Installed:
  centos-release-scl-rh.noarch 0:2-3.el7.centos                                                                                                                            

Complete!
[root@1bf2de961f30 /]# 

 安装ruby2.6

[root@1bf2de961f30 /]# yum install rh-ruby26 -y
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * centos-sclo-rh: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package rh-ruby26.x86_64 0:2.6-1.el7 will be installed
--> Processing Dependency: rh-ruby26-runtime for package: rh-ruby26-2.6-1.el7.x86_64
--> Processing Dependency: rh-ruby26-ruby for package: rh-ruby26-2.6-1.el7.x86_64
--> Running transaction check
---> Package rh-ruby26-ruby.x86_64 0:2.6.10-121.el7 will be installed
--> Processing Dependency: rh-ruby26-ruby-libs(x86-64) = 2.6.10-121.el7 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-ruby(rubygems) >= 3.0.3.1 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(bigdecimal) >= 1.4.1 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(did_you_mean) >= 1.3.0 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(io-console) >= 0.4.7 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(json) >= 2.1.0 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(openssl) >= 2.1.2 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(psych) >= 3.1.0 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: rh-ruby26-rubygem(rdoc) >= 6.1.2.1 for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
--> Processing Dependency: libruby.so.2.6()(64bit) for package: rh-ruby26-ruby-2.6.10-121.el7.x86_64
---> Package rh-ruby26-runtime.x86_64 0:2.6-1.el7 will be installed
--> Running transaction check
---> Package rh-ruby26-ruby-libs.x86_64 0:2.6.10-121.el7 will be installed
---> Package rh-ruby26-rubygem-bigdecimal.x86_64 0:1.4.1-121.el7 will be installed
---> Package rh-ruby26-rubygem-did_you_mean.noarch 0:1.3.0-121.el7 will be installed
---> Package rh-ruby26-rubygem-io-console.x86_64 0:0.4.7-121.el7 will be installed
---> Package rh-ruby26-rubygem-json.x86_64 0:2.1.0-121.el7 will be installed
---> Package rh-ruby26-rubygem-openssl.x86_64 0:2.1.2-121.el7 will be installed
---> Package rh-ruby26-rubygem-psych.x86_64 0:3.1.0-121.el7 will be installed
---> Package rh-ruby26-rubygem-rdoc.noarch 0:6.1.2.1-121.el7 will be installed
--> Processing Dependency: rh-ruby26-rubygem(irb) = 1.0.0 for package: rh-ruby26-rubygem-rdoc-6.1.2.1-121.el7.noarch
---> Package rh-ruby26-rubygems.noarch 0:3.0.3.1-121.el7 will be installed
--> Running transaction check
---> Package rh-ruby26-rubygem-irb.noarch 0:1.0.0-121.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================
 Package                                               Arch                          Version                                   Repository                             Size
===========================================================================================================================================================================
Installing:
 rh-ruby26                                             x86_64                        2.6-1.el7                

 加载临时环境变量

# 临时加载环境变量
[root@1bf2de961f30 /]# scl enable rh-ruby26 bash

 再次查看版本

[root@1bf2de961f30 /]# ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [x86_64-linux]
[root@1bf2de961f30 /]# 

 

添加配置

因为上面添加的环境变量是临时的,重启以后就不再生效,为了一直生效,需添加环境变量配置。

创建配置文件rh-ruby26.sh

vim /etc/profile.d/rh-ruby26.sh

#!/bin/bash
source /opt/rh/rh-ruby26/enable
export X_SCLS="`scl enable rh-ruby26 'echo $X_SCLS'`"
export PATH=$PATH:/opt/rh/rh-ruby26/root/usr/local/bin

作者:编程永无止境
链接:https://www.jianshu.com/p/874b5aaa2326
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值