简体   繁体   中英

Ruby on Mac OSX Sierra via Mac Ports

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.

/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM