如何获取已安装具有本机扩展名的gem列表?

时间:2021-07-15 07:16:24

I'm on windows, and have updated from ruby 1.8.x to 1.9.x, and am now getting error popups that complain ruby-mssomethingrt.1.8.x.dll is missing.

我在Windows上,并已从ruby 1.8.x更新到1.9.x,现在我收到错误弹出窗口,抱怨ruby-mssomethingrt.1.8.x.dll丢失。

I would like to find out which gems have native extensions, so I can uninstall them and force a rebuild of the native extensions locally during installation again, to make the error go away.

我想找出哪些gems具有原生扩展,因此我可以卸载它们并在安装期间强制在本地重建本机扩展,以使错误消失。

5 个解决方案

#1


7  

A good start would be to look at the gem specification for each gem and see if it has the extensions field set. That should leave you with a short-list of gems to re-install. They don't necessarily all use native extensions, but if you look at the corresponding extconf.rb files, this should be pretty easy to find out.

一个好的开始是查看每个gem的gem规范,看看它是否设置了扩展字段。这应该给你留下一个重新安装宝石的简短列表。它们不一定都使用本机扩展,但是如果你查看相应的extconf.rb文件,这应该很容易找到。

Update: Here is a short ruby script to list those gems:

更新:这是一个简短的ruby脚本列出这些宝石:

require 'rubygems'

Gem.source_index.each do |gem|
  spec =  Gem.source_index.specification(gem[0])
  ext = spec.extensions
  puts "#{gem[0]} has extensions: #{ext}" unless ext.empty?
end

#2


5  

You can rebuild (and restore to a pristine state) all installed gems with:

您可以使用以下方法重建(并恢复到原始状态)所有已安装的宝石:

gem pristine --all

--all --no-extensions will restore gems without extensions, but despite being documented, --extensions appears to have no effect (at least on rubygems 1.8.23 on Ubuntu 12.10).

--all --no-extensions将恢复没有扩展的gem,但是尽管有文档记录,--extensions似乎没有效果(至少在Ubuntu 12.10上的rubygems 1.8.23)。

#3


4  

Based on this answer, here is a solution that finds and offers to reinstall gems with native extensions that works with recent rubies (>=1.9).

基于这个答案,这里有一个解决方案,可以找到并提供重新安装带有原始扩展的gem,这些扩展可以使用最近的rubies(> = 1.9)。

native_gems = []
Gem::Specification.each do |spec|
  native_gems << "#{spec.name}:#{spec.version}" unless spec.extensions.empty?
end

install_cmd = "gem install #{native_gems.join ' '}"
puts "Found #{native_gems.length} gem(s) with native extensions:"
puts "\n> " + install_cmd, "\nReinstall gems with above command? (yn)"

exec insall_cmd if gets.downcase[0] == 'y'

Example Output:

示例输出:

Found 36 gem(s) with native extensions:

> gem install atomic:1.1.13 bcrypt-ruby:3.0.1 bigdecimal:1.2.0 eventmachine:1.0.3 eventmachine:1.0.0 eventmachine:0.12.10 ffi:1.9.3 ffi:1.9.0 ffi:1.7.0 hiredis:0.4.5 hpricot:0.8.6 io-console:0.4.2 json:1.8.1 json:1.8.0 json:1.7.6 nokogiri:1.6.0 nokogiri:1.5.9 pg:0.17.1 pg:0.17.0 pg:0.16.0 pg:0.15.1 pg:0.13.2 psych:2.0.0 puma:2.7.1 puma:2.6.0 puma:2.4.0 puma:1.6.3 sqlite3:1.3.8 sqlite3:1.3.7 sqlite3:1.3.5 therubyracer:0.12.0 thin:1.5.1 thin:1.5.0 thin:1.4.1 websocket-driver:0.2.3 websocket-driver:0.1.0

Reinstall gems with above command? (yn)
…

#4


0  

gem list

宝石清单

the part after the version next to the gem should indicate whether it's running native code: e.g. json (1.4.6 x86-mingw32)

gem旁边的版本之后的部分应指示它是否正在运行本机代码:例如json(1.4.6 x86-mingw32)

The error you are seeing is because one of the gems you are using expects the 1.8 ruby interpreter to be present which it no longer is (as you have upgraded to 1.9).

您看到的错误是因为您使用的某个宝石需要1.8 ruby​​解释器不再存在(因为您已升级到1.9)。

I would have thought that just running 'gem update' would fix your problem. If it doesn't, then you might need to seek an alternative gem for the one that is expecting the ruby 1.8 interpreter to be present.

我本以为只要运行'gem update'就可以解决你的问题。如果没有,那么您可能需要为期望ruby 1.8解释器存在的那个寻找替代gem。

#5


0  

In Cygwin you could try gem list --all -d | grep --before-context=1 --after-context=4 Platform.

在Cygwin中你可以尝试gem list --all -d | grep --before-context = 1 --after-context = 4平台。

#1


7  

A good start would be to look at the gem specification for each gem and see if it has the extensions field set. That should leave you with a short-list of gems to re-install. They don't necessarily all use native extensions, but if you look at the corresponding extconf.rb files, this should be pretty easy to find out.

一个好的开始是查看每个gem的gem规范,看看它是否设置了扩展字段。这应该给你留下一个重新安装宝石的简短列表。它们不一定都使用本机扩展,但是如果你查看相应的extconf.rb文件,这应该很容易找到。

Update: Here is a short ruby script to list those gems:

更新:这是一个简短的ruby脚本列出这些宝石:

require 'rubygems'

Gem.source_index.each do |gem|
  spec =  Gem.source_index.specification(gem[0])
  ext = spec.extensions
  puts "#{gem[0]} has extensions: #{ext}" unless ext.empty?
end

#2


5  

You can rebuild (and restore to a pristine state) all installed gems with:

您可以使用以下方法重建(并恢复到原始状态)所有已安装的宝石:

gem pristine --all

--all --no-extensions will restore gems without extensions, but despite being documented, --extensions appears to have no effect (at least on rubygems 1.8.23 on Ubuntu 12.10).

--all --no-extensions将恢复没有扩展的gem,但是尽管有文档记录,--extensions似乎没有效果(至少在Ubuntu 12.10上的rubygems 1.8.23)。

#3


4  

Based on this answer, here is a solution that finds and offers to reinstall gems with native extensions that works with recent rubies (>=1.9).

基于这个答案,这里有一个解决方案,可以找到并提供重新安装带有原始扩展的gem,这些扩展可以使用最近的rubies(> = 1.9)。

native_gems = []
Gem::Specification.each do |spec|
  native_gems << "#{spec.name}:#{spec.version}" unless spec.extensions.empty?
end

install_cmd = "gem install #{native_gems.join ' '}"
puts "Found #{native_gems.length} gem(s) with native extensions:"
puts "\n> " + install_cmd, "\nReinstall gems with above command? (yn)"

exec insall_cmd if gets.downcase[0] == 'y'

Example Output:

示例输出:

Found 36 gem(s) with native extensions:

> gem install atomic:1.1.13 bcrypt-ruby:3.0.1 bigdecimal:1.2.0 eventmachine:1.0.3 eventmachine:1.0.0 eventmachine:0.12.10 ffi:1.9.3 ffi:1.9.0 ffi:1.7.0 hiredis:0.4.5 hpricot:0.8.6 io-console:0.4.2 json:1.8.1 json:1.8.0 json:1.7.6 nokogiri:1.6.0 nokogiri:1.5.9 pg:0.17.1 pg:0.17.0 pg:0.16.0 pg:0.15.1 pg:0.13.2 psych:2.0.0 puma:2.7.1 puma:2.6.0 puma:2.4.0 puma:1.6.3 sqlite3:1.3.8 sqlite3:1.3.7 sqlite3:1.3.5 therubyracer:0.12.0 thin:1.5.1 thin:1.5.0 thin:1.4.1 websocket-driver:0.2.3 websocket-driver:0.1.0

Reinstall gems with above command? (yn)
…

#4


0  

gem list

宝石清单

the part after the version next to the gem should indicate whether it's running native code: e.g. json (1.4.6 x86-mingw32)

gem旁边的版本之后的部分应指示它是否正在运行本机代码:例如json(1.4.6 x86-mingw32)

The error you are seeing is because one of the gems you are using expects the 1.8 ruby interpreter to be present which it no longer is (as you have upgraded to 1.9).

您看到的错误是因为您使用的某个宝石需要1.8 ruby​​解释器不再存在(因为您已升级到1.9)。

I would have thought that just running 'gem update' would fix your problem. If it doesn't, then you might need to seek an alternative gem for the one that is expecting the ruby 1.8 interpreter to be present.

我本以为只要运行'gem update'就可以解决你的问题。如果没有,那么您可能需要为期望ruby 1.8解释器存在的那个寻找替代gem。

#5


0  

In Cygwin you could try gem list --all -d | grep --before-context=1 --after-context=4 Platform.

在Cygwin中你可以尝试gem list --all -d | grep --before-context = 1 --after-context = 4平台。