使用 rvm 无法在此 ruby​​/rails 版本中找到 sqlite3

使用 rvm 无法在此 ruby​​/rails 版本中找到 sqlite3

我安装了 rvm,并使用 1.9.2 和 rails 3.05。我能够创建一个新应用程序,但是一旦我进入目录并尝试启动服务器(“rails s”),我就会收到此错误消息

Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.

我按照说明执行了“捆绑安装”,它进行了一些提取,然后似乎遇到了更多问题。见下文。请注意,当我在 mac os 上使用默认 ruby​​/rails 时,我可以启动服务器。这只是我使用在 rvm 中创建的版本时遇到的问题?

Fetching source index for http://rubygems.org/
Using rake (0.9.2) 
Using abstract (1.0.0) 
Using activesupport (3.0.5) 
Using builder (2.1.2) 
Using i18n (0.6.0) 
Using activemodel (3.0.5) 
Using erubis (2.6.6) 
Using rack (1.2.4) 
Using rack-mount (0.6.14) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.29) 
Using actionpack (3.0.5) 
Using mime-types (1.16) 
Using polyglot (0.3.2) 
Using treetop (1.4.10) 
Using mail (2.2.19) 
Using actionmailer (3.0.5) 
Using arel (2.0.10) 
Using activerecord (3.0.5) 
Using activeresource (3.0.5) 
Using bundler (1.0.18) 
Using thor (0.14.6) 
Using railties (3.0.5) 
Using rails (3.0.5) 
/Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_input.rb:122:in `initialize': no metadata found in /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/cache/sqlite3-1.3.4.gem (Gem::Package::FormatError)
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_input.rb:20:in `new'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_input.rb:20:in `open'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/package.rb:44:in `open'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/format.rb:62:in `from_io'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/format.rb:46:in `block in from_file_by_path'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/open-uri.rb:35:in `open'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/open-uri.rb:35:in `open'
    from /Users/michaeljohnmitchell/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/format.rb:45:in `from_file_by_path'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/rubygems_integration.rb:100:in `spec_from_gem'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/source.rb:77:in `fetch'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/installer.rb:50:in `block in run'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/installer.rb:49:in `run'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/installer.rb:8:in `install'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/cli.rb:220:in `install'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/vendor/thor.rb:263:in `dispatch'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/vendor/thor/base.rb:386:in `start'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/bin/bundle:13:in `<top (required)>'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/bin/bundle:19:in `load'
    from /Users/michaeljohnmitchell/.rvm/gems/ruby-1.9.2-p290/bin/bundle:19:in `<main>'
Michael-Mitchells-MacBook-Pro:demo michaeljohnmitchell$ rails s

答案1

当通过 bundler 或直接通过 ruby​​gems 安装不同版本的 gem 时,也会安装可执行脚本(例如 rails、rake,讽刺的是,)。在使用不同的 bundles 时,运行这些脚本的正确版本是不可能的,所以 bundler 提出的解决方案是在命令前加上bundle exec,这将导致它们在 bundle 的上下文中运行并从 Gemfile 启动正确的版本:

bundle exec rails s

另一个选择是告诉 bundler 将这些脚本安装在一个目录中,以便您可以从那里调用它们:

bundle install --binstubs
# same as:
bundle install --binstubs=./bin

我认为更安全的选择是使用bundle exec,您可以使用 shell 别名来缩短它,因为每次输入都会很烦人。

相关内容