当前位置: 首页 > 工具软件 > Topaz Ruby > 使用案例 >

如何升级ruby的版本

简培
2023-12-01

如何升级ruby的版本

升级ruby版本,在配置Redis集群时有提示报错,提示安装ruby的版本过低,需要进行升级,例如安装在centos7.5安装需要ruby版本在 2.2.2以上。

1、主机环境如下:

[root@localhost bin]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost bin]# uname -r
3.10.0-862.el7.x86_64

2、使用yum安装ruby

[root@localhost ~]# yum install rubygems ruby-devel
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
base                                                                                                                                                                                                          | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                        | 3.4 kB  00:00:00     
updates                                                                                                                                                                                                       | 3.4 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 ruby-devel.x86_64.0.2.0.0.648-34.el7_6 将被 安装
--> 正在处理依赖关系 ruby(x86-64) = 2.0.0.648-34.el7_6,它被软件包 ruby-devel-2.0.0.648-34.el7_6.x86_64 需要
---> 软件包 rubygems.noarch.0.2.0.14.1-33.el7_4 将被 升级
---> 软件包 rubygems.noarch.0.2.0.14.1-34.el7_6 将被 更新
--> 正在检查事务
---> 软件包 ruby.x86_64.0.2.0.0.648-33.el7_4 将被 升级
---> 软件包 ruby.x86_64.0.2.0.0.648-34.el7_6 将被 更新
--> 正在处理依赖关系 ruby-libs(x86-64) = 2.0.0.648-34.el7_6,它被软件包 ruby-2.0.0.648-34.el7_6.x86_64 需要
--> 正在检查事务
---> 软件包 ruby-libs.x86_64.0.2.0.0.648-33.el7_4 将被 升级
---> 软件包 ruby-libs.x86_64.0.2.0.0.648-34.el7_6 将被 更新
--> 解决依赖关系完成

依赖关系解决

================================================================================================
 Package                       架构                                        版本                                        源                                  大小
================================================================================================
正在安装:
 ruby-devel                     x86_64                                   2.0.0.648-34.el7_6                             updates                              131 k
正在更新:
 rubygems                       noarch                                   2.0.14.1-34.el7_6                              updates                               219 k
为依赖而更新:
 ruby                           x86_64                                   2.0.0.648-34.el7_6                             updates                              71 k
 ruby-libs                      x86_64                                   2.0.0.648-34.el7_6                              updates                             2.8 M

事务概要
================================================================================================
安装  1 软件包
升级  1 软件包 (+2 依赖软件包)

总下载量:3.2 M
Is this ok [y/d/N]: y
Downloading packages:
updates/7/x86_64/prestodelta                                                                                                               | 174 kB  00:00:00     
Delta RPMs reduced 3.1 M of updates to 507 k (83% saved)
(1/4): ruby-2.0.0.648-33.el7_4_2.0.0.648-34.el7_6.x86_64.drpm                                                          |  50 kB  00:00:00     
(2/4): ruby-devel-2.0.0.648-34.el7_6.x86_64.rpm                                                                                  | 131 kB  00:00:00     
(3/4): rubygems-2.0.14.1-33.el7_4_2.0.14.1-34.el7_6.noarch.drpm                                                      |  65 kB  00:00:00     
(4/4): ruby-libs-2.0.0.648-33.el7_4_2.0.0.648-34.el7_6.x86_64.drpm                                                   | 392 kB  00:00:02     
Finishing delta rebuilds of 1 package(s) (2.8 M)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                             144 kB/s | 637 kB  00:00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : ruby-libs-2.0.0.648-34.el7_6.x86_64                                                                                                         1/7
  正在更新    : rubygems-2.0.14.1-34.el7_6.noarch                                                                                                           2/7
  正在更新    : ruby-2.0.0.648-34.el7_6.x86_64                                                                                                              3/7
  正在安装    : ruby-devel-2.0.0.648-34.el7_6.x86_64                                                                                                        4/7
  清理        : ruby-2.0.0.648-33.el7_4.x86_64                                                                                                              5/7
  清理        : rubygems-2.0.14.1-33.el7_4.noarch                                                                                                           6/7
  清理        : ruby-libs-2.0.0.648-33.el7_4.x86_64                                                                                                         7/7
  验证中      : ruby-libs-2.0.0.648-34.el7_6.x86_64                                                                                                         1/7
  验证中      : rubygems-2.0.14.1-34.el7_6.noarch                                                                                                           2/7
  验证中      : ruby-2.0.0.648-34.el7_6.x86_64                                                                                                              3/7
  验证中      : ruby-devel-2.0.0.648-34.el7_6.x86_64                                                                                                        4/7
  验证中      : ruby-2.0.0.648-33.el7_4.x86_64                                                                                                              5/7
  验证中      : ruby-libs-2.0.0.648-33.el7_4.x86_64                                                                                                         6/7
  验证中      : rubygems-2.0.14.1-33.el7_4.noarch                                                                                                           7/7

