35

Everything was working fine , until we decided to upgrade ruby to 1.8.7 from 1.8.6, and thats when all hell broke loose. When we compiled Ruby 1.8.7 from source it got installed into /usr/local/bin and Ruby 1.8.6 stayed in /usr/bin. Currently, we've uninstalled ruby 1.8.6 and by some stroke we deleted the ruby 1.8.7 files from /usr/local.

when we try "which ruby" it points to /usr/local. If anybody could help us out what we need to do get back on track , we would be very grateful.and also any idea how we can uninstall ruby from /usr/local. we tried yum remove ruby , which removed ruby from /usr/bin.Thanks and Cheers !

Shreyas
  • 8,737
  • 7
  • 44
  • 56

6 Answers6

23

It's not a good idea to uninstall 1.8.6 if it's in /usr/bin. That is owned by the OS and is expected to be there.

If you put /usr/local/bin in your PATH before /usr/bin then things you have installed in /usr/local/bin will be found before any with the same name in /usr/bin, effectively overwriting or updating them, without actually doing so. You can still reach them by explicitly using /usr/bin in your #! interpreter invocation line at the top of your code.

@Anurag recommended using RVM, which I'll second. I use it to manage 1.8.7 and 1.9.1 in addition to the OS's 1.8.6.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
22

Edit: As suggested in comments. This solution is for Linux OS. That too if you have installed ruby manually from package-manager.

If you want to have multiple ruby versions, better to have RVM. In that case you don't need to remove ruby older version.

Still if want to remove then follow the steps below:

First you should find where Ruby is:

whereis ruby

will list all the places where it exists on your system, then you can remove all them explicitly. Or you can use something like this:

rm -rf /usr/local/lib/ruby
rm -rf /usr/lib/ruby
rm -f /usr/local/bin/ruby
rm -f /usr/bin/ruby
rm -f /usr/local/bin/irb
rm -f /usr/bin/irb
rm -f /usr/local/bin/gem
rm -f /usr/bin/gem
Mukesh Singh Rathaur
  • 12,577
  • 2
  • 23
  • 24
  • 40
    It is *REALLY* important to find out what OS and version this is running on, before suggesting someone remove Ruby from `/usr`. Apple includes Ruby in Snow Leopard and has code calling it from apps. Deleting those will break the apps silently. If it is a Linux system, and Ruby was installed via a package-manager, then that should be used to remove the files. And, in either case, using something like RVM can negate the need to delete a pre-installed Ruby at all. – the Tin Man Jan 20 '11 at 20:19
  • 18
    Sadness ensues if someone copy/pastes that chunk of rm commands. Don't copy/paste without reading kids. – sclarson Jan 07 '13 at 21:23
  • 4
    While removing ruby don't forget to remove also other ruby-related stuff like `erb`, `gem`, `irb`, `rake`, `rdoc`, `ri`, `testrb` (for me in `/usr/local/bin`). – reallynice Oct 30 '13 at 11:49
5

Create a symlink at /usr/bin named 'ruby' and point it to the latest installed ruby.

You can use something like ln -s /usr/bin/ruby /to/the/installed/ruby/binary

Hope this helps.

Paco
  • 4,520
  • 3
  • 29
  • 53
intellidiot
  • 11,108
  • 4
  • 34
  • 41
  • Did you mean /etc/bin/ruby or /usr/bin/ruby? Also, there are additional ruby-related names that need to be linked such as irb, rdoc, etc. – the Tin Man Apr 07 '10 at 20:07
  • Greg,my bad... You pointed it correctly, it's /usr/bin/ruby, just like the first line. I'll correct it. Thanks :-) – intellidiot Apr 08 '10 at 06:04
  • I'm going to suggest NOT doing any links in `/usr/bin` to other versions of Ruby if the OS installed Ruby in `/usr/bin` by default. On Apple's Snow Leopard, Apple is now installing code that uses Ruby 1.8.7 which is preinstalled in `/usr/bin`. Messing with that could cause subtle bugs/failures down the road in that app or any that come along later. Any more I think it's better to use RVM to manage sandboxed Rubies or install into `/usr/local/bin` or maybe somewhere under `/opt/` and adjust your path; Put it somewhere the system won't assume to look. – the Tin Man Jan 07 '11 at 22:30
2

If ruby was installed in the following way:

./configure --prefix=/usr/local
make
sudo make install

You can uninstall it in the following way:

Check installed ruby version; lets assume 2.1.2

wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2
bunzip ...
tar xfv ...
cd ruby-2.1.2
./configure --prefix=/usr/local
make
sudo checkinstall
  # will build deb or rpm package and try to install it

After installation, you can now remove the package and it will remove the directories/files/etc.

sudo rpm -e ruby # or dpkg -P ruby (for Debian-like systems)

There might be some artifacts left:

Removing ruby ...
  warning: while removing ruby, directory '/usr/local/lib/ruby/gems/2.1.0/gems' not empty so not removed.
  ...

Remove them manually.

Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81
1

sudo make uninstall did the trick for me using the Ruby 2.4 tar from the official downloads page.

max pleaner
  • 26,189
  • 9
  • 66
  • 118
-2

do this way :

sudo apt purge ruby
Luan D
  • 1,320
  • 1
  • 13
  • 26