我需要从 bash 脚本中检查是否安装了某些 Ruby gem。
我以为我可以做类似的事情
if ! gem list <name>; then do_stuff; fi
Run Code Online (Sandbox Code Playgroud)
但是在命令行上使用测试echo $?
表明gem list <name>
无论是否实际找到名称都返回 0。
这是否意味着我必须使用 grep 来过滤 gem list 的输出,或者有没有更好的方法可以检查是否安装了 gem?
我使用的是 Ubuntu 12.04 LTS(32 位,服务器)、puppet 2.7.17、ruby 1.8.7.352 rubygems 1.8.15。和 Apache 2.2.22。
当我尝试运行命令来迁移数据库时,
<server>:/usr/share/puppet-dashboard# rake RAILS_ENV=production db:migrate
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /usr/share/puppet-dashboard/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /usr/share/puppet-dashboard/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:100.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/vendor_ruby/1.8/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will …
Run Code Online (Sandbox Code Playgroud)