已安装:
  ruby-devel.x86_64  0:2.0.0.648-34.el7_6                                                                                                                                                                                     

更新完毕:
  rubygems.noarch    0:2.0.14.1-34.el7_6                                                                                                                                                                                                

作为依赖被升级:
  ruby.x86_64 0:2.0.0.648-34.el7_6                          ruby-libs.x86_64 0:2.0.0.648-34.el7_6  

                                                                         

完毕!
 

3、查看ruby的版本

[root@localhost ~]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]

4、升级ruby 2.0.0 到2.2.2以上版本

1)删除原来的rubygems仓库

[root@localhost ~]# gem sources --remove http://rubygems.org/

2)添加aliyun的rubygems仓库

[root@localhost ~]# gem sources -a http://mirrors.aliyun.com/rubygems/

3)查看rubygems仓库

1 [root@localhost ~]# gem sources -l
2 *** CURRENT SOURCES ***
3 
4 http://mirrors.aliyun.com/rubygems/

4)使用RVM进行升级ruby

a:在rvm官方网址:https://rvm.io/执行如下命令:

 

[root@localhost ~]#  gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: requesting key 39499BDB from hkp server keys.gnupg.net
gpg: key D39DC0E3: "Michal Papis (RVM signing) <mpapis@gmail.com>" not changed
gpg: key 39499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 2
gpg:               imported: 1  (RSA: 1)
gpg:              unchanged: 1

 

b:接着执行如下命令:

 

[root@localhost ~]# \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.6.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.6/1.29.6.tar.gz.asc
gpg: 于 2018年12月13日 星期四 23时09分53秒 CST 创建的签名,使用 RSA,钥匙号 39499BDB
gpg: 完好的签名,来自于“Piotr Kuczynski <piotr.kuczynski@gmail.com>”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg:       没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.6.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the rvm group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also, please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!

 

c:执行上述命令 * To start using RVM you need to run `source /etc/profile.d/rvm.sh`

[root@localhost ~]# source /etc/profile.d/rvm.sh

5、查看RVM可安装的ruby的版本

 

[root@localhost ~]# rvm list known
Warning, new version of rvm available '1.29.7', you are using older version '1.29.6'.
You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.1]
[ruby-]2.5[.3]
[ruby-]2.6[.0-rc1]
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.5.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.100]
rbx-head

# TruffleRuby
truffleruby[-1.0.0-rc10]

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.1]
mruby-2[.0.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

 

 

6、安装ruby 2.4.1版本

 

[root@localhost ~]# rvm install ruby 2.4.1
Warning, new version of rvm available '1.29.7', you are using older version '1.29.6'.
You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.4.1.tar.bz2
Checking requirements for centos.
Requirements installation successful.
ruby-2.4.1 - #configure
ruby-2.4.1 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14.1M  100 14.1M    0     0   428k      0  0:00:33  0:00:33 --:--:--  435k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.1 - #validate archive
ruby-2.4.1 - #extract
ruby-2.4.1 - #validate binary
ruby-2.4.1 - #setup
ruby-2.4.1 - #gemset created /usr/local/rvm/gems/ruby-2.4.1@global
ruby-2.4.1 - #importing gemset /usr/local/rvm/gemsets/global.gems......................................................
ruby-2.4.1 - #generating global wrappers.......
ruby-2.4.1 - #gemset created /usr/local/rvm/gems/ruby-2.4.1
ruby-2.4.1 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.1 - #generating default wrappers.......

 

7、查看ruby是否升级成功

[root@localhost ~]# ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

至此,ruby版本升级成功

如果有错误,欢迎各位网友指导。

转载:http://www.cnblogs.com/eeexu123/p/9228044.html

 

 类似资料: