How to uninstall / remove Ruby Gems (on Ubuntu)?

First we need to find out the exact location that the Ruby installs it’s libraries. In the terminal program, You can type the following command to find out the exact location.
ruby -e 'puts $:'
You’ll get list of paths. This is the output that I got in my machine.
/usr/local/lib/site_ruby/1.8
/usr/local/lib/site_ruby/1.8/i486-linux
/usr/local/lib/site_ruby/1.8/i386-linux
/usr/local/lib/site_ruby
/usr/lib/ruby/vendor_ruby/1.8
/usr/lib/ruby/vendor_ruby/1.8/i486-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i386-linux
.
Next we need to change our directory in to /usr/local/lib/site_ruby/1.8 and type following command to list the files.
ls -la
drwxr-xr-x 5 root root   4096 2009-07-15 12:15 .
drwxr-xr-x 3 root root   4096 2009-07-15 12:14 ..
-rw-r--r-- 1 root root   1415 2009-07-15 12:15 gauntlet_rubygems.rb
drwxrwsr-x 2 root staff  4096 2009-07-15 12:14 i486-linux
drwxr-xr-x 2 root root   4096 2009-07-15 12:15 rbconfig
drwxr-xr-x 6 root root   4096 2009-07-15 12:15 rubygems
-rw-r--r-- 1 root root  29116 2009-07-15 12:15 rubygems.rb
-rw-r--r-- 1 root root    268 2009-07-15 12:15 ubygems.rb
Now we are ready to remove the gems. Type,
rm -r rubygems.rb ubygems.rb rubygems
If you wish to remove all gems installed in your computer, first find out the location by executing following commands
 which gem gem1.8
Next you can remove them by using following commands. That’s it!
rm -r /usr/local/bin/gem
rm -r /usr/bin/gem1.8
This entry was posted in Web Development and tagged , , , , , . Bookmark the permalink.

About me

Hello, there! I'm Aslam Najeebdeen, a web craftsman, a visionary, a Rubyist and founder of frontcube
  • http://gaveen.owain.org Gaveen

    Another good one, Aslam. :)

    A little addition here. If you wish to get rid of all the gems (or the complete Ruby installation), it is best to uninstall all the installed gems first. This is because some gems place executables outside the Ruby installation (Eg: directories within $PATH). So if you just delete the Ruby installation, these files become stale and might cause problems in future.

    You can find more information about your RubyGems environment by the command:
    $ gem env

    There we couple of more things in the case you are completely wiping a Ruby installation (Eg: to setup a new one). Unfortunately I cannot remember those. If I run into then again, I’ll comment here.

    Keep it up. :)

  • http://gaveen.owain.org Gaveen

    Another good one, Aslam. :)

    A little addition here. If you wish to get rid of all the gems (or the complete Ruby installation), it is best to uninstall all the installed gems first. This is because some gems place executables outside the Ruby installation (Eg: directories within $PATH). So if you just delete the Ruby installation, these files become stale and might cause problems in future.

    You can find more information about your RubyGems environment by the command:
    $ gem env

    There we couple of more things in the case you are completely wiping a Ruby installation (Eg: to setup a new one). Unfortunately I cannot remember those. If I run into then again, I’ll comment here.

    Keep it up. :)

  • http://mohamedaslam.com Aslam

    Thank you very much for your feedback Gaveen! :D

    Yeah! If can, please comment the exact steps. Waiting to read that!

  • http://mohamedaslam.com Aslam

    Thank you very much for your feedback Gaveen! :D

    Yeah! If can, please comment the exact steps. Waiting to read that!

  • chandima

    very good thing…i learned lot friom your posts…..all the best…

  • chandima

    very good thing…i learned lot friom your posts…..all the best…

  • http://laowise.com Sam Gilman

    Thanks, got those removed.

  • http://laowise.com Sam Gilman

    Thanks, got those removed.

  • pooja

    how to uninstall ruby 1.8 from ubuntu

    • http://mohamedaslam.com Aslam

      Open the terminal and type

      sudo apt-get uninstall ruby
  • pooja

    how to uninstall ruby 1.8 from ubuntu

    • http://mohamedaslam.com Aslam

      Open the terminal and type

      sudo apt-get uninstall ruby
  • eeiil

    if i uninstall rubygems, would ruby be also uninstalled?..or vice versa?

    • http://mohamedaslam.com Aslam

      Nope! Don’t worry. If you need to uninstall Ruby you want to do it manually.

      If you are going to try a new Gem version with a new version of Ruby, before uninstalling your system Ruby version, try RVM or Ruby Version Manger http://rvm.beginrescueend.com/ .

  • eeiil

    if i uninstall rubygems, would ruby be also uninstalled?..or vice versa?

    • http://mohamedaslam.com Aslam

      Nope! Don’t worry. If you need to uninstall Ruby you want to do it manually.

      If you are going to try a new Gem version with a new version of Ruby, before uninstalling your system Ruby version, try RVM or Ruby Version Manger http://rvm.beginrescueend.com/ .

  • Steve Hill

    Thank you Mohamed for helping me get rubygems uninstalled. I was getting a “undefined method” error when I ran the gem command and needed to uninstall and re-install. Thanks, Steve

  • Steve Hill

    Thank you Mohamed for helping me get rubygems uninstalled. I was getting a “undefined method” error when I ran the gem command and needed to uninstall and re-install. Thanks, Steve

  • Mx_grig

    I am having a lot problems with ruby on rails. I was able to install ruby on rails on ubuntu 10:10, but rails db:migrate cannot connect to mysql database.
    I installed all sorts in a bid to fix it. I am now trying to uninstall and start all over. How can I fix this?

    • http://mohamedaslam.com Aslam

      I assume that you are new to Rails. Follow these steps.

      1. You need to create the project with MySQL support.
      rails new myproject -d mysql

      2. Open up the database.yml file in the config directory and set the credentials for the MySQL database.

      3. Then you need to create the database. In this senario the database should be myproject_development. You can do this manually or by a rake task.
      rake db:create

      4. To test the connection type the following command in terminal.
      rake db:schema:dump

      If you didn’t get any error. Your application successfully configured with the database. Now you can run the migrations.

      Hope this helpful. If you get any problems, feel free to post them here. I’m glad to help.

      Happy Rails! :)

  • Anonymous

    Thanks, this is what I’m looking for!

  • Noogrub

    Thank you, Aslam. Concise and effective. Cheers!

  • Prince

    I have Ruby on Rails on Ubuntu 11.04 through RVM. I wanted to uninstall ROR because not only I got the wrong version of Ruby and Rails but also I was unable to get the dependencies so I followed someone’s direction from a video in Google to uninstall Rails,Rake…..but I still am unable to uninstall ROR. I followed your instructions bu I got ‘permission denied’ error after I found the list of files. Can you help me out please?

    • Jase

      U need to use sudo when you do this since  Ruby is a system program at original install.

  • Pingback: [reproduced] in Linux gem unloading

  • Mahwish Khan2010

    Aslam, i hav e an issue, i have installed ruby 1.8.7 at ubuntu 10.10 in VM machine but as i do ruby -v ,it shows ruby is not installed but as i reinstall it ,it shows,its already installed. what i have to do now, please help me ,i am a newbie at ubuntu as well as ruby

    • http://mohamedaslam.com Aslam

      Can you run following command in the terminal and comment the output here?

      ruby -e 'puts $:'
  • Sravaz18

    how to uninstall gems on windows7

    • Sawny

      gem uninstall the-gem