在我的 MacOS 10.15.7 上升级 ruby 2.6 时遇到问题
trouble upgrading ruby 2.6 on my MacOS 10.15.7
最终我尝试安装 Cocoapods 时出现错误:
构建本机扩展错误:安装 cocoapods 时出错错误:构建失败 gem 本机扩展
..我认为是因为 ruby 不是最新的(停留在 2.6)。
我试过了
酿造安装 ruby
和
酿造重新安装 ruby
...仍为 v2.6
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$ brew install ruby
Updating Homebrew...
Warning: ruby 3.0.1 is already installed and up-to-date.
To reinstall 3.0.1, run:
brew reinstall ruby
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$ brew reinstall ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.0.1
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/6d2a0e9cda0072647ac4fcb119f4f0263b91503dc918ba80d057da0897a3f994--ruby-3.0.1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:1af6edba23ff9aa12fcab0fee9246cf46110263bf962e46e800152096b0c7017
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/7d7455d376fe2f0401873034dc82e6daae1f05efe465847b4db1464a73155c8f--ruby--3.0.1.catalina.bottle.tar.gz
==> Reinstalling ruby
==> Pouring ruby--3.0.1.catalina.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.0.0/bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.profile
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
==> Summary
/usr/local/Cellar/ruby/3.0.1: 16,358 files, 38.4MB
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$
我尝试重新启动 Mac。还是2.y
在 mac 上使用 ruby 的最佳方法是使用 ruby 版本管理器。我使用 rbenv。它允许您轻松地在不同 ruby 版本之间切换并且不会引起冲突。
安装运行brew install rbenv ruby-build
然后 echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
最后 source ~/.bash_profile
现在输入 rbenv install 3.0.0
安装任何 ruby 例如 3.0.0
并全局设置
rbenv global 3.0.0
编辑:如果您使用不同的 shell,这可能不起作用。通过 运行ning echo $SHELL
检查 shell 是你的默认设置
如果你的默认 shell 是 zsh,那么代替你的第二步和第三步 运行:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc
最终我尝试安装 Cocoapods 时出现错误: 构建本机扩展错误:安装 cocoapods 时出错错误:构建失败 gem 本机扩展
..我认为是因为 ruby 不是最新的(停留在 2.6)。
我试过了 酿造安装 ruby 和 酿造重新安装 ruby ...仍为 v2.6
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$ brew install ruby
Updating Homebrew...
Warning: ruby 3.0.1 is already installed and up-to-date.
To reinstall 3.0.1, run:
brew reinstall ruby
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$ brew reinstall ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.0.1
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/6d2a0e9cda0072647ac4fcb119f4f0263b91503dc918ba80d057da0897a3f994--ruby-3.0.1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:1af6edba23ff9aa12fcab0fee9246cf46110263bf962e46e800152096b0c7017
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/7d7455d376fe2f0401873034dc82e6daae1f05efe465847b4db1464a73155c8f--ruby--3.0.1.catalina.bottle.tar.gz
==> Reinstalling ruby
==> Pouring ruby--3.0.1.catalina.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.0.0/bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.profile
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
==> Summary
/usr/local/Cellar/ruby/3.0.1: 16,358 files, 38.4MB
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$
我尝试重新启动 Mac。还是2.y
在 mac 上使用 ruby 的最佳方法是使用 ruby 版本管理器。我使用 rbenv。它允许您轻松地在不同 ruby 版本之间切换并且不会引起冲突。
安装运行brew install rbenv ruby-build
然后 echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
最后 source ~/.bash_profile
现在输入 rbenv install 3.0.0
安装任何 ruby 例如 3.0.0
并全局设置
rbenv global 3.0.0
编辑:如果您使用不同的 shell,这可能不起作用。通过 运行ning echo $SHELL
如果你的默认 shell 是 zsh,那么代替你的第二步和第三步 运行:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc