• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

安装Ruby

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

由于在安装Redis集群的时候需要Ruby,但是直接yum Install ruby的版本太低了,会报粗

[root@iZbp143t3oxhfc3ar7jey0Z bin]# gem install -l redis-4.1.2.gem
ERROR:  Could not find a valid gem 'redis-4.1.2.gem' (>= 0) in any repository
[root@iZbp143t3oxhfc3ar7jey0Z bin]# gem install redis
Fetching: redis-4.1.3.gem (100%)
ERROR:  Error installing redis:
        redis requires Ruby version >= 2.3.0.

1.安装curl

[root@iZbp143t3oxhfc3ar7jey0Z bin]# yum -y install curl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * webtatic: us-east.repo.webtatic.com

Package curl-7.29.0-54.el7_7.2.x86_64 already installed and latest version
Nothing to do

2.安装rvm

root@iZbp143t3oxhfc3ar7jey0Z bin]# gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <[email protected]>" imported
gpg: key D39DC0E3: public key "Totally Legit Signing Key <[email protected]>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 2
gpg:               imported: 2  (RSA: 2)
[root@iZbp143t3oxhfc3ar7jey0Z bin]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0     66      0  0:00:02  0:00:02 --:--:--    66
100 24535  100 24535    0     0   6979      0  0:00:03  0:00:03 --:--:--  6979
Downloading https://github.com/rvm/rvm/archive/1.29.10.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.10/1.29.10.tar.gz.asc
gpg: Signature made Thu 26 Mar 2020 05:58:42 AM CST using RSA key ID 39499BDB
gpg: Can't check signature: No public key
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.10.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.10/1.29.10.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security

 解决:

[root@iZbp143t3oxhfc3ar7jey0Z bin]#  gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: requesting key D39DC0E3 from hkp server pool.sks-keyservers.net
gpg: requesting key 39499BDB from hkp server pool.sks-keyservers.net
gpg: key D39DC0E3: "Michal Papis (RVM signing) <[email protected]>" not changed
gpg: key 39499BDB: "Piotr Kuczynski <[email protected]>" not changed
gpg: Total number processed: 2
gpg:              unchanged: 2
[root@iZbp143t3oxhfc3ar7jey0Z bin]# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
https://gems.ruby-china.com/ added to sources
https://rubygems.org/ removed from sources

在开始重新安装

[root@iZbp143t3oxhfc3ar7jey0Z bin]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.10.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.10/1.29.10.tar.gz.asc
gpg: Signature made Thu 26 Mar 2020 05:58:42 AM CST using RSA key ID 39499BDB
gpg: Good signature from "Piotr Kuczynski <[email protected]>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.10.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!
Thanks for installing RVM ????
Please consider donating to our open collective to help us maintain RVM.

????  Donate: https://opencollective.com/rvm/donate

安装完成后,会列出一些安装信息,其中有一行要注意:

...
To start using RVM you need to run `source /etc/profile.d/rvm.sh`
....

意思是如果要开始使用需要执行一个 source 命令来重新执行刚修改的初始化文件,根据安装提示,执行以下命令载入 RVM 环境(新开 Termal 就不用这么做了,会自动重新载入的)

[root@iZbp143t3oxhfc3ar7jey0Z bin]# source /etc/profile.d/rvm.sh
[root@iZbp143t3oxhfc3ar7jey0Z bin]# 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[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.9]
[ruby-]2.5[.7]
[ruby-]2.6[.5]
[ruby-]2.7[.0]
ruby-head

用 RVM 安装 Ruby 环境

列出已知的 ruby 版本:

 rvm list known

可以选择现有的 rvm 版本来进行安装(下面以 rvm 2.4.2 版本的安装为例)

rvm install 2.4.2

同样继续等待漫长的下载,编译过程,完成以后,Ruby, Ruby Gems 就安装好了。

rvm 常用命令

查询已经安装的 ruby

[root@iZbp143t3oxhfc3ar7jey0Z bin]# rvm list
=* ruby-2.4.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

[root@iZbp143t3oxhfc3ar7jey0Z bin]# 

卸载一个已安装版本

rvm remove 1.9.2

设置 Ruby 版本

RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本

[root@iZbp143t3oxhfc3ar7jey0Z bin]# rvm 2.4.2  --default
Using /usr/local/rvm/gems/ruby-2.4.2
[root@iZbp143t3oxhfc3ar7jey0Z bin]# 

同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本

这个时候你可以测试是否正确

[root@iZbp143t3oxhfc3ar7jey0Z bin]# ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
[root@iZbp143t3oxhfc3ar7jey0Z bin]# gem -v
3.0.8
[root@iZbp143t3oxhfc3ar7jey0Z bin]#

这有可能是因为 Ruby 的默认源使用的是 cocoapods.org,国内访问这个网址有时候会有问题,网上的一种解决方案是将远替换成 ruby-china 的,替换方式如下:

$ gem source -r https://rubygems.org/
$ gem source -a https://gems.ruby-china.com/

要想验证是否替换成功了,可以执行:

[root@iZbp143t3oxhfc3ar7jey0Z bin]# gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.com/
[root@iZbp143t3oxhfc3ar7jey0Z bin]#

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap