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

问题描述 投票:0回答:2

我使用 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

请帮助我我做错了什么。

ruby bundler rbenv
2个回答
0
投票

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

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

0
投票

就我而言,我无法更改 ruby 版本,因为我有

export RUBY_HOME=$HOME/.rbenv/versions/3.3.0
export PATH=$RUBY_HOME/bin:$PATH

在我的

~/.bashrc
。去掉之后就起作用了。即使在
eval "$(rbenv init - bash)"
文件中添加
~/.bash_profile
后它也不起作用。我正在使用索诺玛。

© www.soinside.com 2019 - 2024. All rights reserved.