如何从 Ruby on Rails 应用程序中删除 gem?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5250362/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:37:16  来源:igfitidea点击:

How to remove gem from Ruby on Rails application?

ruby-on-railsrubyrubygems

提问by Oded Harth

I have installed a gem on my Rails application (devise). After I installed the gem, I realized that I don't need it.

我在我的 Rails 应用程序(设计)上安装了一个 gem。安装 gem 后,我意识到我不需要它。

I want to remove the gem, its dependencies and the files it created on my application. In other words, I want to restore the system to what it used to be before the gem. How can I do this? (I'm using Ruby on Rails 3.)

我想删除 gem、它的依赖项以及它在我的应用程序上创建的文件。换句话说,我想将系统恢复到 gem 之前的状态。我怎样才能做到这一点?(我使用的是 Ruby on Rails 3。)

采纳答案by d135-1r43

Devise uses some generators to generate views and stuff it needs into your application. If you have run this generator, you can easily undo it with

Devise 使用一些生成器来生成视图并将它需要的内容添加到您的应用程序中。如果你已经运行了这个生成器,你可以很容易地撤销它

rails destroy <name_of_generator>

The uninstallation of the gem works as described in the other posts.

gem 的卸载工作如其他帖子中所述。

回答by rtfminc

You can use

您可以使用

gem uninstall <gem-name>

gem uninstall <gem-name>

回答by Srdjan Pejic

If you're using Rails 3+, remove the gem from the Gemfile and run bundle install.

如果您使用的是 Rails 3+,请从 Gemfile 中删除 gem 并运行bundle install.

If you're using Rails 2, hopefully you've put the declaration in config/environment.rb. If so, removing it from there and running rake gems:installshould do the trick.

如果您使用 Rails 2,希望您已将声明放在 config/environment.rb 中。如果是这样,从那里删除它并运行rake gems:install应该可以解决问题。

回答by Gagan Gami

For Rails 4 - remove the gem name from Gemfileand then run bundle installin your terminal. Also restart the server afterwards.

对于 Rails 4 - 删除 gem 名称Gemfile,然后bundle install在终端中运行。之后也重新启动服务器。

回答by cybertoast

How about something like:

怎么样:

gem dependency devise --pipe | cut -d \  -f 1 | xargs gem uninstall -a

(this assumes that you're not using bundler - but I guess you're not since removing from your bundle gemspec would solve the problem)

(这假设您没有使用捆绑程序 - 但我想您没有使用,因为从您的捆绑包中删除 gemspec 可以解决问题)

回答by harald

You are using some sort of revision control, right? Then it should be quite simple to restore to the commit before you added the gem, or revert the one where you added it if you have several revisions after that you wish to keep.

您正在使用某种版本控制,对吗?然后,在您添加 gem 之前恢复到提交应该是非常简单的,或者如果您希望保留之后有多个修订,则恢复添加它的那个提交。