28

I have many rubies installed by ruby-install under ~/.rubies:

ls .rubies
ruby-1.9.3-p545 ruby-2.0.0-p598 ruby-2.1.3      ruby-2.1.5
ruby-2.0.0-p451 ruby-2.1.2      ruby-2.1.4      ruby-2.2.0

I want to uninstall one of the ruby installed by ruby-install, How do I do that?

Juanito Fatas
  • 9,419
  • 9
  • 46
  • 70
  • Are you using Linux? If yes, which distro? Are you using `rvm`, `rbenv` or any other ruby version manager? – Rael Gugelmin Cunha Dec 27 '14 at 12:59
  • 2
    Does it matter which OS? I use OS X and I don't use any tools except ruby-install and chruby. – Juanito Fatas Dec 28 '14 at 06:59
  • Yes, it matters a lot. While on Linux you can completely remove Ruby, Apple includes Ruby starting at Snow Leopard and has code calling it from apps. I've upvoted your question if the OS matters, because it's frequent and really important :) – Rael Gugelmin Cunha Dec 28 '14 at 11:52
  • 1
    I did not want to completely remove Ruby, just want to remove one version of Ruby installed by ruby-install. And I did not want to remove system Ruby. Sorry I did not state clearly from my question. I have updated my question. – Juanito Fatas Dec 28 '14 at 17:25

6 Answers6

25

Unfortunately appears that ruby-install just downloads and compiles Ruby, with no option to remove it, unlike RVM or rbenv.

So, probably you'll need to run some manual commands here to delete all installed files.

1. Locate it

Usually ruby-install will install rubies in ~/.rubies/ folder.

If you're not sure which ruby was installed using ruby-install, locate the file .installed.list, as it has a list of installed files during Ruby install. If you want to quickly locate it, just run locate .installed.list and you'll get a short list of them.

Then run a cat on the file located at the version you want to remove, to make sure which is the root folder for the ruby install you want to delete.

2. Remove it

Then you can just remove the folder where the target version is located.

If you want to remove ruby-1.9.3-p545, run:

rm -Rf ~/.rubies/ruby-1.9.3-p545
Rael Gugelmin Cunha
  • 3,327
  • 30
  • 25
  • 7
    You'll also need to clear out the installed gems as well. For me they are in `~/.gem/ruby/*`. – Schneems Dec 06 '18 at 22:28
  • And then to update the list of rubies that `chruby` reports, either open a new shell or run `source /usr/local/share/chruby/chruby.sh`. See https://github.com/postmodern/ruby-install/issues/135 – davew Jan 14 '20 at 15:48
5

Based on the responses in a feature request, the best way to remove older ruby versions is to go back to the src directory and run make uninstall or rake uninstall. By default, ruby-install uses $HOME/src/ruby-$version for unpacked sources of ruby versions during installation.

For example, removing ruby version 2.6.3:

cd $HOME/src/ruby-2.6.3/ && make uninstall

Unfortunately, even though this bug/request was opened in 2016, this feature is still not implemented in ruby-install.

If you've installed the ruby version using the default locations, then you should be safe by removing the specific subfolder within $HOME/.rubies/.

rm -rf $HOME/.rubies/ruby-2.6.3

It's worth noting that it may be necessary to manually remove any gems installed with that ruby version.

e.g.

rm -rf $HOME/.gem/ruby/ruby-2.6.3
ILMostro_7
  • 1,422
  • 20
  • 28
  • 1
    In my case a `gem update` corrupted my 2.7.2 version. Removing (`rm -rf`) the `~/.rubies/ruby-2.7.2` and `~/.gem/ruby/ruby-2.7.2` and then reinstalling with `ruby-install --src-dir ~/src/ruby-install ruby 2.7.2` worked for me. My setup: `Ubuntu 20.04`, using https://brew.sh for `ruby-install` and `chruby` installs – Richard Logwood Jan 16 '21 at 19:28
2

I had exactly the same problem with my lubuntu virtual machine! I went into the shell from the login screen (by pressing CNTR + ALT + F3) and checked the versions of ruby and gem:

ruby -v
gem -v

then I run sudo apt-get purge -y ruby as suggested by chad. It successfully removed both ruby and gem.

Then I rebooted with:

reboot

And I was able to log in normally again!

emelieh21
  • 21
  • 2
2

If you installed package 2.3x(+) and you need to uninstall it, there is an uninstall executable inside of the root directory. Go to C:/ and you'll see the ruby folder there, inside it there will be the unin.exe. This all depends on where you chose to install it.

eric323
  • 19
  • 1
1

You just remove where the ruby is.

For example, uninstall ruby that installed by ruby-install (default installation location is ~/.rubies):

rm ~/.rubies/ruby-2.2.0

If you see this kind of error after removed Ruby 2.2.0-preview2 and installed Ruby 2.2.0-p0 for example:

$ bundle -v
zsh: /Users/Juan/.gem/ruby/2.2.0/bin/bundle: bad interpreter:
     /Users/Juan/.rubies/ruby-2.2.0-preview2/bin/ruby: no such file or directory

You need to run

gem pristin --only-executables

Because whenever a ruby is updated or perhaps moved/named, due to RubyGems is generating explicit #!/path/to/ruby for all gem executables, will need to regenerate the gem bin stubs with the new path to the ruby executable.

Juanito Fatas
  • 9,419
  • 9
  • 46
  • 70
1

if you install soft by dpkg or yum, when to uninstall it, you also should use dpkg or yum to purge it.

for example, we want to unintall fcitx,

sudo apt-get purge -y fcitx

otherwise, the soft install manually, use configuration && make && make install , just remove the directory installed when you uninstall it.

for you example. just

rm -rf ~/.rubies/ruby-2.2.0

if you have doubts that is the target ruby remove clearly, just use find command to confirm.

find ~/ -name "ruby-2.2.0"

chad
  • 61
  • 5