由於在安裝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) <mpapis@gmail.com>" imported gpg: key D39DC0E3: public key "Totally Legit Signing Key <mallory@example.org>" 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) <mpapis@gmail.com>" not changed gpg: key 39499BDB: "Piotr Kuczynski <piotr.kuczynski@gmail.com>" 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 <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
安裝完成后,會列出一些安裝信息,其中有一行要注意:
... 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]#