Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

macos

symlink

ln

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.

like image 328
egidra Avatar asked Apr 19 '16 22:04

egidra


4 Answers

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

like image 173
Gordon Davisson Avatar answered Nov 08 '22 09:11

Gordon Davisson


I created the symbolic link for Sublime Text 3 in Mac OS High Sierra as

sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/

I was also trying to create the symbolic link in "/usr/bin" and was getting Operation Not Permitted.

Then I created the symbolic link in "/usr/local/bin" and there was not error. The symbolic link works fine. Just ensure that "/usr/local/bin" is in the path.

So, it seems the access to "/usr/bin" is restricted.

like image 40
Vineet Sharma Avatar answered Nov 08 '22 09:11

Vineet Sharma


Restart the system -> long press cmd + R.  select a terminal from utilities menu type the following command csrutil disable close terminal and restart system.

like image 44
kesavan Avatar answered Nov 08 '22 08:11

kesavan


  1. Create a symbolic link to psql in usr/bin (for mac only)
         command: sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/psql /usr/bin/psql 

if you are not able to create symnbolic link due to permission issue, it will be due to "csrutil".after disabling csrutil you can create symbollic link. Follow these steps to disable CSRUtill :

Restart your Mac. Before OS X starts up, hold down Command-R and keep it held down until you see an Apple icon and a progress bar. Release. This boots you into Recovery. From the Utilities(on the top bar)menu, select Terminal. At the prompt type exactly the following and then press Return: csrutil disable Terminal should display a message that SIP was disabled. From the  menu, select Restart.

like image 24
Srima Avatar answered Nov 08 '22 08:11

Srima