Terminal – Adding Symlink to /usr/bin

symlinkterminal

I'm trying to add python3 to my path by adding a symlink but it's erroring and I'm not sure why.

/usr/bin $ sudo su
sh-3.2# ln -s /Library/Frameworks/Python.framework/Versions/3.7/bin/python3  /usr/bin/python3
ln: /usr/bin/python3: Operation not permitted

sh-3.2# whoami
root

sh-3.2# ls -la | head -n 2
total 139064
drwxr-xr-x  977 root   wheel     31264 24 Jul  2018 .

* Edit *

I have symlinked from /usr/local/bin/python3 so that's fine.

Best Answer

/usr/bin is, as a lot of directories installed by default, protected by SIP and can't be modified by any user. There are ways to disable SIP, but the better approach is to use the directories beneath /usr/local for user-installed things

sudo mkdir /usr/local/bin
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 /usr/local/bin/
sudo sh -c 'grep -q "/usr/local/bin" /etc/paths || echo "/usr/local/bin" >> /etc/paths'

The last line will make sure that /usr/local/bin is part of PATH for all shells started/Terminal tabs created after the line has been executed.