Cannot create a symlink inside of /usr/bin even as sudo

egidra picture egidra · Apr 20, 2016 · Viewed 74.9k times · Source

When I try to symlink a binary in my /usr/bin folder, I get an Operation not permitted error:

 sudo ln -s /usr/bin/python2.7 /usr/bin/python2
ln: /usr/bin/python2: Operation not permitted

Even as sudo, I get this error.

Answer

Gordon Davisson picture Gordon Davisson · Apr 20, 2016

Why can't I symlink into /usr/bin?

El Capitan's new System Integrity Protection feature prevents changes to several core parts of OS X, including most of /usr/, even by root.

How can I still add executable files to my path?

Local customizations, such as what you're doing, belong in /usr/local instead. The path /usr/local/bin doesn't exist by default, but you can create it and put custom binaries (and symlinks) in it:

sudo mkdir -p /usr/local/bin
sudo ln -s /usr/bin/python2.7 /usr/local/bin/python2

Note that while /usr/local/bin doesn't exist by default, it is in the default PATH, so as soon as you create it, it'll be searched for commands.

Disabling SIP

It's also possible to disable System Integrity Protection, but it's generally best to leave it on and do customization in more appropriate locations. An Apple Stack Exchange question has more details on this: What is the Rootless Feature in El-Captain, really?.