Ruby-on-rails 如何删除默认 gem?!想卸载一个 gem 1.7.7 版本的 json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20945110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I remove a default gem? ! want to uninstall a gem 1.7.7 version of json
提问by wanghao
I have the same rails app in OSX and Ubuntu, I want to use Zeus to speed up my rspec.
In Ubuntu, Zeus starts Ok, but in OSX it always be crashed.
At last I find the issue, https://github.com/burke/zeus/issues/237#issuecomment-18700462the difference between OSX and Ubuntu is the version of json gem.
I use gem list | grep jsonUbuntu shows
我在 OSX 和 Ubuntu 中有相同的 rails 应用程序,我想使用 Zeus 来加速我的 rspec。在 Ubuntu 中,Zeus 启动正常,但在 OSX 中它总是崩溃。终于找到问题了,https://github.com/burke/zeus/issues/237#issuecomment-18700462OSX和Ubuntu的区别在于json gem的版本。我使用gem list | grep jsonUbuntu 节目
json (1.8.1, 1.8.0, 1.5.3)
json_pure (1.5.3)
json_spec (1.1.1)
jsonpath (0.5.3)
multi_json (1.8.2, 1.7.8, 1.0.3)
Mac shows
麦克秀
json (1.8.1, 1.7.7)
json_spec (1.1.1)
jsonpath (0.5.5, 0.5.3)
multi_json (1.8.2, 1.7.8)
so I want to uninstall 1.7.7 version of json gem to make zeus start, but
所以我想卸载 1.7.7 版本的 json gem 来让 zeus 启动,但是
gem uninstall json -v 1.7.7
ERROR: While executing gem ... (Gem::InstallError)
gem "json" cannot be uninstalled because it is a default gem
What should I do?
我该怎么办?
回答by newdark-it
So based off what I can tell there is no easy command that can move the gemspec file from the default folder to the non-default folder. This is a good thing from what I can tell but here are the instructions on how to do this by hand.
因此,根据我所知道的,没有简单的命令可以将 gemspec 文件从默认文件夹移动到非默认文件夹。据我所知,这是一件好事,但这里是有关如何手动执行此操作的说明。
Find the location of the default spec. The easiest way is to go into
irband run the following command:irb(main):002:0> Gem.default_specifications_dir => "/Users/user/.rubies/ruby-2.5.7/lib/ruby/gems/2.5.0/specifications/default"For older rubygems it's:
irb(main):001:0> File.join Gem::Specification.default_specifications_dir => "/Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default"
找到默认规范的位置。最简单的方法是进入
irb并运行以下命令:irb(main):002:0> Gem.default_specifications_dir => "/Users/user/.rubies/ruby-2.5.7/lib/ruby/gems/2.5.0/specifications/default"对于较旧的 rubygems,它是:
irb(main):001:0> File.join Gem::Specification.default_specifications_dir => "/Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default"
This is the line of code that builds the gemspec path https://github.com/rubygems/rubygems/blob/v2.6.13/lib/rubygems/installer.rb#L420
这是构建 gemspec 路径的代码行 https://github.com/rubygems/rubygems/blob/v2.6.13/lib/rubygems/installer.rb#L420
Once you get the file path you just need to move the gem name and version from the default folder to the parent folder.
$ cd /Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default $ mv json-1.7.7.gemspec ../
获得文件路径后,您只需将 gem 名称和版本从默认文件夹移动到父文件夹。
$ cd /Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default $ mv json-1.7.7.gemspec ../
if you do gem list -dyou should no longer see the words Installed at (default)next to the gem version json-1.7.7. you can then run gem uninstall json -v 1.7.7with out it fighting you. If you want to undo all this just run gem install json -v 1.7.7 --default
如果你这样做了,gem list -d你应该不会再看到Installed at (default)gem 版本 json-1.7.7 旁边的字样。然后你就可以跑gem uninstall json -v 1.7.7了,它不会和你打架。如果您想撤消所有这些,请运行gem install json -v 1.7.7 --default
回答by riverswb
I have been experiencing a problem with default versions of gems, and the accepted answer did not work for me. What worked for me was to install the same version as the default, but without the default flag, and then uninstall it.
我遇到了默认版本的 gems 的问题,接受的答案对我不起作用。对我有用的是安装与默认版本相同的版本,但没有默认标志,然后卸载它。
gem install json -v '1.7.7'
Then once that is finished:
然后一旦完成:
gem uninstall json -v '1.7.7'
回答by HarsHarI
may be this will help you....
可能这会帮助你......
bundle exec gem uninstall GEM_NAME
if above cmd not work then try this
如果上面的 cmd 不起作用,那么试试这个
execute this either in irb or in a script proper:
在 irb 或适当的脚本中执行此操作:
`gem list --no-versions`.split("\n").each do |gem|
`gem list -d #{gem}`.gsub(/Installed at(.*):.*/).each do |dir|
dir = dir.gsub(/Installed at(.*): /,'').gsub("\n", '')
system "gem uninstall #{gem} -aIx -i #{dir}"
end
end
if above both are fails then try this
如果以上两者都失败,那么试试这个
go to your rvm dir.. where all gems are install then manually remove that gem which you want.. such as in my case my gem dir location is /home/user_name/.rvm/gems/ruby-1.9.3-p194/gems
转到您的 rvm 目录 .. 安装所有 gems 然后手动删除您想要的那个 gem.. 例如在我的情况下,我的 gem 目录位置是 /home/user_name/.rvm/gems/ruby-1.9.3-p194/宝石

