153

I recently started learning Ruby and Ruby on Rails, and have watched a plethora of getting started materials. I have been finding lately that I keep getting errors where gems won't install or they will be installed but they can't be used for some reason, and I have decided that I want to remove everything down to once again just having Ruby installed and start over with the installation. One training video had me install most of my gems with RVM, so I don't know if that changes anything.

So in short my question is "How to I get rid of RVM, Rubygems, and all installed Gems so that I can start over with just Ruby?"

Edit: I am on Mac OS 10.6

Dave Long
  • 9,569
  • 14
  • 59
  • 89

8 Answers8

176
gem uninstall -aIx

Uninstalls all gems without prompt.

Options

-a, --[no-]all                   Uninstall all matching versions
-I, --[no-]ignore-dependencies   Ignore dependency requirements while
                                 uninstalling
-x, --[no-]executables           Uninstall applicable executables without
                                 confirmation
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Pants
  • 2,563
  • 1
  • 20
  • 34
  • 5
    That gives me: `ERROR: While executing gem ... (Gem::InstallError) gist is not installed in GEM_HOME, try: gem uninstall -i /usr/share/rubygems-integration/all gist` – user2023370 Nov 02 '20 at 22:58
  • 5
    then you should do as it suggest. then after that, rerun `gem uninstall -aIx` again. repeat if error occured for other gem untill it finisehd – Zuzu Softman Jan 14 '21 at 14:56
  • 1
    That's what I did, I had to repeat those steps a few dozen times. Sometimes, the `gem` was complaining that I didn't have the right permissions for a directory: `ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/share/rubygems-integration/2.7.0/bin directory. ` In fact, the directory didn't exist: I just had to `mkdir` it and re-run the `gem` command. – Pierre Jun 18 '22 at 16:03
138

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
rastersize
  • 488
  • 3
  • 19
michaelmichael
  • 13,755
  • 7
  • 54
  • 60
  • 1
    I just ran that, but gems is still installed. It does however look like it reloaded it. Not sure if it reloaded with defaults from Mac XCode or what... – Dave Long Feb 05 '11 at 15:31
  • added another line to get rid of the gems you added pre-RVM – michaelmichael Feb 05 '11 at 15:39
  • 1
    I'd add the '-all -x -I' options to gem uninstall to prevent it from prompting you (for binaries, versions, or dependencies) while uninstalling. – timmfin Feb 25 '12 at 00:54
  • 5
    For reference, the full command is: for x in \`gem list --no-versions\`; do gem uninstall $x -a -x -I; done – Daniel Rehner Sep 18 '12 at 18:34
  • 9
    For more reference, another option: `gem list --no-versions | xargs gem uninstall -aIx` – trisweb Nov 20 '12 at 16:29
  • This actually works quite nicely with rbenv as well on Debian – konung Jun 13 '13 at 16:54
  • doing this gave me the following error once i ran it and ran bundle install: ``` ~/.rvm/gems/ruby-2.5.0@global/bin/bundle: No such file or directory``` – raingod Apr 28 '18 at 19:51
35

For Windows and Unix copy/paste in command prompt (Ruby 1.9.x).

ruby -e "`gem list`.split(/$/).each { |line| puts `gem uninstall -Iax #{line.split(' ')[0]}` unless line.strip.empty? }"
nalzok
  • 14,965
  • 21
  • 72
  • 139
Haris Krajina
  • 14,824
  • 12
  • 64
  • 81
  • 2
    `ERROR: While executing gem ... (Gem::CommandLineError) Please specify at least one gem name (e.g. gem build GEMNAME) -e:1: no . floating literal anymore; put 0 before dot bundle (0.0.1) ^ -e:1: syntax error, unexpected tINTEGER bundle (0.0.1) ^ ` – isomorphismes Feb 26 '13 at 21:14
  • @isomorphismes not sure if I have fixed it, but you can try command now. – Haris Krajina Mar 04 '13 at 09:41
29

using RVM, you could just type...

rvm gemset empty GEMSET

where GEMSET is the gemset which you would like to empty. then...

