How to create symbolic links in /usr/bin on a Mac?

Environment: OSX Sierra, Darwin Kernel Version 16.3.0

Root Problem: I want to use a bunch of shell scripts in a central repository, which have a #!/usr/bin/zsh. On my Mac, the zsh is in /bin/zsh.

Attempted solution: I want to create a symbolic link

ln -s /bin/zsh /usr/bin/zsh

My user account has admin rights, but I am not root, and I would prefer not to enable the root user on this Mac. Therefore I first did a

sudo su

to get a shell with root privileges and then executed the ln command. However I still get the error message ln: /usr/bin/zsh: Operation not permitted.

Questions:

  • Why do I get this error message?

  • What would have I to do to create the link?

  • Is there a better way to achieve my original goal? Note that fixing the #! lines is not an option.


You get this message because of Apple's System Integrity Protection. System Integrity Protection includes protection for these parts of the system:

/System
/usr
/bin
/sbin
Apps that are pre-installed with OS X

Paths and apps that third-party apps and installers can continue to write to include:

/Applications
/Library
/usr/local

This means that you can simply create a symbolic link in /usr/local/bin (it's still in your $PATH).

BUT, it seems that you specifically need to create the symbolic link in /usr/bin. You can achieve it by disabling System Integrity Protection (please don't do it, just edit the scripts..). You can disable it by (I haven't tested it myself!!!):

Click the  menu.
Select Restart...
Hold down command-R to boot into the Recovery System.
Click the Utilities menu and select Terminal.
Type csrutil disable and press return.
Close the Terminal app.
Click the  menu and select Restart....