mac上ruby版本的奇怪问题

zmeyuzjn  于 2023-03-08  发布在  Ruby
关注(0)|答案(4)|浏览(160)

我正在尝试创建一个Rails应用程序,失败如下:

$ rails new blog

    Rails 6 requires Ruby 2.5.0 or newer.

    You're running:
      ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

    Please upgrade to Ruby 2.5.0 or newer to continue.

但是,根据我的系统,我的ruby版本是2.6.3:

$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

$ which ruby
/Users/flaab/.rbenv/shims/ruby

Rbenv已激活2.6.5。

$ rbenv versions
  system
* 2.6.5 (set by /Users/flaab/.ruby-version)
  mruby-dev

但它也认识到了错误的一方。

$ which -a ruby
/Users/flaab/.rbenv/shims/ruby
/usr/bin/ruby

我的宝石环境是...

flaab@MBP-de-Arturo ~ $ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.3
  - RUBY VERSION: 2.6.5 (2019-10-01 patchlevel 114) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Users/flaab/.gem
  - USER INSTALLATION DIRECTORY: /Users/flaab/.gem/ruby/2.6.0
  - RUBY EXECUTABLE: /Users/flaab/.rbenv/versions/2.6.5/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /Users/flaab/.gem/bin
  - SPEC CACHE DIRECTORY: /Users/flaab/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/flaab/.rbenv/versions/2.6.5/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-18
  - GEM PATHS:
     - /Users/flaab/.gem
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "echo \"gem" => "--no-document\" > ~/.gemrc"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/flaab/.rbenv/versions/2.6.5/bin
     - /opt/local/libexec/rbenv
     - /Users/flaab/.rbenv/shims
     - /usr/local/bin
     - /opt/local/bin
     - /opt/local/sbin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Users/flaab/bin
     - /Users/flaab/.rbenv/shims
     - /sw/bin
     - /Users/flaab/.local/lib/npm/bin
     - /Users/flaab/.composer/vendor/bin

我怎样才能让gem使用上面提到的ruby 2. 6. 5版本?
先谢了

vsdwdz23

vsdwdz231#

无济于事。抛弃了mac,回到debian上开发。没有问题。

zbsbpyhn

zbsbpyhn2#

运行rbenv global 2.5.0设置全局ruby,或者在app目录中创建一个.ruby-version文件,指示rbenv使用特定版本。
echo "2.5.0" >> .ruby-version,然后重试。
文件

cvxl0en2

cvxl0en23#

您是否已将此添加到.bash_profile中?

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

如果没有将以上行添加到文件底部,则关闭并重新启动终端。
EXECUTABLE DIRECTORY可能设置不正确。请尝试以下命令:

rbenv shell 2.6.5

此外,确保您位于新的空目录中,并执行以下操作

rbenv local 2.6.5

然后重试rails命令

rails new blog
cld4siwp

cld4siwp4#

使用howebrew重新安装,请按照以下步骤操作:

  • 安装自制程序:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 使用自制程序安装您的ruby版本:
brew install ruby@2.6
  • 将2.6设置为默认版本:
export PATH="/usr/local/opt/ruby@2.6/bin:$PATH"
  • 重新启动shell并根据您拥有的shell运行以下命令:
source ~/.bash_profile

source ~/.zshrc
  • 验证它是否与以下各项配合使用:
ruby -v

相关问题