Monday, November 19, 2012

Uninstalling Ruby on Rails in Ubuntu Manually

Only do this if you installed RoR from Source.

It's playtime! Last week, I blogged how I was able to successfully install RoR from source despite several issues encountered. Now, I'm going to uninstall RoR manually. Most of you might think my previous adventure rendered some of my screws loose. Perhaps a little (hehe) but I assure you everything I type here is thoroughly tested so proceed at your own risk. ;)

I reason I have the guts to do crazy stuff is because I'm running Ubuntu in VM so I don't care much if I wreck numerous instances (which I did for the entire duration of my RoR installation journey) because I could easily reinstall Ubuntu. But this action has become tiring and very annoying. I admit I'm a newbie at both Ubuntu and Ruby and I'm doing this for educational purposes only. It's hitting two birds with one stone: I learn how to use Ubuntu (the terminal commands stuff) while experimenting on RoR installation.


According to Ruby homepage, there's three ways to install Ruby:

1) Compiling from Source 
    - We're done with this option.

2) Using third party tools (like rvm and rbenv)
    - I'm planning to use rvm for my next RoR installation attempt. If I'll have some spare time I might also use rbenv and maybe I'll do a post about which of the two is easier to use from a total beginner's perspective. Don't hold your breath though.

3) Using package management systems (like apt-get, aptitude and yum)
    - I'd read several articles/posts that warns against using this option (Ryan Bigg's guide comes to mind). I'm not going to push my luck and I'm going to follow their advice and be a good girl. After all they know what they're saying right?

This also translates that there are also three ways to uninstall Ruby: manually (refer to post below), using rvm (rvm uninstall version_number) and using apt-get (sudo apt-get purge ruby).



Without further ado, let's start.

The sequence we installed RoR last time was Ruby + RubyGems + Rails. We're going the opposite way in uninstalling: Rails (with dependencies) first, then RubyGems and Ruby.


To uninstall Rails + all dependencies:

gem list --no-version | xargs sudo gem uninstall -ax

I got this one-liner from James McGrath's post. If you want to know the meaning for each switch used, he explained it very well in his post.


To uninstall all gems except for one:

gem list --no-version | grep -v rails | xargs sudo gem uninstall -ax

This will uninstall all gems (Rails dependencies and other gems installed) except for Rails (remember Rails is also a gem).


To delete only the old versions:

gem clean


To uninstall specific gem:

sudo gem uninstall rails

This will uninstall Rails gem only.


To uninstall RubyGems and Ruby (in one sweep):

sudo rm /usr/local/bin/{ruby,irb,gem,testrb,erb}
sudo rm /usr/local/lib/libruby-static.a
sudo rm -r /usr/local/lib/ruby/


To check:

whereis ruby
whereis gem


1 comment: