简体   繁体   English

如何在 MacOS 上使用 rbenv 设置 Ruby 的版本?

[英]How to set the version of Ruby with rbenv on MacOS?

I was trying to follow the book "Agile Web Development with Rails 5.1" (on MacOS).我试图遵循“Agile Web Development with Rails 5.1”一书(在 MacOS 上)。

I want ruby -v to be 2.4.1 .我希望ruby -v2.4.1

Currently, ruby -v says ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19] .目前, ruby -vruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]

I want to use rbenv to manage the version of Ruby installed.我想使用rbenv来管理安装的 Ruby 的版本。 So I tried rbenv install 2.4.1 then rbenv global 2.4.1 .所以我尝试rbenv install 2.4.1然后rbenv global 2.4.1 But that still did not change the output of ruby -v .但这仍然没有改变ruby -v的 output 。 What more do I have to do?我还需要做什么?

I see that which ruby returns ~/.rubies/ruby-2.6.5/bin/ruby .我看到which ruby返回~/.rubies/ruby-2.6.5/bin/ruby I can't remember how I installed that version of Ruby - it might have been homebrew.我不记得我是如何安装那个版本的 Ruby - 它可能是自制的。

Okay so可以,然后呢

brew install rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
echo 'source ~/.bashrc' >> ~/.bash_profile
rbenv install 2.4.1
rbenv global 2.4.1
rbenv rehash # This is probably what you didn't do, start a new terminal or use rehash

Then try ruby -v and which ruby然后尝试ruby -vwhich ruby

You can skip some of the beginning steps in case you have rbenv setup and everything.如果你有 rbenv 设置和一切,你可以跳过一些开始步骤。

I ended up using RVM instead.我最终改用 RVM。 I'm not sure but I might have had multiple ruby version managers installed when I asked the question.我不确定,但当我问这个问题时,我可能安装了多个 ruby 版本管理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM