參考:
https://blog.csdn.net/qq_35641923/article/details/86493822
https://www.runoob.com/ruby/ruby-installation-unix.html
rvm可以用rbenv代替
報錯1:需要添加本地域名hosts解析
[root@centos7 ~]# curl -L get.rvm.io | bash -s stable
curl: (7) Failed connect to raw.githubusercontent.com:443; Connection refused #報錯
[root@centos7 ~]# 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 103 0 0:00:01 0:00:01 --:--:-- 103
curl: (7) Failed connect to raw.githubusercontent.com:443; Connection refused
解決方法
vim /etc/hosts
加入下面的配置
199.232.28.133 raw.githubusercontent.com
參考下面的連接解決
https://www.jianshu.com/p/c2e829027b0a
報錯2 沒有公鑰
gpg: Can't check signature: 沒有公鑰
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.11.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.11/1.29.11.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
In case of further problems with validation please refer to https://rvm.io/rvm/security
解決方法:
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
或者
gpg --keyserver keyserver.ubuntu.com --recv-key 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
報錯3:如果提示
gpg: failed to start the dirmngr '/usr/bin/dirmngr': 沒有那個文件或目錄
這是缺少dirmngr命令,直接apt裝一下就行
$ sudo apt install -y dirmngr
再執行下面的curl操作成功了,呵呵
[root@centos7 ~]# 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 329 0 --:--:-- --:--:-- --:--:-- 329
100 24535 100 24535 0 0 4868 0 0:00:05 0:00:05 --:--:-- 7904
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 <piotr.kuczynski@gmail.com>"
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
[root@centos7 ~]# source /etc/profile.d/rvm.sh
[root@centos7 ~]# rvm reload
[root@centos7 ~]# rvm -v
rvm 1.29.10 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
到此rvm安裝成功
安裝依賴
rvm安裝完畢之后,就是ruby的下載安裝了
但是在此之前需要安裝一下ruby的依賴包,諸如openssl之類的,否則以后會出現各種問題,重新安裝也是大麻煩
rvm requirements
輸入一下命令檢查安裝情況
rvm requirements run
將顯示:
Checking requirements for centos.
Requirements installation successful.
列出已知的 ruby 版本:
$ rvm list known
最后便可安裝ruby了,當然版本可以任選,反正我選2.3.8
rvm install 2.3.8
或者
rvm install 3.0.0
檢查安裝情況
顯示如下信息則 安裝完成:下面顯示本人已經成功安裝了兩個版本的ruby,並且當前默認使用的是3.0版本 。呵呵
root@haima-PC:/home/haima/Desktop# rvm list
* ruby-2.3.8 [ x86_64 ]
=> ruby-3.0.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
切換默認運行的ruby版本
rvm use 2.3.8 --default
use了某個版本之后,可以使用 which ruby 命令查看當前的ruby命令信息。
如果報下面的錯誤:
rvm is not a function的解決方法
haima@haima-PC:/usr/local$ rvm use 2.3.8 --default
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
編輯~/.bashrc
haima@haima-PC:/usr/local$ vim ~/.bashrc
加入下面的代碼
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
再執行
haima@haima-PC:/usr/local$ rvm use 2.3.8 --default
Using /home/haima/.rvm/gems/ruby-2.3.8
haima@haima-PC:/usr/local$ rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
haima@haima-PC:/usr/local$ ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
請參考
https://blog.csdn.net/dazhi_100/article/details/38845689
刪除一個已安裝的版本:
$ rvm remove 2.3.8
gemset 的使用
列出當前 Ruby 的 gemset
root@haima-PC:/home/haima/Desktop# rvm gemset list
gemsets for ruby-3.0.0 (found in /home/haima/.rvm/gems/ruby-3.0.0)
=> (default)
global
進入ruby控制台
irb
更多參考:
https://blog.csdn.net/u010744827/article/details/84269612
https://ruby-china.org/wiki/rvm-guide
http://www.zzvips.com/article/62805.html