You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用rbenv升级Ruby至2.6.5后安装Rails 6.0.2.1路径异常求助

Fixing Rails Installation Not Found with rbenv

Hey there, let's troubleshoot why your Rails 6.0.2.1 install isn't being recognized even though you've installed it via gem. The core issue here is path priority conflicts between your system/brew-installed Ruby and rbenv-managed Ruby, plus your Rails gem ended up in the wrong gem directory.

Let's Break Down the Problem

From your environment info:

  • $PATH has /usr/local/opt/ruby/bin before ~/.rbenv/shims — so your system is using the brew-installed Ruby instead of the rbenv-managed 2.6.5
  • which ruby points to /usr/local/opt/ruby/bin/ruby (not rbenv's shim), which means your gem install rails command installed Rails to brew's Ruby gem directory, not rbenv's 2.6.5 directory
  • That's why ls $(rbenv prefix)/bin doesn't show rails — it's not in rbenv's bin folder

Step-by-Step Fixes

1. Fix Your PATH Priority

First, we need to make sure rbenv's shims directory takes precedence over other Ruby paths. Edit your shell configuration file (this depends on your shell: ~/.bash_profile for Bash, ~/.zshrc for Zsh):

  • Look for lines that add /usr/local/opt/ruby/bin to your PATH
  • Move the rbenv initialization code before those lines. The rbenv init line looks like this:
    eval "$(rbenv init -)"
    
  • Save the file, then restart your terminal or run source ~/.zshrc (or source ~/.bash_profile) to apply changes.

2. Ensure rbenv's Ruby 2.6.5 is Active

Set rbenv to use your 2.6.5 version globally (or locally for your project):

  • For global use:
    rbenv global 2.6.5
    
  • For a specific project directory:
    cd your-project-folder
    rbenv local 2.6.5
    

Now verify you're using rbenv's Ruby:

which ruby
# Should output: /Users/paulinedussart/.rbenv/shims/ruby

3. Uninstall and Reinstall Rails to the Correct Directory

First, remove the Rails that was installed to brew's Ruby:

gem uninstall rails -v 6.0.2.1

Then install Rails using rbenv's Ruby:

gem install rails -v 6.0.2.1
rbenv rehash

4. Clean Up Conflicting Ruby Version Managers

I noticed ~/.rvm/bin in your PATH — rvm and rbenv don't play well together. If you're not using rvm anymore, comment out any rvm-related lines in your shell config file (like [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"), then restart your terminal.

Verify the Fix

Run these commands to confirm everything works:

which rails
# Should output: /Users/paulinedussart/.rbenv/shims/rails
rails --version
# Should show: Rails 6.0.2.1

内容的提问来源于stack exchange,提问作者Pauline DUSSART

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 16:02:33