rbenv - Ruby - 如何在多个项目之间切换 ruby 版本

rbenv - Ruby - How to switch ruby versions between multiple projects

我使用 rbenv 安装了 Ruby。我正在使用 Mac。对于我的一个项目,我使用 ruby 2.6.3。对于我的其他项目,我需要 ruby 2.7.4。所以我安装了这两个版本。

在我的第一个项目中,如果我使用 rbenv 版本,它会正确显示

   system
   * 2.6.3 (set by /Users/suganyas/academics/project1/.ruby-version)
    2.7.4

对于我的第二个项目,我使用命令

设置了ruby版本2.7.4
rbenv local 2.7.4

因此,如果我从我的第二个项目中执行 rbenv 版本,它再次显示,

  system
  2.6.3
  * 2.7.4 (set by /Users/suganyas/project2/ceep/.ruby-version)

但是当我进行捆绑安装时,出现以下错误

  Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4

这里有完整的跟踪

    The git source `git://github.com/sqlninja/outdatedbrowser_rails.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
   The git source `git://github.com/nhodges/phantomjs-gem.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
    The git source `git://github.com/heapsource/active_model_otp.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
  Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4

请帮助我我做错了什么。

运行 下面的命令帮助我选择了正确的 rbenv 本地版本

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile