如果您的系统中有 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