所有rails项目--Bundler正在使用为不同的gem创建的binstub

时间:2015-03-19 17:47:18

标签: ruby-on-rails-4 bundler

在我的所有Rails项目中,当我运行rails s时,我得到以下输出:

Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub rails` to work around a system/bundle conflict.

我已经看过处理项目的解决方案,但我可能遇到系统问题吗?

1 个答案:

答案 0 :(得分:0)

如果您的系统中同时具有3.x和4.x,或者在我的系统中有两个具有不同bin名称的版本,则会发生这种情况,我使用3.2.22,其名称为railties和4。 x bin名称是rails,Rubygems将在第一次安装时为gem创建一个binstubs,所以如果你像我先安装4.x rails一样,其他3.x项目将会收到此消息。 rails 4.x的binstub文件的最后一行是这样的:     加载Gem.bin_path('railties','rails',版本)

而3.x就是这个     加载Gem.bin_path('rails','rails',版本)

警告消息来自Bundler gem的rubygems_integration.rb第344行

def replace_bin_path(specs)
  gem_class = (class << Gem; self; end)
  redefine_method(gem_class, :bin_path) do |name, *args|
    exec_name = args.first

    return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"

    spec = nil

    if exec_name
      spec = specs.find {|s| s.executables.include?(exec_name) }
      raise(Gem::Exception, "can't find executable #{exec_name}") unless spec
      unless spec.name == name
        warn "Bundler is using a binstub that was created for a different gem.\n" \
          "This is deprecated, in future versions you may need to `bundle binstub #{name}` " \
          "to work around a system/bundle conflict."
      end
    else
      spec = specs.find {|s| s.name == name }
      raise Gem::Exception, "no default executable for #{spec.full_name}" unless exec_name = spec.default_executable
    end

    gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
    gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
    File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
  end
end

因此解决方案是卸载所有导轨

gem uninstall rails

如果仍然存在,则删除binstub文件

which rails
rm -rf path_of_rails

并安装实际使用的rails版本

gem install rails -v 3.2.22