install bundle

yum install bundler and finally

bundle install
veer7
  • 20,074
  • 9
  • 46
  • 74
mfittko
  • 411
  • 4
  • 3
18

rvm implode (see cli docs) seems to work - and it even tells you where to look at for leftovers

chesterbr
  • 2,940
  • 3
  • 29
  • 26
  • 2
    This is technically the most correct answer and exactly what it was designed for. – mpowered Oct 22 '17 at 20:03
  • 2
    "implode - removes all ruby installations it manages, everything in ~/.rvm" – Nein May 21 '20 at 11:36
  • "implode does not uninstall the RVM itself. Basically, there is no way to automatically uninstall RVM other than manually cleaning up everything that the installation did to your system. And that’s a huge downside. The only way to uninstall RVM is to manually clean up everything it did to your system." source: https://duseev.com/articles/rbenv-vs-rvm/ NOTE: I'm a novice and unqualified to determine whether the advice in the article is accurate. – Mark Gavagan Nov 17 '20 at 21:08
  • 2
    @MarkGavagan I agree it does not do everything, but it will tell you what else needs to be done (what I refer to above as "leftovers"). In fact, that very article's step zero on uninstalling rvm is... `rvm impode` :-) – chesterbr Nov 23 '20 at 22:25
  • Does this have the same effect as `rvm gemset empty GEMSET`? – Ray Apr 14 '21 at 08:01
  • @Beyar I'm not super familiar with `rvm gemset`, but I think it won't remove the rvm tooling (including the `rvm` utility itself), nor the extra files that `rvm implode` will inform you about. – chesterbr Oct 06 '21 at 12:54
6
  1. This is work for me on Ubuntu 16.04. For me, when I was executing command rails -v it throw errors because of NameError. I have installed 3 version of rails (4.2.0, 4.2.6, 5.0.0.1). I was trying to uninstall unnecessary gem using command gem uninstall rails -v version number but I won't able to, but I find a way to solve this problem. In order to uninstall all gems, you have to loop through all entries in gem list with bash scripting. This method is very inconvenient. Thanks to Rubygems 2.1.0, you now could do it with one command.

    STEP - 1

    Firstly, please make sure you upgrade your Rubygems to 2.1.0 or newer. For this run this command (Incase you are working on an older version. You can check your gem version using this command any one of them gem -v or gem --version)

    gem update --system

    gem --version

    STEP - 2

    Run this command in you terminal

    gem uninstall --all

    Step - 3

    Install gem bundles (it is not necessary I think just for precautions) gem install bundle

    Step - 4
    Install the rails on your system using this command gem install rails -v specific version you want to install you can check the rails version on the official site rails all versions example :- I have installed rails 4.2.6 version, you install as per requirement. gem install rails -v 4.2.6

    Step - 5

    Finally check the version of installed rails framework application by Using basic command rails -v. It will echoed the current version of rails frameworks. Enjoy :)

    References

http://ruby-journal.com/how-to-uninstall-all-ruby-gems/ http://guides.rubyonrails.org/v4.1/getting_started.html

Mukesh Kumar Gupta
  • 1,567
  • 20
  • 15
4

Step 1:

I first kept running into an error that said:

You don't have write permissions for the /usr/bin directory

To get permission, I became a root user with (this is potentially dangerous for reasons beyond my current understanding):

sudo -s

Credit

Step 2:

Then, I kept running into an error that said:

[gem] cannot be uninstalled because it is a default gem

This allowed me to uninstall everything:

for i in `gem list --no-versions`; do gem uninstall -aIx $i; done

Credit

Community
  • 1
  • 1
John R Perry
  • 3,916
  • 2
  • 38
  • 62
1

FWIW, there are some weird cases where gems are installed but not really installed:

This should do the trick reasonably reliably.

gem uninstall -Iax `gem list  | grep default | awk '{print $1}'`
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
  • You might want to grep for `'default:'` instead (including the colon) since there are quite a few gems that include "default" in their name. – jox Dec 10 '21 at 11:17