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

CentOS7搭建ruby环境(RVM安装ruby以及ruby加速)

沈宇定
2023-12-01

血淋淋的教训,第二次使用rvm安装ruby(以普通用户运行)


[qqq@haproxy ~]$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
[qqq@haproxy ~]$ curl -L https://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     88      0  0:00:02  0:00:02 --:--:--    88
100 24173  100 24173    0     0   6639      0  0:00:03  0:00:03 --:--:-- 21297
Downloading https://github.com/rvm/rvm/archive/1.29.7.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc
gpg: 于 2019年01月04日 星期五 06时01分48秒 CST 创建的签名,使用 RSA,钥匙号 39499BDB
gpg: 完好的签名,来自于“Piotr Kuczynski <piotr.kuczynski@gmail.com>”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg:       没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/home/qqq/.rvm/archives/rvm-1.29.7.tgz'
Installing RVM to /home/qqq/.rvm/
    Adding rvm PATH line to /home/qqq/.profile /home/qqq/.mkshrc /home/qqq/.bashrc /home/qqq/.zshrc.
    Adding rvm loading line to /home/qqq/.profile /home/qqq/.bash_profile /home/qqq/.zlogin.
Installation of RVM in /home/qqq/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/qqq/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
[qqq@haproxy ~]$ source /home/qqq/.rvm/scripts/rvm
[qqq@haproxy ~]$ sudo yum install patch autoconf automake bison bzip2 gcc-c++ libffi-devel libtool patch readline-devel sqlite-devel zlib-devel glibc-headers glibc-devel openssl-devel

[qqq@haproxy ~]$ echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > ~/.rvm/user/db

[qqq@haproxy ~]$ rvm install ruby-2.6.0 --disable-binary
Checking requirements for centos.
Requirements installation successful.
-bash: /home/qqq/.rvm/scripts/functions/manage/install/centos: 没有那个文件或目录
Installing Ruby from source to: /home/qqq/.rvm/rubies/ruby-2.6.0, this may take a while depending on your cpu(s)...
ruby-2.6.0 - #downloading ruby-2.6.0, this may take a while depending on your connection...
** Resuming transfer from byte position 1335296
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12.6M  100 12.6M    0     0  8360k      0  0:00:01  0:00:01 --:--:-- 8364k
ruby-2.6.0 - #extracting ruby-2.6.0 to /home/qqq/.rvm/src/ruby-2.6.0.....
ruby-2.6.0 - #configuring......................................................................
ruby-2.6.0 - #post-configuration..
ruby-2.6.0 - #compiling............................................................................................
ruby-2.6.0 - #installing...............................
ruby-2.6.0 - #making binaries executable..
Installed rubygems 3.0.1 is newer than 2.7.8 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.6.0 - #gemset created /home/qqq/.rvm/gems/ruby-2.6.0@global
ruby-2.6.0 - #importing gemset /home/qqq/.rvm/gemsets/global.gems................................................................
ruby-2.6.0 - #generating global wrappers.......
ruby-2.6.0 - #gemset created /home/qqq/.rvm/gems/ruby-2.6.0
ruby-2.6.0 - #importing gemsetfile /home/qqq/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.6.0 - #generating default wrappers.......
ruby-2.6.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.0 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

 


