How to Remove Gem from Ruby on Rails Application

How to remove gem from Ruby on Rails application?

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

rails destroy <name_of_generator>

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

How to remove gems from Rails project?

The gem could be a dependency of another gem which would explain its presence in bundle show.

If the gem appears indented beneath another gem within the Gemfile.lock file then it would indicate that it's included still because it's a dependency.

How to uninstall ahoy gem

I'm going to make some assumptions about your app to answer this question. Feel free to provide additional information if this answer does not apply to you.

gem uninstall ahoy-matey isn't going to do anything for your app because the gem is called ahoy_matey. Uninstalling the gem requires gem uninstall ahoy_matey.

Even then, this has no effect your app. Rails apps use bundler to manage gems through a Gemfile, so removing the gem from your app would require editing the Gemfile to remove the reference to ahoy_matey, then running bundle install to update your gems.

But this still won't remove it from your app. I assume that you are using a standard git workflow and that before installing ahoy you were working from a clean branch with no uncommitted changes, and that after you installed and configured ahoy you committed all those changes. You need to go back to your git commit history to see what changes were made to your app and begin undoing them.

Looking at the installation instructions, you probably had to run these commands:

rails generate ahoy:install
rails db:migrate

The generator will have created a couple of models for you, an initializer, and a database migration. Removing these isn't as simple as "just delete the files." You will need to write a migration to drop these tables from your database while maintaining your database's migration history. Figuring out what tables to drop will require reviewing what the original migrations did that were added by the gem.

After you have written and run your migration you can then remove any models and initializers that were created by the gem. Finally, you can run your application's test suite to ensure the app works properly before starting it and validating it works the way you expect.

Removing all installed Gems and starting over

From the RVM support site:

RVM installs everything into ~/.rvm.
To remove RVM from your system run 'rm
-rf ~/.rvm'. You may have one additional config file in ~/.rvmrc and
of course the RVM hook in your
bash/zsh startup files.

So, just go to the command line and type rm -rf ~/.rvm

All the installed gems are in the ~/.rvm folders, so doing the above will remove the gems and installed rubies in one go.

Gems you added pre-RVM with the default ruby install can be removed by typing this at the command prompt:

for x in `gem list --no-versions`; do gem uninstall $x -a -x -I; done

What is the best way to uninstall gems from a rails3 project?

Bundler is launched from your app's root directory so it makes sure all needed gems are present to get your app working.If for some reason you no longer need a gem you'll have to run the

    gem uninstall gem_name 

as you stated above.So every time you run bundler it'll recheck dependencies

EDIT - 24.12.2014

I see that people keep coming to this question I decided to add a little something.
The answer I gave was for the case when you maintain your gems global. Consider using a gem manager such as rbenv or rvm to keep sets of gems scoped to specific projects.

This means that no gems will be installed at a global level and therefore when you remove one from your project's Gemfile and rerun bundle then it, obviously, won't be loaded in your project. Then, you can run bundle clean (with the project dir) and it will remove from the system all those gems that were once installed from your Gemfile (in the same dir) but at this given time are no longer listed there.... long story short - it removes unused gems.

Uninstall old versions of Ruby gems

# remove all old versions of the gem
gem cleanup rjb

# choose which ones you want to remove
gem uninstall rjb

# remove version 1.1.9 only
gem uninstall rjb --version 1.1.9

# remove all versions less than 1.3.4
gem uninstall rjb --version '<1.3.4'


Related Topics



Leave a reply



Submit