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

时间:2023-01-21 19:24:21

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。)

6 个解决方案

#1


17  

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

designs使用了一些生成器来生成视图和应用程序所需的东西。如果您运行了这个生成器,您可以很容易地用它来撤消它

rails destroy <name_of_generator>

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

如其他文章所述,宝石作品的解除。

#2


83  

You can use

您可以使用

gem uninstall <gem-name>

宝石卸载< gem-name >

#3


34  

If you're using Rails 3, removing it from the Gemfile and running bundle install will suffice.

如果您正在使用Rails 3,那么从Gemfile中删除它并运行bundle安装就足够了。

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:install should do the trick.

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

#4


3  

For Rails 4 - remove the gem name from Gemfile and then run bundle install in your terminal. Also restart the server afterwards.

对于Rails 4——从Gemfile中删除gem名称,然后在终端中运行bundle install。然后,重启服务器。

#5


1  

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)

(这里假设您没有使用bundler—但是我想您并没有从bundle gemspec中删除这个问题)

#6


-2  

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之前恢复提交应该非常简单,或者如果在添加了几个修订之后还想保留的话,就恢复添加的提交。

#1


17  

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

designs使用了一些生成器来生成视图和应用程序所需的东西。如果您运行了这个生成器,您可以很容易地用它来撤消它

rails destroy <name_of_generator>

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

如其他文章所述,宝石作品的解除。

#2


83  

You can use

您可以使用

gem uninstall <gem-name>

宝石卸载< gem-name >

#3


34  

If you're using Rails 3, removing it from the Gemfile and running bundle install will suffice.

如果您正在使用Rails 3,那么从Gemfile中删除它并运行bundle安装就足够了。

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:install should do the trick.

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

#4


3  

For Rails 4 - remove the gem name from Gemfile and then run bundle install in your terminal. Also restart the server afterwards.

对于Rails 4——从Gemfile中删除gem名称,然后在终端中运行bundle install。然后,重启服务器。

#5


1  

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)

(这里假设您没有使用bundler—但是我想您并没有从bundle gemspec中删除这个问题)

#6


-2  

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之前恢复提交应该非常简单,或者如果在添加了几个修订之后还想保留的话,就恢复添加的提交。