解决安装 RVM 遇到的问题

Ruby 版本管理器 (RVM)
RVM 是一个命令行工具,可让您轻松安装、管理和使用从解释器到 gems 的多个 ruby 环境。

我基本上不做 Ruby 开发,但是很多开发都依赖 Ruby 开发的工具或包,比如 Cocoapods、Sass 等。RubyGems 是 Ruby 的包管理器,我们可以通过它安装这些工具或包。

CocoaPods 是 Swift 和 Objective-C Cocoa 项目的依赖管理器。它拥有超过 87,000 个库,并在超过 300 万个应用程序中使用。CocoaPods 可以帮助您优雅地扩展您的项目。

Sass 是世界上最成熟、最稳定、最强大的专业级 CSS扩展语言。

我写的这篇文章 Error installing cocoapods: cocoapods-core requires Ruby version >= 2.6. The current ruby version is 2.5.8.224. - 干志雄的博客,就是因为 Ruby 版本过低导致不能安装最新的 Cocoapods,因此我需要更新 Ruby,macOS 自带的 Ruby 可以通过 Brew 来更新,如果你想管理多个版本的 Ruby,就可以通过 RVM。因为我担心直接更新系统自带的 Ruby 会影响到现有环境,所以我用 RVM 来管理。

安装 RVM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 获取当前系统使用的 ruby 版本。
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
# 检测是否安装 RVM,RVM 是安装和管理 ruby 的工具。
$ rvm
zsh: command not found: rvm
# Install RVM stable with ruby:
# 命令来源 [RVM: Ruby Version Manager - Installing RVM](https://rvm.io/rvm/install#1-download-and-run-the-rvm-installation-script)。
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
# 失败提示 port 443: Connection refused,有如下解决办法:
# 1. 科学上网。
# 2. 设置DNS为114.114.114.114或者8.8.8.8。
# 3. 替代镜像,比如中科大镜像$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)。
# 4. 在 https://www.ipaddress.com/ 查询 http://raw.githubusercontent.com 的真实IP,然后修改 hosts。
# 这里我是使用科学上网,先验证终端能否访问 Google。
$ curl google.com
^C
# 发现不行,然后执行终端代理命令,我这条命令来自 ClashX。
$ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
# 再次验证终端能否访问 Google。
$ curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
# 执行安装 RVM stable 的命令。
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby
curl: (22) The requested URL returned error: 403
WARN: ...the preceeding error with code 22 occurred while fetching https://api.github.com/repos/rvm/rvm/tags
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/ganzhixiong/.rvm/
Adding rvm PATH line to /Users/ganzhixiong/.profile /Users/ganzhixiong/.mkshrc /Users/ganzhixiong/.bashrc /Users/ganzhixiong/.zshrc.
Adding rvm loading line to /Users/ganzhixiong/.profile /Users/ganzhixiong/.bash_profile /Users/ganzhixiong/.zlogin.
Installation of RVM in /Users/ganzhixiong/.rvm/ is almost complete:

* To start using RVM you need to run `source /Users/ganzhixiong/.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


Ruby enVironment Manager 1.29.12 (latest) (c) 2009-2020 Michal Papis, Piotr Kuczynski, Wayne E. Seguin

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/11.6/x86_64/ruby-3.0.0.tar.bz2
Checking requirements for osx.
About to install Homebrew in the default location `/usr/local`.

It is possible to select a custom location, however it is not recommended and some things might not work.
You should do it only if you do not have write rights to `/usr/local`.

Press ENTER to install Homebrew in the default location `/usr/local`
or type a custom path (needs to be writable for the current user)
: Requirements installation failed with status: 1.
# Requirements installation failed with status: 1. 安装失败。
# 然后又在 [RVM: Ruby Version Manager - Installing RVM](https://rvm.io/rvm/install#1-download-and-run-the-rvm-installation-script) 找到如下命令,
# Installing the stable release version:(该命令只是少了最后的 --ruby,就是不使用 ruby 安装 RVM。)
$ \curl -sSL https://get.rvm.io | bash -s stable

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.
Upgrading the RVM installation in /Users/ganzhixiong/.rvm/
RVM PATH line found in /Users/ganzhixiong/.mkshrc /Users/ganzhixiong/.profile /Users/ganzhixiong/.bashrc /Users/ganzhixiong/.zshrc.
RVM sourcing line found in /Users/ganzhixiong/.profile /Users/ganzhixiong/.bash_profile /Users/ganzhixiong/.zlogin.
Upgrade of RVM in /Users/ganzhixiong/.rvm/ is complete.

Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

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

# 看提示就是安装 RVM 成功了。
$ rvm -v
zsh: command not found: rvm
$ source ~/.bash_profile
$ rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

用 RVM 安装 Ruby

Error running ‘__rvm_make -j10’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ rvm install 3.0.0                                                                                       

ruby-3.0.0 - #removing src/ruby-3.0.0 - please wait
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/12.6/arm64/ruby-3.0.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/opt/homebrew/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/gan/.rvm/rubies/ruby-3.0.0, this may take a while depending on your cpu(s)...
ruby-3.0.0 - #downloading ruby-3.0.0, this may take a while depending on your connection...
ruby-3.0.0 - #extracting ruby-3.0.0 to /Users/gan/.rvm/src/ruby-3.0.0 - please wait
ruby-3.0.0 - #configuring - please wait
ruby-3.0.0 - #post-configuration - please wait
ruby-3.0.0 - #compiling - please wait
Error running '__rvm_make -j10',
please read /Users/gan/.rvm/log/1691140731_ruby-3.0.0/make.log

There has been an error while running make. Halting the installation.

使用下面命令解决:

1
2
3
4
$ rvm install 2.7.7 --with-openssl-dir=$HOME/.rvm/usr/include/ --force

# 但是安装 3.2.2 还是报同样的错误。
$ rvm install 3.2.2 --with-openssl-dir=$HOME/.rvm/usr/include/ --force

RVM is not a function

我错误地认为我需要的只是将 rvm 包含在 my.bashrc.zshrc. 但这并不能真正解决错误。

1
export PATH="$PATH:$HOME/.rvm/bin"

在StackOverflow上找到了我的 Linux VM 上的解决方案:

您需要运行以下命令

1
$ source ~/.rvm/scripts/rvm

然后运行这个

1
$ type rvm | head -n 1

因为我的结果是

1
rvm is a shell function from /home/sun/.rvm/scripts/cli

我又可以使用 RVM 了!

相关教程

RVM 实用指南 · Ruby China

版本管理工具及 Ruby 工具链环境 - 掘金

解决安装 RVM 遇到的问题

https://ganzhixiong.com/p/31d0a24d/

Author

干志雄

Posted on

2022-01-06

Updated on

2022-01-06

Licensed under

Comments