为什么bundler使用旧版本的ruby,而不是识别已安装的新宝石?

时间:2013-05-24 04:40:23

标签: ruby rvm bundler rubymine

在我的Heroku / Sinatra应用程序中,我使用Ruby 1.8.7设置我的gemfile,然后使用RVM将我的默认值设置为2.0.0。现在,当我尝试安装任何新的宝石时,如Sinatra-flash或Pony,当我在main.rb文件中需要它时,无法识别或找到宝石。

当我在我的gemfile中添加gem“pony”时,我收到一条弹出消息:

Gem 'pony' is not available in SDK 'ruby-1.8.7-p385' 

即使我已安装它。当我在终端中输入gem list时,它会返回我安装的所有未被识别为已安装在我的程序中的宝石。

如果我在main.rb中添加require 'sinatra/flash'require 'pony',我会收到一条消息:

no such file to load

我真的很感激这方面的任何帮助,这让我疯狂。

编辑:

使用命令sudo gem install 'gemname'

当我输入rvm info时,我会回来

ruby :
    interpreter:  "ruby"
    version:      "2.0.0p195"
    date:         "2013-05-14"
    platform:     "x86_64-darwin12.3.0"
    patchlevel:   "2013-05-14 revision 40734"
    full_version: "ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]"

  homes:
    gem:          "/Users/adam419/.rvm/gems/ruby-2.0.0-p195"
    ruby:         "/Users/adam419/.rvm/rubies/ruby-2.0.0-p195"

  binaries:
    ruby:         "/Users/adam419/.rvm/rubies/ruby-2.0.0-p195/bin/ruby"
    irb:          "/Users/adam419/.rvm/rubies/ruby-2.0.0-p195/bin/irb"
    gem:          "/Users/adam419/.rvm/rubies/ruby-2.0.0-p195/bin/gem"
    rake:         "/Users/adam419/.rvm/gems/ruby-2.0.0-p195@global/bin/rake"

  environment:
    PATH:         "/Users/adam419/.rvm/gems/ruby-2.0.0-p195/bin:/Users/adam419/.rvm/gems/ruby-2.0.0-p195@global/bin:/Users/adam419/.rvm/rubies/ruby-2.0.0-p195/bin:/Users/adam419/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/git/bin/[["
    GEM_HOME:     "/Users/adam419/.rvm/gems/ruby-2.0.0-p195"
    GEM_PATH:     "/Users/adam419/.rvm/gems/ruby-2.0.0-p195:/Users/adam419/.rvm/gems/ruby-2.0.0-p195@global"
    MY_RUBY_HOME: "/Users/adam419/.rvm/rubies/ruby-2.0.0-p195"
    IRBRC:        "/Users/adam419/.rvm/rubies/ruby-2.0.0-p195/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

编辑:输入'rvm use ruby​​-2.0.0'然后'bundle install'

我明白了;

Adams-MacBook-Pro:songs adam419$ rvm use ruby-2.0.0
Using /Users/adam419/.rvm/gems/ruby-2.0.0-p195
Adams-MacBook-Pro:songs adam419$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Could not find gem 'sinatra/flash (>= 0) ruby' in the gems available on this machine.

从gem“sinatra / flash”更改为gem“sinatra-flash”然后运行bundle install

Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Enter your password to install the bundled RubyGems to your system: 
Using addressable (2.2.8) 
Installing daemons (1.1.9) 
Using data_objects (0.10.12) 
Using dm-core (1.2.0) 
Using dm-do-adapter (1.2.0) 
Installing dm-migrations (1.2.0) 
Using do_sqlite3 (0.10.12) 
Using dm-sqlite-adapter (1.2.0) 
Installing eventmachine (1.0.3) 
Using rack (1.5.2) 
Using rack-protection (1.5.0) 
Using sass (3.2.9) 
Using tilt (1.4.1) 
Using sinatra (1.4.2) 
Using sinatra-flash (0.3.0) 
Installing temple (0.6.5) 
Installing slim (1.3.9) 
Installing thin (1.5.1) 
Using bundler (1.3.5) 
Your bundle is complete!
Gems in the group production were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

当前Gemfile

source 'https://rubygems.org'
gem "sinatra"
gem "slim"
gem "sass"
gem "dm-core"
gem "sinatra-flash"
gem "dm-migrations"
gem "thin"
gem "pg", :group => :production
gem "dm-postgres-adapter", :group => :production
gem "dm-sqlite-adapter", :group => :development

Gemlock文件依赖项

DEPENDENCIES
  dm-core
  dm-migrations
  dm-postgres-adapter
  dm-sqlite-adapter
  pg
  sass
  sinatra
  sinatra-flash
  slim
  thin

2 个答案:

答案 0 :(得分:1)

通过使用sudo gem install pony,您将触发与RVM版本不同的系统Ruby安装。不要使用sudo。只需确保已加载RVM,然后使用正确版本的ruby:

rvm use ruby-2.0.0

然后运行bundler:

bundle install

这应该为您提供完整的环境。

答案 1 :(得分:0)

我有同样的问题,我删除了我的rubymine .idea文件,现在它正常工作。