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

Har*_*tor 17 ruby rubygems suppress-warnings rvm

我最近运行更新:

gem update --system
gem update
Run Code Online (Sandbox Code Playgroud)

现在,每次加载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
Run Code Online (Sandbox Code Playgroud)

我使用RVM,Ruby 1.9.2和Rubygems 1.8.1.有什么方法可以解决这个问题吗?还原到旧版本的rubygems?

p3d*_*ola 15

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

sudo gem update --system 1.6.2


rye*_*nus 14

请参阅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`}"
Run Code Online (Sandbox Code Playgroud)

如果反引号(或反引号)对你不起作用,正如@ 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)}"
Run Code Online (Sandbox Code Playgroud)

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

  • OSX/BSD 系统会得到一个 `sed: 非法选项 -- r`,因为 sed 使用不同的标志。用`-E`代替`-r`,即:`ruby -e "%x[gem -v 2>&1 | grep called | sed -E -e 's#^.*specifications/##' -e 's/-[0-9].*$//'].split.each {|x| %x[gem pristine #{x} -- --build-arg]}"` (3认同)

Joo*_*uur 8

您还可以使用更具体的RVM rvm rubygems current来回到更安全的gem版本(1.6.2现在).


psp*_*psp 5

我接受了其他人的答案,并将它们编写成对我来说更有用的东西。我仍然不得不从 /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
Run Code Online (Sandbox Code Playgroud)