如何修复Rubygems最近的弃用警告?

我最近运行更新:

gem update --system gem update 

现在,每次加载gem时,我都会收到很多弃用警告。 例如, rails console

 NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01. Gem::Specification#default_executable= called from /Users/user/.rvm/gems/ruby-1.9.2-p180@global/specifications/rake-0.8.7.gemspec:10. NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01. Gem::Specification#default_executable= called from /Users/user/.rvm/gems/ruby-1.9.2-p180@global/specifications/rake-0.8.7.gemspec:10. NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01. Gem::Specification#default_executable= called from /Users/user/.rvm/gems/ruby-1.9.2p180@global/specifications/rake-0.8.7.gemspec:10. Loading development environment (Rails 3.0.7) ruby-1.9.2-p180 :001 > exit 

我使用RVM,Ruby 1.9.2和Rubygems 1.8.1。 有办法解决这个问题吗? 还原到旧版本的rubygems?

我不得不降级到1.6.2。 那些通知绝对是荒谬的。 他们使最新版本完全无法使用。 应该有一种方法来禁用它们,但在那之前:

sudo gem update --system 1.6.2

请参阅http://ryenus.tumblr.com/post/5450167670/eliminate-rubygems-deprecation-warnings

简而言之,跑步

 gem pristine --all --no-extensions ruby -e "`gem -v 2>&1 | grep called | sed -r -e 's#^.*specifications/##' -e 's/-[0-9].*$//'`.split.each {|x| `gem pristine #{x} -- --build-arg`}" 

如果反引号(或反引号)不适合你,正如@ jari-jokinen指出的那样(谢谢!)在某些情况下,用这个替换第二行

 ruby -e "%x(gem -v 2>&1 | grep called | sed -r -e 's#^.*specifications/##' -e 's/-[0-9].*$//').split.each {|x| %x(gem pristine #{x} -- --build-arg)}" 

注意:如果您在生产环境中使用Bundler,您的违规gem将被缓存到shared / bundle,因此您需要使用bundle exec运行这些命令

您还可以使用更多RVM特定的rvm rubygems current回到更安全的gem版本(1.6.2现在)。

我接受了其他人的回答,并将它们写成了一些对我来说更有用的东西。 我仍然需要从/ usr / local / cellar手动删除一对夫妇。

 #!/usr/bin/env bash # brew install gnu-sed sudo gem pristine --all --no-extensions gems=$(gem -v 2>&1 | grep called | gsed -r -e 's#^.*specifications/##' -e 's/-[0-9].*$//') for gem in $gems do echo Fixing $gem... sudo gem pristine $gem -- -build-arg done 

安装rubygems版本1.8.4摆脱了gem规范弃用警告:

$ gem update –system

=== 1.8.4 / 2011-05-25

  • 1个小改进:

    • 从Specification中删除了default_executable弃用。

运行此命令sudo gem pristine –all –no-extensions

删除所有这些警告消息。

更简单:将以下内容添加到environment.rb

 ActiveSupport::Deprecation.silenced = true 

看起来你还好,这只是一个警告, rake-0.8.7.gemspec不符合RubyGems的新标准。

我相信rake的创建者会得到这个同步。

我可以确认1.8.10已经在Rails 3.1环境中删除了这些弃用警告。

简单地跑

 gem update --system 

SlimGems也可能是一个解决方案。

首选解决方案

使用这个,由gmarik的要点提供 :

.bashrc:

 if [ -d "$HOME/.ruby/lib/" ]; then RUBYLIB="$RUBYLIB:$HOME/.ruby/lib" RUBYOPT="-rno_deprecation_warnings_kthxbye" export RUBYLIB RUBYOPT fi 

~/.ruby/lib/no_deprecation_warnings_kthxbye.rb

 begin require 'rubygems' Gem::Deprecate.skip = true if defined?(Gem::Deprecate) rescue LoadError => e pe end 

后退解决方案

在以下情况下使用

  • 你使用RVM并将gem保存在〜中
  • 你不能使用$RUBYLIB因为你的IDE在运行unit testing时会忽略它
  • 你无法升级到最新的Rubygems,因为Gemfile中的一些旧的,未维护的gem

修改rubygems/deprecate.rb

 def self.skip # :nodoc: @skip ||= true end