Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
2  
You might want to look into RVM - The Ruby Version Manager - it allows you to have multiple ruby versions installed along with specific gemsets for different projects. rvm.beginrescueend.com –  barryj May 10 '11 at 14:02
1  
Do you really need to replace /usr/bin/ruby or are you open to alternatives like RVM or modifying the $PATH variable? –  bmike May 10 '11 at 19:57
    
Yes I need to replace the version of ruby that is currently installed on the system. This seems to be hard to do based on the answers I am getting. –  Binary X May 11 '11 at 4:03
    
I want to be sure you understand what you're saying. "Replace" Ruby is very different from "use a different version" of Ruby. If you want the latter, RVM would be a great option, as several have mentioned. If you are sure you want to replace the system's version of Ruby (and understand that may have negative consequences), then I explain how to do that at the bottom of my answer below. Either way, there should be plenty of information here to answer your question now. –  Austin May 11 '11 at 4:34
    
It's seems that RVM is the way to go rather than replacing the system version of ruby. Thanks everyone for your input. –  Binary X May 11 '11 at 4:40
add comment

5 Answers

up vote 10 down vote accepted

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
share|improve this answer
    
+1 Using RVM to manage my Ruby installations and gemsets has changed my life. Whenever an incompatibility or conflict has cropped up, I'm back up and running in minutes. –  ghoppe May 10 '11 at 15:11
    
+1 This would probably be a great option for you. –  Austin May 10 '11 at 16:12
    
Although I love RVM - this doesn't answer the question posed. The OP already has the ruby he wants compiled and seems intent on not using $PATH to let them coexist. –  bmike May 10 '11 at 17:20
1  
@bmike Where does the OP voice that intent? I don't see it. I disagree with your interpretation of what it means to answer a question on StackExchange. Giving advice, presenting alternatives, and outlining best practices are valid answers as well if they address the asker's need, which in this case is to install the latest version of Ruby on Snow Leopard. –  michaelmichael May 10 '11 at 17:41
    
I agree RVM is the best way to maintain a non standard ruby. But unless the question gets edited (which hopefully will happen to make the question more usefully match your great answer) I don't see how "use RVM" best answers the question "how do I replace /usr/bin/ruby at 1.8.7 with /usr/local/bin/ruby at 1.9.2?" What if the OP has scripts hard coded to call /usr/bin/ruby? Does RVM step in there to assist? –  bmike May 10 '11 at 19:56
add comment

The way to get any self installed program to be found befiore 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

share|improve this answer
    
This is better IMHO than replacing the binaries as the OP asks. –  bmike May 10 '11 at 17:21
add comment

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.

share|improve this answer
2  
Overwriting system components is usually a bad idea. There can be other applications depending on /usr/bin/ruby being the Apple supplied ruby. –  Bavarious May 10 '11 at 4:28
    
@Bavarious I think the chances of that are very slim for ruby on OS X (it would be different if we were talking about making a major change like PHP4 to PHP5). But you're right that it's generally a Bad Idea, which is why I mentioned it last. I presume there's a reason this user prefers 1.9.2 over 1.8.7 or they wouldn't be asking this question -- the potential benefits of running the latest version probably outweigh the tiny risk of breaking something because it was upgraded to the next minor version. –  Austin May 10 '11 at 4:39
    
are you certain the risk is "tiny"? Managing Ruby with RVM is so much easier and safer. –  ghoppe May 10 '11 at 15:09
    
@ghoppe I say the risk is "tiny" because you're not likely to break any important, core system functionality on OS X by upgrading Ruby. Could it cause some quirkiness in a small corner of your system somewhere that's hard to troubleshoot? Maybe. Ultimately, the main headache would probably be maintenance related if he plans to update Ruby frequently. You're definitely right that RVM would be a good option, and much preferable to changing system files. –  Austin May 10 '11 at 16:10
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.