RVM (Ruby enVironment Manager)是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换。
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 91 0 0:00:02 0:00:02 --:--:-- 91
100 24535 100 24535 0 0 5397 0 0:00:04 0:00:04 --:--:-- 14914
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc',
but no GPG software exists to validate it, skipping.
Installing RVM to /Users/x x x/.rvm/
Adding rvm PATH line to /Users/username/.profile /Users/username/.mkshrc /Users/username/.bashrc /Users/username/.zshrc.
/Users/username/.rvm/src/rvm/scripts/functions/installer: line 1103: /Users/username/.zshrc: Is a directory
Adding rvm loading line to /Users/username/.profile /Users/username/.bash_profile /Users/username/.zlogin.
Installation of RVM in /Users/username/.rvm/ is almost complete:
* To start using RVM you need to run `source /Users/username/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM
Please consider donating to our open collective to help us maintain RVM.
Donate: https://opencollective.com/rvm/donate
等待一段时间后就可以成功安装好 RVM。
然后,载入 RVM 环境(新开 Termal 就不用这么做了,会自动重新载入的)
source ~/.rvm/scripts/rvm
检查一下是否安装正确
rvm -v
类似输出:
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
查看RVM帮助命令:
rvm help
查询已经安装的ruby
rvm list
列出已知的ruby版本
rvm list known
可以选择现有的rvm版本来进行安装
rvm install 2.6.6
会提示输入密码,同样继续等待漫长的下载,编译过程,完成以后,Ruby, Ruby Gems 就安装好了。
RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本
rvm use 2.6.6 --default
同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本
这个时候你可以测试是否正确
ruby -v
gem -v
这有可能是因为Ruby的默认源使用的是cocoapods.org,国内访问这个网址有时候会有问题,网上的一种解决方案是将远替换成淘宝的,替换方式如下:
gem source -r https://rubygems.org/
gem source -a https://ruby.taobao.org
要想验证是否替换成功了,可以执行:
gem sources -l
正常的输出结果:
CURRENT SOURCES
http://ruby.taobao.org/