Reputation: 1489
I'm on macOS Sierra. I installed ruby 2.5 via macports (/opt/local/bin/ruby2.5). However, I also have ruby 2.0 sitting in /usr/bin/ruby -- not sure where that comes from -- its not a macports package. How can I get my system to use the newer ruby 2.5 system wide? When I try to remove/rename /usr/bin/ruby I get "Operation not permitted" even as super user.
Upvotes: 0
Views: 227
Reputation: 2998
/usr/bin
is Apple-land. You should not change it, and Apple has implemented a feature called "System Integrity Protection" (SIP) that actively prevents modification of files with this protection enabled, one of which is /usr/bin/ruby
. There are ways to disable SIP, but there are better alternatives to change the default ruby.
Instead, the general method to prefer specific versions of self-installed tools is to set $PATH
so that a folder under your control comes before /usr/bin
. MacPorts already does this by prepending /opt/local/bin
. However, MacPorts does not, by default, create a /opt/local/bin/ruby -> ruby2.5
symlink, because you might have multiple versions of Ruby installed and it would not know which one you want to make the default.
For this reason, MacPorts comes with a mechanism called port select
(see port help select
) that allows you to manage a /opt/local/bin/ruby
symlink. In your case, port select --list ruby
should show a list of choices, and sudo port select --set ruby ruby25
should make ruby2.5 the default. Note that Shells usually cache the lookup from a command name to the path that provides it, so this will only be effective after opening a new shell, or running hash -r
in the current one.
In the specific case of Ruby, there are also tools available to manage different versions of Ruby side-by-side, such as rbenv and rvm.
Upvotes: 2