Rails:“bundle install”由于旧的 rails 版本(3.2)而失败

Posted

技术标签:

【中文标题】Rails:“bundle install”由于旧的 rails 版本(3.2)而失败【英文标题】:Rails: "bundle install" failed because of old rails version(3.2) 【发布时间】:2019-07-24 01:41:56 【问题描述】:

我最近有一个旧的 Rails 应用程序并尝试通过 bundle install 安装 gems。但它一直在提醒我:

Bundler 找不到 gem "bundler" 的兼容版本:在 Gemfile:rails (~> 3.2) 中被解析为 3.2.22.5,这取决于 bundler (~> 1.0)

经过一些谷歌搜索,我知道 Rails 3.2 将捆绑器版本冻结为 1.0。所以我通过执行 `gem uninstall bundler -v 2.0.1and install bundler 1.0.10gem install bundler -v 1.0.10``` 卸载了我当前的捆绑程序(2.0.1),但出现另一个错误:

/home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler/shared_helpers.rb:3:in <top (required)>': undefined methodsource_index ' 对于 Gem:Module (NoMethodError) 你的意思是?来源 来自 /home/alec/.rbenv/versions/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /home/alec/.rbenv/versions/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' 来自 /home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler.rb:195:in default_gemfile' from /home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler.rb:165:inroot' 来自/home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler.rb:171:in app_config_path' from /home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler.rb:183:insettings' 来自/home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler/cli.rb:222:in install' from /home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:inrun' 来自/home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler/vendor/thor/invocation.rb:118:in @987654328 @派遣' 来自/home/alec/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.0.10/lib/bundler/vendor/thor/base.rb:389:in @987654329 @' 来自 /home/alec/.rbenv/versions/2.3.7/bin/bundle:22:in load' from /home/alec/.rbenv/versions/2.3.7/bin/bundle:22:in'

顺便说一句,我的 Gemfile:

source 'http://gems.ruby-china.com'

unless RUBY_PLATFORM =~ /w32/
  # unix-like only
  gem 'iconv'
  if RUBY_PLATFORM =~ /darwin/
    gem "rmagick", "= 2.15.4" ## osx must be this version
  elsif RUBY_PLATFORM =~ /linux/
    gem 'simple_xlsx_reader'
    gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel
    gem 'pdfkit'
    gem 'wkhtmltopdf-binary'
    gem 'rqrcode', '~> 0.10.1'
    gem 'rqrcode_png'
  end
  gem 'certified'
  gem 'net-ssh', '2.9.1'
  gem 'jenkins_api_client'
  gem 'nokogiri'
end

#gem 'simple_xlsx_reader'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
gem 'rest-client'
gem "mysql2", "= 0.3.18"
gem 'redis-rails'
gem 'rubyzip'
gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'
gem 'grape-entity', '= 0.4.5'
gem 'rack-cors', :require => 'rack/cors'
gem 'seems_rateable', '~> 1.0.13'
gem 'rails', '~> 3.2'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem 'coderay', '~> 1.1.0'
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
gem 'binding_of_caller'
gem 'chinese_pinyin'
# gem 'sunspot_rails', '~> 1.3.3'
# gem 'sunspot_solr'
# gem 'sunspot'
# gem 'progress_bar'
gem  'ansi'

gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'

#rails 3.2.22.2 bug
# gem "test-unit", "~>3.0"

### profile
# gem 'oneapm_rpm'
# gem 'therubyracer'

group :development do
  gem 'grape-swagger'
  gem 'better_errors', '~> 1.1.0'
  # gem "query_reviewer"
  gem 'rack-mini-profiler', '~> 0.9.3'
  if RUBY_PLATFORM =~ /w32/
    gem  'win32console'
  end

  if RUBY_PLATFORM =~ /darwin/
    gem 'puma'
end
end

group :development, :test do
    if RUBY_VERSION >= '2.0.0'
      gem 'pry-byebug'
    gem "test-unit", "~>3.0"
    end
  gem 'rspec-rails', '~> 3.0'
  gem 'factory_girl_rails'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

# Optional gem for LDAP authentication
group :ldap do
  gem "net-ldap", "~> 0.3.1"
end


# Optional gem for OpenID authentication
group :openid do
  gem "ruby-openid", "~> 2.1.4", :require => "openid"
  gem "rack-openid"
end


database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
else
  warn("Please configure your config/database.yml first")
end

# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
  puts "Loading #file ..." if $DEBUG # `ruby -d` or `bundle -v`
  instance_eval File.read(file)
end

我到处搜索,但没有任何用处。任何帮助将不胜感激!谢谢。

【问题讨论】:

【参考方案1】:

旧版本的bundlerrubygems 之间似乎有些不兼容。

我能够通过更新bundler 成功安装您的Gemfile(在此 sn-p 中,我将其更新到最新的可用 v1):

$ gem uninstall bundler
$ gem install bundler -v '~>1'
$ bundle install

【讨论】:

太棒了!它有效,你能给我一些关于这个选项的相关文档'~&gt;1' 吗? @Talon.Zhou 它与您在Gemfile 中使用的语法相同,例如gem 'grape', '~&gt; 0.9.0''~&gt; 0.9.0' 部分。以下是版本字段的完整语法:guides.rubygems.org/patterns/#pessimistic-version-constraint 非常感谢您的帮助!

以上是关于Rails:“bundle install”由于旧的 rails 版本(3.2)而失败的主要内容,如果未能解决你的问题,请参考以下文章

Elastic Beanstalk Ruby/Rails 需要安装 git,所以 bundle install 可以工作.. 但不是

bundle install on ruby​​ on rails 抛出 mingw32 错误

`bundle install` 由于权限被拒绝而失败

无法在 bundle install ruby​​ 上安装 mysql2

理解 Gemfile.lock:删除 Gemfile.lock 然后再次运行 bundle install 可以吗?

导轨。 'Bundle install' 在 Ruby 版本升级 (Windows) 后给出了 'bad interpreter: No such file or directory' 错误