简体   繁体   English

Ruby版本遇到问题-rbenv

[英]Having trouble with Ruby versions - rbenv

I recently updated my computer to Mac OS X El Capitan and had to reinstall homebrew and rbenv. 我最近将计算机更新为Mac OS X El Capitan,不得不重新安装homebrew和rbenv。

When I go to bundle install in one of my rails app and run bundle install I get: "Your Ruby version is 2.0.0, but your Gemfile specified 2.2.0". 当我在其中一个rails应用程序中进行捆绑安装并运行捆绑安装时,我得到:“您的Ruby版本是2.0.0,但是您的Gemfile指定了2.2.0”。

However, when I do ruby-v I get: ruby 2.2.0p0 . 但是,当我执行ruby-v时,我得到:ruby 2.2.0p0。 Why am I seeing two different versions and how can I change it? 为什么会看到两个不同的版本,我该如何更改?

rbenv -h will tell you what to do. rbenv -h会告诉您该怎么做。

"rbenv versions" List all Ruby versions available to rbenv “ rbenv版本”列出了rbenv可用的所有Ruby版本

"rbenv global" Set or show the global Ruby version “ rbenv global”设置或显示全局Ruby版本

"rbenv local" Set or show the local application-specific Ruby version “ rbenv local”设置或显示本地特定于应用程序的Ruby版本

to set, just do "rbenv local 2.2.0" or "rbenv global 2.2.0" 设置,只需执行“ rbenv local 2.2.0”或“ rbenv global 2.2.0”

Also, there is the .ruby-version file that can also set ruby version. 另外,还有.ruby-version文件,它也可以设置ruby版本。

Look at the instructions from rbenv main github page for more info. 查看rbenv主页github页面上的说明以获取更多信息。 They do a pretty good job describing how to set the active ruby version. 他们在描述如何设置活动红宝石版本方面做得很好。 https://github.com/sstephenson/rbenv https://github.com/sstephenson/rbenv

It seems that you must update your executables ( bundle install ), try this rbenv rehash . 看来您必须更新可执行文件( bundle install ),然后尝试执行此rbenv rehash Take from here 这里

rbenv rehash Installs shims for all Ruby executables known to rbenv (ie, ~/.rbenv/versions/ /bin/ ). rbenv rehash为rbenv已知的所有Ruby可执行文件(例如〜/ .rbenv / versions / / bin / )安装垫片。 Run this command after you install a new version of Ruby, or install a gem that provides commands. 在安装新版本的Ruby或安装提供命令的gem后,请运行此命令。

This is a duplicate of another question and you can find the answer here https://stackoverflow.com/a/53849574/3182171 这是另一个问题的重复,您可以在这里找到答案https://stackoverflow.com/a/53849574/3182171

For convenience I report also here. 为了方便起见,我也在这里报告。

Try with this. 试试这个。

In your rails project folder check the presence of .ruby-version file and put inside the same ruby version specified into Gemfile. 在rails项目文件夹中,检查.ruby-version文件是否存在,并将其放置在Gemfile中指定的相同红宝石版本中。 (if this file is not present, create it.) (如果此文件不存在,请创建它。)

~/your-rails-project/.ruby-version file: 〜/ your-rails-project / .ruby-version文件:

2.2.0

~/your-rails-project/Gemfile file: 〜/ your-rails-project / Gemfile文件:

source 'https://rubygems.org'
ruby '2.2.0'
...

Then install that version with rbenv: 然后使用rbenv安装该版本:

$ rbenv install 2.2.0
$ rbenv rehash
$ rbenv local 2.2.0
$ rbenv global 2.2.0

Now check that you are using the right version with: 现在检查您使用的版本是否正确:

$ ruby -v

You can now execute 您现在可以执行

$ bundle install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM