Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I switch to ruby 1.9.3 installed using Homebrew?

I have installed ruby 1.9.3 using hombrew

brew install ruby

But default 1.8.7 is still used. How can I switch osx to use 1.9.3 as default ruby?

like image 736
Alexey Zakharov Avatar asked Jan 04 '12 16:01

Alexey Zakharov


People also ask

How do I switch between Ruby versions on a Mac?

Set Ruby version with rvm on Mac 0 on the command line. To switch to the system ruby, enter rvm use system . To switch back to the default, rvm default . The command rvm list will show all installed Rubies, including the current and default versions.

How do I run a specific version of Ruby?

Selecting a version of Ruby You'll need to install bundler 1.2. x or above to use the ruby keyword and bundler 1.13. x or above to use a Ruby version specifier. You can use the ruby keyword in your app's Gemfile to specify a specific version of Ruby.

How do I install Ruby 1.9 3 on Windows?

Install Ruby.In the Windows Explorer, double click on the rubyinstaller-1.9. 3-p194.exe file and follow the directions. By default, Ruby will be installed in the C:\Ruby193 folder. Check the boxes "Install Tcl/Tk support" and "Add Ruby executables to your PATH." Then click Install >> Finish.


2 Answers

I suggest you take a look at rvm. You can then set it as default with rvm use 1.9.3 --default

But if you are happy with your homebrew install.

Then just change the precedence of directories in the PATH

Here is my /etc/paths

# homebrews should always take precedence /usr/local/bin  # the default stack /usr/bin /bin /usr/sbin /sbin 

This is important generally for homebrew, else the system version of git, ruby, pg_admin,... will all be used instead of the brew version.

if you say which -a ruby you'll see all the installed rubies, and the precedence in the PATH

eg.

$ which -a ruby /Users/matthew/.rvm/rubies/ruby-1.9.3-p0/bin/ruby /Users/matthew/.rvm/bin/ruby /usr/bin/ruby 


UPDATE: I now don't think you should change /etc/paths

Instead you need to check which of .profile, .bashrc, or .bash_login is being loaded in your shell, and just add /usr/local/bin to your path.

For me, I only have a .profile. You can create that file if none of those files already exist in your home directory.

# homebrews should always take precedence export PATH=/usr/local/bin:$PATH 
like image 97
Matthew Rudy Avatar answered Oct 13 '22 20:10

Matthew Rudy


SHORT ANSWER:

after installing ruby via homebrew just do this:

brew link --overwrite ruby 

and restart or reopen your Terminal  


LONG ANSWER

So I did a normal install of ruby using homebrew

brew install ruby 

that installed fine BUT it was still using the system's default ruby. which I verified by doing:

which ruby  #/usr/bin/ruby 

So as per Matthew Rudy's suggestion, I checked the order of my /etc/paths, and all was good.

Then I decided to do:

which -a ruby #/usr/bin/ruby #usr/local/bin/ruby 

so nothing was broken as such. tried to reinstall ruby again using the homebrew method, and then i found it.

Homebrew mentioned:

Warning: ruby-2.3.1 already installed, it's just not linked 

so had to do:

brew link --overwrite ruby 
like image 44
Craig Wayne Avatar answered Oct 13 '22 20:10

Craig Wayne