macOS 10.15 Terminal - unlink gets "Operation not permitted"
Asked Answered
S

2

2

zsh; Terminal has Full Disk Access permission in System Preferences.

/usr/bin % ls -alF python
lrwxr-xr-x  1 root  wheel  75 Jul 12 11:48 python@ -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/usr/bin % sudo unlink python
Password:
unlink: python: Operation not permitted
/usr/bin % 

EDIT by OP to add this terminal transcript:

~ % whence python
/usr/bin/python
~ % echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/brec/.rvm/bin
~ % ls -alF /usr/local/bin/python
lrwxr-xr-x  1 brec  admin  24 Dec 11 10:45 /usr/local/bin/python@ -> /usr/local/bin/python3.8
~ % python

WARNING: Python 2.7 is not recommended.

NOTE: /usr/local/bin/python3.8 does not exist.

Stability answered 11/12, 2020 at 20:12 Comment(9)
This is likely an issue with the root file system being mounted read-only, which renders individual file permissions moot.Turoff
@Turoff If that's the issue, how would I re-target the symlink?Stability
Maybe try and sudo chown the symlink.Chlamydeous
chown: python: Operation not permitted :(Stability
You don't. Leave system-installed stuff alone. Put the directory containing the version you want to use in your PATH variable ahead of /usr/bin, or use virtual environments.Turoff
Thanks @chepner. My PATH starts with: /usr/local/bin:/usr/local/sbin:/usr/bin and /usr/local/bin/python is a symlink to /usr/local/bin/python3.8. But whence python returns /usr/bin/python which is a symlink to a python2.7. alias returns no alias for python. Why does the python command resolve to /usr/bin/python ?Stability
@Stability : I think this is a Catalina issue. Apple provides at least since Mojave the MacOS in a way, that even root can not do everything in /usr/bin.Alwyn
If whence python return /usr/bin/python, then either PATH isn't what you think it is, your shell's path cache needs to be refreshed, or python isn't installed in /usr/local/bin.Turoff
@Turoff please see the terminal transcript I added to the question.Stability
C
3

On recent macOS versions, System Integrity Protection (SIP) prevents modification of files in several locations, including /usr/bin. Because some parts of macOS use Python, you cannot modify the symlink at /usr/bin/python - if you did, it might break some parts of the OS which depend on that specific version of Python. You cannot modify SIP-protected files even as root.

Your best bet is to install a separate version of Python and make sure your PATH environment variable is set accordingly.

Caitiff answered 14/12, 2020 at 23:14 Comment(0)
S
0

I unlinked /usr/local/bin/python and then created a soft link /usr/local/bin/python to the version of python I want the python command to execute.

Stability answered 14/12, 2020 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.