Mavericks, RBENV, Your Ruby version is 2.0.0, but

2019-01-22 04:38发布

I've read and tried the suggestions in several, other, questions, like mine (all with accepted answers) as well as a few more hours of Google searching, but nothing worked. That leads me to think my issue is something corrupt with a piece of Ruby/RBENV ecosystem on my computer or maybe a dreaded PATH issue. I always have to run sudo to install any gems, which I've never had to do before, so that's puzzling too.

Here are some outputs of files & commands I think are relevant. If you need more information, please let me know:

.zshrc

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" if which rbenv > /dev/null;
then eval "$(rbenv init - zsh)"; fi

ruby -v

ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]

rbenv local

2.1.1

Gemfile (I've also blown out my gemfile.lock several times too)

source 'https://rubygems.org'

ruby '2.1.1'

gem 'rails', '4.1.4'
... [omitted for brevity]

.ruby-version

2.1.1

echo $PATH

/[user path]/.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

I'd be grateful if anyone has any ideas about what I should try next, short of reformatting my computer.

EDIT 1: Tried option B installing both of them from their git repos below as per Ben Kreeger. type rbenv correctly returned rbenv is a shell function and the original message kept appearing. I reinstalled Mavericks and my setup still isn't working.

EDIT 2: Any time I try to install a gem, I get a Gem::FilePermissionError saying I don't have access to the Ruby 2.0.0 folder (installed as system). Going to fiddle with RBENV some more...

EDIT 3: More debugging (everything below)

Kept erroring when installing Ruby versions with RBENV and found some people mentioning readline issues.

Tried the following steps to fix readline: https://github.com/sstephenson/ruby-build/issues/550#issuecomment-40681557, and got an error that my Xcode command line tool install was bad.

Ran xcode-select --install to reinstall them.

Tried rbenv install 2.1.1 again, and got The Ruby openssl extension was not compiled. Missing the OpenSSL lib?

As per https://coderwall.com/p/n9bnug, I linked my OpenSSL extension with https://coderwall.com/p/n9bnug

Reset versions of Ruby: rbenv local 2.1.1 rbenv global 2.1.1 and rbenv rehash

Everything seems to indicate bundler is trying to use my system Ruby install (2.0.0-p247) instead of what RBENV is specifying. Baffled where the missing link is.

2条回答
来,给爷笑一个
2楼-- · 2019-01-22 05:12

WOW, JUST WOW.

All I had to do was gem install bundler and then rbenv rehash. Everything worked.

The original error message pointed me to a problem with RBENV or my Ruby version when in reality it was just falling back on an old version of bundler.

Why wouldn't I have received the more standard this needs bundler version [xxxx]... error instead of telling me my Ruby version is specified incorrectly?

查看更多
家丑人穷心不美
3楼-- · 2019-01-22 05:29

If you're having to use sudo to install gems, then something's likely wrong with your rbenv installation. I'm of the opinion that if you're on OS X and you have to run sudo to install gems or packages, you're doing it wrong (especially if you've got homebrew installed)! You've got two options —

Option A: Alter your .zshrc to be a little more friendly with your $PATH and your rbenv settings. Note here that /usr/local/bin is just being prepended to $PATH, which itself is going to set to a proper default by your system (Mavericks). Make those two lines you posted look like this:

export PATH="/usr/local/bin:$PATH"
eval "$(rbenv init -)"

Then ensure that you close any and all shells and open new ones to load the new settings. Then when you run echo $PATH it should look similar to...

[home path]/.rbenv/shims:[home path]/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Option B: Since I'm more familiar with installing rbenv via git, you may try nuking your homebrew-installed rbenv installation by brew remove rbenv, and follow the directions specified on rbenv's github page (and don't forget to install ruby-build as well). This includes removing any rbenv-specific lines in your .zshrc and setting them to what rbenv recommends.

You can always check the sanity of your rbenv installation by running type rbenv at a command prompt. If all is well, you should at least be getting back "rbenv is a function".

查看更多
登录 后发表回答