升级ruby的版本

升级ruby版本,有时候安装ruby的版本过低,需要进行升级,例如安装在centos6.7安装fpm需要ruby版本在1.9以上。

1、主机环境如下:

1 [root@test ~]# cat /etc/redhat-release 
2 CentOS release 6.7 (Final)
3 [root@test ~]# uname -r
4 2.6.32-573.el6.x86_64

2、使用yum安装ruby

[root@web ~]# yum install rubygems ruby-devel               
Loaded plugins: fastestmirror, security
Setting up Install Process
base                                                                                                   | 3.7 kB     00:00     
base/primary_db                                                                                        | 4.7 MB     00:02     
extras                                                                                                 | 3.4 kB     00:00     
extras/primary_db                                                                                      |  30 kB     00:00     
updates                                                                                                | 3.4 kB     00:00     
updates/primary_db                                                                                     | 8.1 MB     00:01     
Resolving Dependencies
--> Running transaction check
---> Package ruby-devel.x86_64 0:1.8.7.374-5.el6 will be installed
--> Processing Dependency: ruby-libs = 1.8.7.374-5.el6 for package: ruby-devel-1.8.7.374-5.el6.x86_64
--> Processing Dependency: libruby.so.1.8()(64bit) for package: ruby-devel-1.8.7.374-5.el6.x86_64
---> Package rubygems.noarch 0:1.3.7-5.el6 will be installed
--> Processing Dependency: ruby-rdoc for package: rubygems-1.3.7-5.el6.noarch
--> Processing Dependency: /usr/bin/ruby for package: rubygems-1.3.7-5.el6.noarch
--> Running transaction check
---> Package ruby.x86_64 0:1.8.7.374-5.el6 will be installed
---> Package ruby-libs.x86_64 0:1.8.7.374-5.el6 will be installed
---> Package ruby-rdoc.x86_64 0:1.8.7.374-5.el6 will be installed
--> Processing Dependency: ruby-irb = 1.8.7.374-5.el6 for package: ruby-rdoc-1.8.7.374-5.el6.x86_64
--> Running transaction check
---> Package ruby-irb.x86_64 0:1.8.7.374-5.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================
 Package                        Arch                       Version                             Repository                Size
==============================================================================================================================
Installing:
 ruby-devel                     x86_64                     1.8.7.374-5.el6                     base                     318 k
 rubygems                       noarch                     1.3.7-5.el6                         base                     207 k
Installing for dependencies:
 ruby                           x86_64                     1.8.7.374-5.el6                     base                     538 k
 ruby-irb                       x86_64                     1.8.7.374-5.el6                     base                     318 k
 ruby-libs                      x86_64                     1.8.7.374-5.el6                     base                     1.7 M
 ruby-rdoc                      x86_64                     1.8.7.374-5.el6                     base                     381 k

Transaction Summary
==============================================================================================================================
Install       6 Package(s)

Total download size: 3.4 M
Installed size: 12 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): ruby-1.8.7.374-5.el6.x86_64.rpm                                                                 | 538 kB     00:00     
(2/6): ruby-devel-1.8.7.374-5.el6.x86_64.rpm                                                           | 318 kB     00:00     
(3/6): ruby-irb-1.8.7.374-5.el6.x86_64.rpm                                                             | 318 kB     00:00     
(4/6): ruby-libs-1.8.7.374-5.el6.x86_64.rpm                                                            | 1.7 MB     00:01     
(5/6): ruby-rdoc-1.8.7.374-5.el6.x86_64.rpm                                                            | 381 kB     00:00     
(6/6): rubygems-1.3.7-5.el6.noarch.rpm                                                                 | 207 kB     00:00     
------------------------------------------------------------------------------------------------------------------------------
Total                                                                                         502 kB/s | 3.4 MB     00:06     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-7.el6.centos.12.3.x86_64 (@anaconda-CentOS-201508042137.x86_64/6.7)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : ruby-libs-1.8.7.374-5.el6.x86_64                                                                           1/6 
  Installing : ruby-1.8.7.374-5.el6.x86_64                                                                                2/6 
  Installing : ruby-irb-1.8.7.374-5.el6.x86_64                                                                            3/6 
  Installing : ruby-rdoc-1.8.7.374-5.el6.x86_64                                                                           4/6 
  Installing : rubygems-1.3.7-5.el6.noarch                                                                                5/6 
  Installing : ruby-devel-1.8.7.374-5.el6.x86_64                                                                          6/6 
  Verifying  : ruby-rdoc-1.8.7.374-5.el6.x86_64                                                                           1/6 
  Verifying  : ruby-1.8.7.374-5.el6.x86_64                                                                                2/6 
  Verifying  : rubygems-1.3.7-5.el6.noarch                                                                                3/6 
  Verifying  : ruby-libs-1.8.7.374-5.el6.x86_64                                                                           4/6 
  Verifying  : ruby-irb-1.8.7.374-5.el6.x86_64                                                                            5/6 
  Verifying  : ruby-devel-1.8.7.374-5.el6.x86_64                                                                          6/6 

Installed:
  ruby-devel.x86_64 0:1.8.7.374-5.el6                              rubygems.noarch 0:1.3.7-5.el6                             

Dependency Installed:
  ruby.x86_64 0:1.8.7.374-5.el6             ruby-irb.x86_64 0:1.8.7.374-5.el6        ruby-libs.x86_64 0:1.8.7.374-5.el6       
  ruby-rdoc.x86_64 0:1.8.7.374-5.el6       

Complete!

3、查看ruby的版本

1 [root@web ~]# ruby -v
2 ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

4、升级ruby1.9.3版本

1)删除原来的rubygems仓库

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

2)添加aliyun的rubygems仓库

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

3)查看rubygems仓库

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

4)使用RVM进行升级ruby

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

[root@web ~]#  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@web ~]# \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
curl: (35) SSL connect error

Could not download 'https://github.com/rvm/rvm/archive/1.29.3.tar.gz'.
  curl returned status '35'.

Downloading https://bitbucket.org/mpapis/rvm/get/1.29.3.tar.gz
Downloading https://bitbucket.org/mpapis/rvm/downloads/1.29.3.tar.gz.asc
curl: (7) couldn't connect to host

Could not download 'https://bitbucket.org/mpapis/rvm/downloads/1.29.3.tar.gz.asc'.
  curl returned status '7'.

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.

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

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

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

[root@web ~]# rvm list known
# 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[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
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.13.0]
jruby-head

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

# 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[-head]

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

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# 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-1.9.3版本

[root@web ~]# rvm install 1.9.3
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/6/x86_64/ruby-1.9.3-p551.tar.bz2
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: libffi-devel, readline-devel, sqlite-devel, zlib-devel, libyaml-devel, openssl-devel...........|
Requirements installation successful.
ruby-1.9.3-p551 - #configure
ruby-1.9.3-p551 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10.2M  100 10.2M    0     0   188k      0  0:00:55  0:00:55 --:--:--  223k
ruby-1.9.3-p551 - #validate archive
ruby-1.9.3-p551 - #extract
ruby-1.9.3-p551 - #validate binary
ruby-1.9.3-p551 - #setup
ruby-1.9.3-p551 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p551@global
ruby-1.9.3-p551 - #importing gemset /usr/local/rvm/gemsets/global.gems...................................
ruby-1.9.3-p551 - #generating global wrappers........
ruby-1.9.3-p551 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p551
ruby-1.9.3-p551 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p551 - #generating default wrappers........

7、查看ruby是否升级成功

1 [root@web ~]# ruby -v
2 ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]

至此,ruby版本升级成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值