Dave
Dave

Reputation: 19130

How do I get /usr/bin/ruby to point to the right version of Ruby on my Mac?

I’m using Ruby 2.3 (I think) on Mac Sierra. How do I make /usr/bin/ruby point at the correct version of Ruby? I reinstalled version 2.3.0 (the one I want to use) through rvm and set it as the default, but still no love …

localhost:~ davea$ rvm use 2.3.0 --default
Using /Users/davea/.rvm/gems/ruby-2.3.0
localhost:~ davea$ /usr/bin/ruby --version
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

The reason I need this version is that its used for Rails 5 and I need to tell passenger the path of where Ruby is installed.

Upvotes: 2

Views: 6861

Answers (2)

7stud
7stud

Reputation: 48599

In this line:

localhost:~ davea$ /usr/bin/ruby --version

You are telling your shell to go to the directory /usr/bin, and output the version of the ruby command that is located there. But rvm does not use that directory for the ruby versions that it manages.

If you want to see what version of ruby that rvm is currently using, issue the command:

localhost:~ davea$ ruby --version

Backing up for a minute, when you issue any command on the command line, the command is looked up in the directories specified in the $PATH environment variable--in the order they are listed--until the command is found. You can examine those directories by doing this:

localhost:~ davea$ echo $PATH

rvm works by adding directories to and removing directories from the front of the $PATH environment variable so that the ruby command is first found in an rvm directory.

To see where the ruby that rvm is using is located, you can do this:

localhost:~ davea$ which ruby
/Users/7stud/.rvm/rubies/ruby-2.3.0/bin/ruby

And if you use rvm to switch the ruby version:

~$ rvm list

rvm rubies

   ruby-1.9.3-p194 [ x86_64 ]
   ruby-1.9.3-p551 [ x86_64 ]
   ruby-2.2.1 [ x86_64 ]
=* ruby-2.3.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

~$ rvm use 2.2.1
Using /Users/7stud/.rvm/gems/ruby-2.2.1

~$ ruby --version
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]

~$ which ruby
/Users/7stud/.rvm/rubies/ruby-2.2.1/bin/ruby

If for some reason /usr/bin/ruby is hardcoded into Passenger, then you can create a link from /usr/bin/ruby to any ruby version installed on your computer. First, you might want to save the current ruby command:

/usr/bin$ sudo mv ./ruby ./ruby-orig
/usr/bin$ sudo ln -s /Users/7stud/.rvm/rubies/ruby-2.3.0/bin/ruby ./ruby
/usr/bin$ ls -al ./ruby
lrwxr-xr-x  1 root  wheel  44 Dec 29 17:04 ./ruby -> /Users/7stud/.rvm/rubies/ruby-2.3.0/bin/ruby

Also see: https://www.phusionpassenger.com/library/indepth/ruby/multiple_rubies.html

And: https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_ruby

That latter seems to indicate that you can use an rvm path.

Upvotes: 1

Camden Narzt
Camden Narzt

Reputation: 2003

When the correct ruby is set using rvm, run passenger-config about ruby-command to find out what to set PassengerRuby to.

Source: https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/#determine_ruby_command

Upvotes: 0

Related Questions