How to Completely Wipe Rubygems Along with Rails etc

How to completely wipe rubygems along with rails etc

I've recently had to so just this. I had built up alot of cruft with my system installed ruby and gems and wanted to clean all that out and move everything over to run under rvm for various projects.

1. Clean up old and busted

First thing I did, before messing with rvm (or run rvm system to get back to the system ruby), was to remove all my gems:

gem list | cut -d" " -f1 | xargs gem uninstall -aIx

WARNING: this will uninstall all ruby gems. If you installed as root you may want to switch to root and run this.

2. Install new hotness

Now you can run gem list to see what is left.

Time to install rvm, I recomend blowing away your current install and reinstall fresh:

rm -rf $HOME/.rvm
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Now the real trick is to use gemsets to install rails 3, and this is easy if you follow Waynee Seguin's gist:

rvm update --head
rvm install 1.8.7
rvm --create use 1.8.7@rails3
curl -L http://rvm.beginrescueend.com/gemsets/rails3b3.gems -o rails3b3.gems
rvm gemset import rails3b3.gems

One difference is I use 1.8.7 since I have had issues with 1.9.2-head and RSpec, but 1.8.7 has been smooth.

Uninstall Rails 3 with dependencies?

if you're planning to upgrade to a newer version of rails, you can do:

sudo gem clean

or in newer versions

sudo gem cleanup

after the newer version has been installed, this uninstall All older versions of All your gems leaving only the latest version in your system.

Note: these days I use RVM gemset and/or bundler to manage my gems, if you're using RVM I find it's a lot simpler this way. For example you can create a new gemset for each project:

rvm gemset create project_name
rvm gemset use project_name
bundle install

anything goes wrong you can just delete the gemset and start again

rvm gemset delete project_name

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.

Do I have to manually uninstall all dependent gems?

As far as I know you're correct, there is not an easy way built-in to the gem command to do this.

However, you can check out gem-prune which can help clean up your gem repository after you've removed dm-core.

http://github.com/ddollar/gem-prune/tree/master

Resolve multiple versions of rubygems

I have a feeling that you might be using a different version of ruby than ruby gems is. Either that or ruby doesn't know where to look for your gems.

See the the gem installation guide to ensure your environment is configured to use gems.

If you're still having problems after following instructions, ensure that you haven't got multiple versions of ruby installed. In the event that there are multiple version of Ruby available, make sure your scripts are calling the same version of Ruby as gem is. This is done by comparing the gem environment listing for RUBY_EXECUTABLE against your scripts' shebang line. Double check to follow any symlinks, because most distribution based installations of ruby will symlink /usr/bin/ruby to /usr/bin/ruby1.8

You should also check that your gems were installed by the same user who is running the script.

If you ran gem install without root privileges the new gems will be installed in your home directory. If you're running a script that depends on these gems as another user. Those installed gems will not be found. However, there's no problems if your gems are installed by root and a different user is running scripts that requires those gems.

I experienced this problem while switching from Ruby to Ruby Enterprise Edition. I found that I had to install all my required gems again using REE's instance of gem.

How to remove RVM (Ruby Version Manager) from my system

There's a simple command built-in that will pull it:

rvm implode

This will remove the rvm/ directory and all the rubies built within it. In order to remove the final trace of rvm, you need to remove the rvm gem, too, if you installed that:

gem uninstall rvm

There may be elements left over from a Homebrew, Apt or DNF install of it that require removal as well. This depends on how you installed it in the first place. That clean-up step is optional, as RVM will no longer be involved in Ruby, but can help keep things organized.

If you've made modifications to your PATH you might want to pull those, too. Check your .bashrc, .profile and .bash_profile files, among other things.

You may also have an /etc/rvmrc file, or one in your home directory ~/.rvmrc that may need to be removed as well.

How to delete all data from all tables in Rails?

rake db:reset 

It recreates your table from migrations.

As suggested in the comments, a faster way to do it (but you have to add a new rake task) is:

namespace :db do
desc "Truncate all tables"
task :truncate => :environment do
conn = ActiveRecord::Base.connection
tables = conn.execute("show tables").map { |r| r[0] }
tables.delete "schema_migrations"
tables.each { |t| conn.execute("TRUNCATE #{t}") }
end
end

Response copied from: answer on SO.

How do I uninstall bundler on AWS (& difference btw local and system wide gems)

Quick fix:

$ cd /var/www/mheesen.cc/releases/20131206072125
$ sudo gem install bundler # Since "bundler is not installed in GEM_HOME"
$ sudo bundle install

Long fix:

It seems you have RVM installed as a system package, probably through sudo apt-get install rvm. If possible uninstall that and install it using RVM install guide. Do not install using sudo.

Steps:

# Uninstall system package RVM (in flavor of RVM user install method)
$ sudo apt-get remove rvm

# Don't edit your bashrc. RVM alone will attempt to setup your shell (2013)
$ \curl -sSL https://get.rvm.io | bash
$ source ~/.rvm/scripts/rvm

$ rvm requirements #=> will install gawk, g++, libreadline6-dev, etc...
$ rvm install 1.9.3
$ rvm use --default 2.0.0

You should enforce the ruby version to use within a .ruby-version file within your project's directory (commit this changes and deploy again) with this content:

$ vim .ruby-version
1.9.3

As a bonus you can completely replace old system ruby 1.8.7 with latest and greatest:

# Use this to replace old 1.8.7 on your system
$ git clone https://github.com/sstephenson/ruby-build.git
$ cd ruby-build
$ ./install.sh

$ ruby-build 2.0.0-p353 /usr/local

Notes on GEM_HOME and related:

GEM_PATH provides the locations (there may be several) where gems can be found

GEM_HOME is where gems will be installed (by default)

Therefore GEM_PATH should include GEM_HOME

How to reinstall a gem using bundler

First I did a gem q --L, the shortcut for gem query --local. It outputs me the all the local gems installed.

actionmailer (3.2.8, 3.2.6, 3.2.1, 3.1.0)
actionpack (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activemodel (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activerecord (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activeresource (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activesupport (3.2.8, 3.2.6, 3.2.1, 3.1.0)
acts-as-taggable-on (2.3.3)
...

And then, following DVG advice, I uninstalled the gem using its correct name gem uninstall acts-as-taggable-on and ran bundle install. After that I was able to rails c or rails s again without any problem.



Related Topics



Leave a reply



Submit