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

如何修复Rubygems最近的弃用警告?,ruby,rubygems,rvm,suppress-warnings,Ruby,Rubygems,Rvm,Suppress Warnings,我最近运行了以下更新: gem update --system gem update 现在,每次加载gem时,我都会收到很多不推荐的警告。例如,rails控制台: NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01. Gem::Specification#default_executable= calle

我最近运行了以下更新:

gem update --system
gem update
现在,每次加载gem时,我都会收到很多不推荐的警告。例如,
rails控制台

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更新——system 1.6.2

看起来你没事,这只是一个警告,rake-0.8.7.gempec将无法满足RubyGems的新标准

我确信rake的创建者将获得此同步。

请参见此处

简而言之,就是跑步

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`}"
如果backtick(或backquote)在某些情况下对您不起作用,正如@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,您的违规gems将被缓存到shared/bundle中,因此您需要使用bundle exec运行这些命令。我收集了其他人的答案,并将其脚本化为对我来说更有效的内容。我仍然不得不从/usr/local/cillar中手工删除一对

#!/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

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

安装rubygems 1.8.4版可以消除gem规范弃用警告:

$gem更新--系统

==1.8.4/2011-05-25

  • 1轻微改善:

    • 从规范中删除了默认的\u可执行文件弃用
运行此命令 sudo gem pristine--全部--无扩展


删除所有这些警告消息。

我可以确认1.8.10也删除了Rails 3.1环境中的这些弃用警告

简单运行

gem update --system

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

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

ActiveSupport::Deprecation.silenced = true
begin
require 'rubygems'
Gem::Deprecate.skip = true if defined?(Gem::Deprecate)
rescue LoadError => e
  p e
end
首选解决方案 使用此功能,有礼貌地:

.bashrc:

if [ -d "$HOME/.ruby/lib/" ]; then
  RUBYLIB="$RUBYLIB:$HOME/.ruby/lib"
  RUBYOPT="-rno_deprecation_warnings_kthxbye"
  export RUBYLIB RUBYOPT
fi
~/.ruby/lib/no\u deprecation\u warnings\u kthxbye.rb

ActiveSupport::Deprecation.silenced = true
begin
require 'rubygems'
Gem::Deprecate.skip = true if defined?(Gem::Deprecate)
rescue LoadError => e
  p e
end
回退方案 在以下情况下使用它:

  • 您使用RVM并将宝石保存在~
  • 您不能使用
    $RUBYLIB
    ,因为您的IDE在运行单元测试时会忽略它
  • 您无法升级到最新的Rubygems,因为Gemfile中有一些旧的、未维护的gems
修改rubygems/deprecate.rb:

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

我尝试了以上所有的选择,但没有任何效果

最后,我卸载了Ruby和所有依赖项,使用链接安装了RVM, 并使用
rvm install Ruby
重新安装了Ruby


事情开始进展顺利

你需要提供更多的信息,你的Gemfile是什么样子的?可能的副本不仅仅是Rake。这会影响到很多其他gem,如果它们使用本机代码,则需要重新安装。不幸的是,这对我不起作用。使用mac、rvm(1.92)和雪豹。@walinzi先生,我不确定是否诚实。我只是想和平地开发我的rails应用程序,我可以用1.6.2来实现这一点,现在我已经升级回1.8.4了。
gem pristine…
解决方案似乎工作得很好回滚总是会在ruby 1.9.1 rubygems上引入它自己的问题-对我来说,这个命令无论如何都不起作用-在ruby 1.9.1 rubygems.rb:483:in
find_files:undefined method
map',for gem::Specification:Class(NoMethodError)我已经尝试运行了上面提到的命令,但它不起作用。显示以下错误消息。正在获取rubygems-update-1.6.2.gem错误:在执行gem时。。。(Gem::FilePermissionError)您没有/usr/bin目录的写入权限第一个命令运行得很好,但第二个命令给了我一个语法错误(Ruby 1.8.7-p249)。还有其他人吗?我在第二行也有语法错误,所以我只是手工做的。检查调用的
gem-v2>&1 | grep的输出
,对于该命令返回的每个gem,执行
gem pristine gem_NAME_此处----build arg
。您可能需要使用
sudo
allow.hmmm、@aidan feldman、@mirthlab,请问这是什么语法错误?我不认为第二行中使用了任何仅ruby 1.9的功能,可能缺少sed或sudo?Backticks在ruby Enterprise Edition 2011.03(1.8.7)和/或Bash 4.1.5(1)中不起作用,所以我只是将它们替换为%x[]如下:
ruby-e”%x[gem-v2>&1 | grep称为| sed-r-e's#^.*规范/-[0-9].*/]《代码>OSX/BSD系统将得到一个<代码>sed:非法选项:非法选项——r因为sed使用了不同的标志。由于sed使用了不同的国旗。相反,将<代码>-r替换为<代码>-r&1 |格雷普称为.格雷普称为| sed-E-E-E-E-E-E-E-E-E-E-E-E-E-E-E-E-E-E的格雷普称为.格雷普称为.格雷普称为.格雷普称为.格雷普称为..格雷普称为.格雷普称为.格雷普称为................................{x}-->build arg]}“
需要Scala的人来正确修复Ruby gems!谢谢!->在我的例子中,我使用了带有Ruby-1.8.7-p302的rvm,运行current仍然给了我rubygems 1.8.6及其所有警告;
rvm安装rubygems 1.6.2
完成了这个技巧。