簡體   English   中英

Ruby新版本如何升級不清楚

[英]Unclear on how to upgrade new version of Ruby

請參閱下面我用來升級到最新版本 Ruby 的終端命令。它在某一時刻說“ruby 3.2.0 已經安裝並且是最新的”,但是當我運行“ruby -v”時它仍然返回舊版本Ruby。我做錯了什么嗎?

➜  ~ ruby -v            
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
➜  ~ brew install ruby  
Error: 
homebrew-core is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
Warning: ruby 3.2.0 is already installed and up-to-date.
To reinstall 3.2.0, run:
brew reinstall ruby
➜  ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
➜  ~ brew reinstall ruby
==> Fetching ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.2.0
Already downloaded:                    /Users/Madeline/Library/Caches/Homebrew/downloads/c360900acacef49e831b0f640b0e175180c181ef83afbcd24d4d6609fbf146fe--ruby-3.2.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:c25553dfc94e9
Already downloaded:     /Users/Madeline/Library/Caches/Homebrew/downloads/f587974e09ec9fbb07b125260da3ce05b66e91a92ec27898f2e446b81a840b88--ruby--3.2.0.monterey.bottle.tar.gz
==> Reinstalling ruby 
==> Pouring ruby--3.2.0.monterey.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.2.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"' >> ~/.zshrc

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"

For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/ruby/3.2.0: 16,574 files, 44.8MB
==> Running `brew cleanup ruby`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
➜  ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
➜  ~ 

我希望“ruby -v”在運行命令“brew reinstall ruby”后返回最新版本 (3.2.0)。 它仍在返回舊版本。

使用 Homebrew 安裝 Ruby 時,brew 不會使安裝的版本自動成為系統上的默認 Ruby 版本,因為這會覆蓋您的操作系統可能正在使用的系統 Ruby。

安裝后的消息中對此進行了解釋:

==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.2.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"' >> ~/.zshrc

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"

For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

也就是說:當您想使用新的 Ruby 版本時,您需要按照該消息中的步驟進行操作,並且需要按照所述設置或重新配置環境變量。 完成后,您需要重新啟動終端(甚至機器)以使這些更改生效。

覆蓋系統 Ruby,並且不能在 Ruby 的不同版本之間切換,通常被視為一種不好的做法。 因此,人們通常建議使用 Ruby 版本管理器,提供更靈活。 您可能需要查看 Ruby 版本管理器,如rbenvRVMRuby asdf 版本管理器插件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2025 STACKOOM.COM