Ruby版本和项目不匹配

时间:2017-07-31 15:04:10

标签: ruby sinatra bundler rbenv

当我跑步时,bundle我看到以下内容:

Your Ruby version is 2.5.0, but your Gemfile specified
2.4.0.pre.dev

我的Gemfile看起来像:

source 'https://rubygems.org'
ruby '2.4.0-dev'
gem 'sinatra', :github => 'sinatra/sinatra'

这是我的gem env

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.12
  - RUBY VERSION: 2.5.0 (2017-07-31 patchlevel -1) [x86_64-darwin16]
  - INSTALLATION DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /Users/johndoe/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /Users/johndoe/.rbenv/versions/2.4.0-dev/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/bin
  - SPEC CACHE DIRECTORY: /Users/johndoe/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-16
  - GEM PATHS:
     - /Users/johndoe/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.5.0
     - /Users/johndoe/.gem/ruby/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "-n/usr/local/bin"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/johndoe/.rbenv/versions/2.4.0-dev/bin
     - /Users/johndoe/.rbenv/libexec
     - /Users/johndoe/.nvm/versions/node/v8.1.4/bin
     - /usr/local/sbin
     - /Library/Frameworks/Python.framework/Versions/3.4/bin
     - /Users/johndoe/.rbenv/shims
     - /Users/johndoe/google-cloud-sdk/bin
     - /Users/johndoe/Library/Python/2.7/bin
     - /Users/johndoe/.rbenv/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin

当我输入rbenv verions时,这就是我所看到的:

system
  2.0.0-p247
  2.3.1
* 2.4.0-dev (set by /Users/johndoe/code/projects/blog-server/.ruby-version)

使用Rbenv我指定了我想要的ruby版本,并且我在我的项目的Gemfile中匹配它。但是,每当我运行bundlebundle exec gem uninstall sinatra时,我都会看到有关我的ruby版本和我的gemfile ruby​​版本不匹配的上述错误消息。我也看到我的Ruby版本是2.5.0,我不知道它是如何设置的。有人可以帮我解决这个错误吗?

Your Ruby version is 2.5.0, but your Gemfile specified
2.4.0.pre.dev

在我的bash个人资料中,我有:

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

简而言之,我只想让运行我的ruby进程的shell为我的博客项目使用ruby版本2.4.0-dev,我很难理解是什么阻止了我以及如何解决它。

更新:

我也注意到一些奇怪的事情。我的捆绑版本继续指向ruby 2.5.0p-1

## Environment


Bundler   1.15.3
Rubygems  2.6.12
Ruby      2.5.0p-1 (2017-07-31 revision 59454) [x86_64-darwin16]
Git       2.11.0
Platform  x86_64-darwin-16
OpenSSL   OpenSSL 1.0.2k  26 Jan 2017
```

## Gemfile

### Gemfile

```ruby
source 'https://rubygems.org'
ruby '2.4.0-dev'
gem 'sinatra', '2.0.0'
```

### Gemfile.lock

```
<No /Users/johndoe/code/projects/blog-server/Gemfile.lock found>

2 个答案:

答案 0 :(得分:0)

在项目文件夹中运行:

rbenv local 2.4.0-dev

它应该做的伎俩。您只需为此特定项目指定 local ruby​​版本。您的全局版本设置为2.5.0

答案 1 :(得分:-2)

我认为,最好的选择是安装Ruby Version Manager(rvm)。

RVM通过完全按照您的需要帮助每个ruby开发人员;根据需要自动管理ruby版本。

这是链接,希望它有所帮助;

https://rvm.io/

干杯