简体   繁体   English

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

[英]How to remove gem from Ruby on Rails application?

I have installed a gem on my Rails application (devise).我已经在我的 Rails 应用程序(设计)上安装了一个 gem。 After I installed the gem, I realized that I don't need it.安装 gem 后,我意识到我不需要它。

I want to remove the gem, its dependencies and the files it created on my application.我想删除 gem、它的依赖项以及它在我的应用程序上创建的文件。 In other words, I want to restore the system to what it used to be before the gem.换句话说,我想将系统恢复到 gem 之前的状态。 How can I do this?我怎样才能做到这一点? (I'm using Ruby on Rails 3.) (我使用的是 Ruby on Rails 3。)

您可以使用

gem uninstall <gem-name>

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.如果您使用 Rails 2,希望您已将声明放在 config/environment.rb 中。 If so, removing it from there and running rake gems:install should do the trick.如果是这样,从那里删除它并运行rake gems:install应该可以解决问题。

Devise uses some generators to generate views and stuff it needs into your application. Devise 使用一些生成器来生成视图并将它需要的内容添加到您的应用程序中。 If you have run this generator, you can easily undo it with如果你已经运行了这个生成器,你可以很容易地撤销它

rails destroy <name_of_generator>

The uninstallation of the gem works as described in the other posts. gem 的卸载工作如其他帖子中所述。

For Rails 4 - remove the gem name from Gemfile and then run bundle install in your terminal.对于 Rails 4 - 从Gemfile删除 gem 名称,然后在终端中运行bundle install Also restart the server afterwards.之后也重新启动服务器。

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 可以解决问题)

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 之前恢复到提交应该非常简单,或者如果您希望保留之后有多个修订,则恢复添加它的那个提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM