ruby 在 OSX 中卸载所有已安装的 gems?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8095209/
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
Uninstall all installed gems, in OSX?
提问by crftr
There are instances where I would like to revert and uninstall all previous gem installations.
在某些情况下,我想恢复和卸载所有以前的 gem 安装。
For instance, I needed to assist a friend migrate their rails development machine to use RVM. As they had been previously using the system-wide gem, he was experiencing many headaches when working with multiple projects. Essentially, he was the poster-child for an RVM convert.
例如,我需要帮助朋友迁移他们的 rails 开发机器以使用 RVM。由于他们之前一直在使用系统范围的gem,他在处理多个项目时遇到了很多麻烦。 从本质上讲,他是 RVM 转换的典型代表。
How can I elegantly uninstall all of the gems on his OSX system?
如何优雅地卸载他的 OSX 系统上的所有 gem?
回答by crftr
Rubygems >= 2.1.0
红宝石 >= 2.1.0
gem uninstall -aIx
aremoves all versionsIignores dependenciesxincludes executables
a删除所有版本I忽略依赖项x包括可执行文件
Rubgems < 2.1.0
红宝石 < 2.1.0
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
回答by bswinnerton
You could also build out a new Gemfile and run bundle clean --force. This will remove all other gems that aren't included in the new Gemfile.
您还可以构建一个新的 Gemfile 并运行bundle clean --force. 这将删除未包含在新 Gemfile 中的所有其他 gem。
回答by Thiago Ganzarolli
A slighest different version, skipping the cut step, taking advantage of the '--no-version' option:
一个最轻微的不同版本,跳过剪切步骤,利用“--no-version”选项:
gem list --no-version |xargs gem uninstall -ax
Since you are removing everything, I don't see the need for the 'I' option. Whenever the gem is removed, it's fine.
由于您要删除所有内容,因此我认为不需要“I”选项。每当宝石被移除时,就可以了。
回答by aercolino
Use either
使用任一
$ gem list --no-version | xargs gem uninstall -ax
or
或者
$ sudo gem list --no-version | xargs sudo gem uninstall -ax
Depending on what you want, you may need to execute both, because "gem list" and "sudo gem list" provide independent lists.
根据您的需要,您可能需要同时执行两者,因为“gem list”和“sudo gem list”提供了独立的列表。
Do not mix a normal "gem list" with a sudo-ed "gem uninstall" nor the other way around otherwise you may end up uninstalling sudo-installed gems (former) or getting a lot of errors (latter).
不要将普通的“gem 列表”与带有 sudo 的“gem 卸载”混合在一起,反之亦然,否则您最终可能会卸载 sudo 安装的 gem(前者)或出现很多错误(后者)。
回答by collect
First make sure you have at least gem version 2.1.0
首先确保你至少有 gem 版本 2.1.0
gem update --system
gem --version
# 2.6.4
To uninstall simply run:
要卸载只需运行:
gem uninstall --all
You may need to use the sudocommand:
您可能需要使用以下sudo命令:
sudo gem uninstall --all
回答by rrrub
If you are using Rubygems version 2.1.0 or later, you can try: gem uninstall --all.
如果您使用的RubyGems版本2.1.0或更高版本,你可以试试:gem uninstall --all。
回答by Haris Krajina
If you like doing it using ruby:
如果您喜欢使用 ruby:
ruby -e "`gem list`.split(/$/).each { |line| puts `gem uninstall -Iax #{line.split(' ')[0]}` unless line.strip.empty? }"
Cheers
干杯
回答by Kirtikumar A.
Rubygems >= 2.1.0
红宝石 >= 2.1.0
gem uninstall -aIx
If Terminal returns below error
如果终端返回以下错误
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Then write above command as below
然后写上面的命令如下
sudo gem uninstall -aIx
And enter your mac os account password Done!!
并输入您的 mac os 帐户密码 Done!!
回答by Trevor Elwell
And for those of you who are here because you want to remove all gems with a certain prefix (ahemI'm looking at you aws-sdk!) you can run something like this:
对于那些因为想要删除所有带有特定前缀的 gem(啊哈,我正在看着你 aws-sdk!)而在这里的人,你可以运行这样的东西:
gem list --no-version | grep "aws-sdk-" | xargs gem uninstall -aIx
Obviously put in your query instead of aws-sdk-. You need the -Iin there to ignore dependencies.
显然把你的查询而不是aws-sdk-. 您需要-I在那里忽略依赖项。
Adopted form Ando's earlier answer
采用安藤早先的回答
回答by Attenzione
The only command helped me to cleanup all gems and ignores default gems, which can't be uninstalled
唯一的命令帮助我清理了所有 gems 并忽略了无法卸载的默认 gems
for x in `gem list --no-versions`; do gem uninstall $x -a -x -I; done