网上还有使用rbenv安装ruby的(使用rbenv安装和管理Ruby版本

ruby这个东西好多地方要用,我又不会,安装高版本的ruby也是个问题,以下是参考文章和大胆尝试

有文章说(https://ruby-china.org/wiki/rvm-guide)不要以root身份运行,我管他呢,他又没说原因,第一次,随便玩玩

参考:

centos7搭建ruby环境

centos7/rhel7安装较高版本ruby2.2/2.3/2.4+

https://ruby-china.org/wiki/rvm-guide

https://rvm.io/(rvm官网)


先安装gcc环境

[root@client ~]# yum install gcc-c++

接下来rvm官网教程三步走:

获取密钥:

[root@client ~]# gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: 下载密钥‘D39DC0E3’,从 hkp 服务器 keys.gnupg.net
gpg: 下载密钥‘39499BDB’,从 hkp 服务器 keys.gnupg.net
gpg: /root/.gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 D39DC0E3:公钥“Michal Papis (RVM signing) <mpapis@gmail.com>”已导入
gpg: 密钥 39499BDB:公钥“Piotr Kuczynski <piotr.kuczynski@gmail.com>”已导入
gpg: 没有找到任何绝对信任的密钥
gpg: 合计被处理的数量:2
gpg:           已导入:2  (RSA: 2)

安装rvm

说安装目录到/usr/local/rvm/,几乎已经安装完成,首先你需要添加需要执行rvm命令的用户到rvm组,然后登出再登陆。任何人使用rvm时候umask必须为...

...(渣渣英语,不翻译了)

[root@client ~]# \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.7.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc
gpg: 于 2019年01月04日 星期五 06时01分48秒 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.7.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!
[root@client ~]# \curl -sSL https://get.rvm.io | bash -s stable

那我就按照提示走一下:

将root加入到rvm组

[root@client ~]# usermod -aG rvm root
[root@client ~]# id root
uid=0(root) gid=0(root) 组=0(root),1001(rvm)

source一下:

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

然后试用rvm list known命令。列出所有已知源

[root@client ~]# 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[.5]
[ruby-]2.5[.3]
[ruby-]2.6[.0]
......

根据网上大佬(https://ruby-china.org/wiki/rvm-guide)所说,修改ruby源加快安装速度:

由于是root安装,所以安装目录不在家目录

[root@client ~]# sed -i "s/ruby_url=https:\/\/cache.ruby-lang.org\/pub\/ruby/ruby_url=https:\/\/cache.ruby-china.com\/pub\/ruby/g"  /usr/local/rvm/config/db

或者:

echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > /usr/local/rvm/user/db

安装ruby-2.6

[root@client ~]# rvm install ruby-2.6 --disable-binary
Checking requirements for centos.
Requirements installation successful.
-bash: /usr/local/rvm/scripts/functions/manage/install/centos: 没有那个文件或目录
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.6.0, this may take a while depending on your cpu(s)...
ruby-2.6.0 - #downloading ruby-2.6.0, this may take a while depending on your connection...
** Resuming transfer from byte position 6725632
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 7676k  100 7676k    0     0  8310k      0 --:--:-- --:--:-- --:--:-- 8307k
ruby-2.6.0 - #extracting ruby-2.6.0 to /usr/local/rvm/src/ruby-2.6.0.....
ruby-2.6.0 - #configuring......................................................................
ruby-2.6.0 - #post-configuration..
ruby-2.6.0 - #compiling............................................................................................
ruby-2.6.0 - #installing................................
ruby-2.6.0 - #making binaries executable..
Installed rubygems 3.0.1 is newer than 2.7.8 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.6.0 - #gemset created /usr/local/rvm/gems/ruby-2.6.0@global
ruby-2.6.0 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................
ruby-2.6.0 - #generating global wrappers.......
ruby-2.6.0 - #gemset created /usr/local/rvm/gems/ruby-2.6.0
ruby-2.6.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.6.0 - #generating default wrappers.......
ruby-2.6.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.0 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

查询已经安装的ruby

[root@client ~]# rvm list
=> ruby-2.5.3 [ x86_64 ]
 * ruby-2.6.0 [ x86_64 ]

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

切换 Ruby 版本

[root@client ~]# rvm use ruby-2.6.0
Using /usr/local/rvm/gems/ruby-2.6.0
[root@client ~]# rvm list
   ruby-2.5.3 [ x86_64 ]
=* ruby-2.6.0 [ x86_64 ]

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

如果想设置为默认版本,这样一来以后新打开的控制台默认的 Ruby 就是这个版本

[root@client ~]# rvm use ruby-2.6.0 --default
Using /usr/local/rvm/gems/ruby-2.6.0

卸载一个已安装版本

[root@client ~]# rvm remove ruby-2.5.3
ruby-2.5.3 - #removing src/ruby-2.5.3..
ruby-2.5.3 - #removing rubies/ruby-2.5.3..
ruby-2.5.3 - #removing gems....
ruby-2.5.3 - #removing wrappers....
ruby-2.5.3 - #removing environments....
Using /usr/local/rvm/gems/ruby-2.6.0

 

 

 

 

 

 

 类似资料: