Question

I downloaded and compiled the latest version of ruby 1.9.2 which was installed in /usr/local/bin/ruby, however the system officially recognizes /usr/bin/ruby which is only 1.8.7 which came installed on the machine. How can I get the new ruby into place?

In this instance I need to replace the ruby version and be able to use the updated version for command line work and rails development.

Was it helpful?

Solution

You should use RVM, the Ruby Version Manager. It allows multiple side-by-side installations of Ruby without affecting the system Ruby installation, which as another commenter pointed out can potentially be problematic (or at the very least, tiresome to maintain).

It allows you to quickly and easily install the latest patchlevel of Ruby, past Ruby versions, or even alternate implementations like JRuby, MacRuby, or Rubinius.

To install:

$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Once it's installed, setting 1.9.2 as the default is as simple as typing:

rvm default 1.9.2

And if you feel like switching back to 1.8.7 temporarily:

rvm use 1.8.7

OTHER TIPS

What do you mean by "get the new Ruby into place"?

If you are trying to run it from the command line using just the command ruby, the system will search each of the paths specified in /etc/paths in order until it finds a match. In Snow Leopard, the default /etc/paths file looks like this:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

So when you enter ruby at the command line, the system looks for /usr/bin/ruby first, finds it, and doesn't check the rest of the paths (so it never gets to /usr/local/bin/ruby). To confirm this, you can enter which ruby at the command line, and the system will print the path of the executable that it would use for that command.

If you want to run your newer version of Ruby from the command line, simply enter /usr/local/bin/ruby instead of ruby.

If you are using another program that is using Ruby indirectly, there's probably an option somewhere to specify the path to ruby.


EDIT: As a last resort, you can overwrite the built-in system version of Ruby with your newer version. Use the following commands, and enter your administrator password when prompted:

cp /usr/bin/ruby ~/Desktop/ruby_OLD
sudo cp /usr/local/bin/ruby /usr/bin/ruby

If something breaks, put it back with this command:

sudo mv ~/Desktop/ruby_OLD /usr/bin/ruby

As others have mentioned, though, using a tool like RVM to manage Ruby would be a better idea than upgrading the built-in installation.

If you truly want to replace the existing /usr/bin/ruby (which is simply a sym link to /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby ) just overwrite the existing file with the one you compiled being careful to match file permissions.

The reasons to not do this are many, but it's that simple given a literal interpretation of your question.

Most people change their path to include the newer ruby before the system one since that is simpler and less likely to break other things that depend on the installed version of ruby and associated dylib, gems, rdocs, and such remaining the same.

One of the benefits of homebrew and fink and RVM and MacPorts is that they help automate the staging to an alternate location and support modifying your path.

You can do the same with the ruby you have in /usr/local/bin by manipulating your path variable and using which -a ruby to double check your work afterwards.

The way to get any self installed program to be found before an Apple supplied ome is to add the directory of the new program (e.g. /usr/local/bin) to the fromt of the PATH environment variable.

If you are running ruby from the shell edit ~/.profile or if from a GUI ~/.MacOSX/environment.plist

You might want to take a look at Homebrew, which makes it easy to install the latest Ruby - brew install ruby is all you need - and many other packages without interfering with anything already on your system, to a location that's (almost certainly) already in your $PATH.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top