Ran into the same problem tonight as this question from SO that wasn't fully answered.

I'm trying to uninstall an old installation of MacPorts, and run into SIP:

mybox:~ me$ sudo rm -rf /opt/local
rm: /opt/local/var/macports/home/Library/Preferences: Operation not permitted
rm: /opt/local/var/macports/home/Library: Operation not permitted
rm: /opt/local/var/macports/home: Operation not permitted
rm: /opt/local/var/macports: Directory not empty
rm: /opt/local/var: Directory not empty
rm: /opt/local: Directory not empty

According to the original question, the answer seems to involve SIP… but why has SIP decided to protect this (empty) directory?

EDIT: Here's the results of ls -a in the directory:

./ ../

And here's the results of ls -leOd /opt/local/var/macports/home/Library/Preferences:

drwxrwxrwx  2 root  wheel  - 64 Nov  8 19:45 /opt/local/var/macports/home/Library/Preferences/


EDIT 2018-11-12:

Here's the results of ls -laeO@ /opt/local/var/macports/home

drwxr-xr-x  3 root  wheel  - 96 Nov  8 19:42 ./
drwxr-xr-x@ 3 root  wheel  - 96 Nov  8 19:45 ../
    com.apple.FinderInfo    32 
drwxr-xr-x  3 root  wheel  - 96 Nov  8 19:42 Library/

EDIT 2018-11-13:

Here's the results of xattr -l /opt/local/var/macports

00000000  00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  |........@.......|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
  • are you sure it is empty or does it has hidden files
    – Ruskes
    Nov 9, 2018 at 2:15
  • There are a number of possible causes for this error. Check the directories' access control list (ACL) and flags with e.g. ls -leOd /opt/local/var/macports/home/Library/Preferences. If that lists a "restricted" flag, the directory of protected by SIP. There are a number of other flags that might forbid deletion; see man chflags for a partial list of them. I don't think an ACL could have this effect, but it doesn't hurt to check that as well. You can add the results to your question by editing it (note: please use code format, as you did for the original errors). Nov 9, 2018 at 2:30
  • 1
    @Wowfunhappy I'm actually more interested in learning what's going on than in solving the problem. Nov 9, 2018 at 5:04
  • 1
    One other thing occurs to me: is there an actual user account that .../macports/home is the home directory for? If so, it might be some weird effect of the new privacy protection feature in Mojave. Try granting the Terminal app access in Security & Privacy preferences -> Privacy tab -> Application Data (see here), and then see if you can delete them. Nov 14, 2018 at 3:41
  • 1
    @GordonDavisson That did it. I also looked up the users with dscacheutil -q user and found a user named "macports" with /opt/local/var/macports/home as its home directory. Bizarre. Thank you! Nov 15, 2018 at 6:02

2 Answers 2


The directory is SIP-protected because it is the home directory for a macports user, presumably created as part of the MacPorts installation process.

The best solution is to first remove that user account, following the instructions in this accepted answer to another AppleSE question. You may also wish to remove the corresponding macports group that also exists.

Specifically, the following commands will remove the user and group:

sudo /usr/bin/dscl . -delete "/Users/macports"
sudo /usr/bin/dscl . -delete "/Groups/macports"

The MacPorts website uninstall page mentions deleting the user and group but does not note that it is necessary due to SIP-protection to do this before deleting the folders. I think they also have an error in the syntax of their dscl command.

Once you have done that, you should be able to sudo rm -rf /opt/local successfully.

Significant credit for this answer is due to @GordonDavisson for providing 90% of the solution in comments, some months ago.

  • delete: Invalid Path <dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)
    – Dr.jacky
    Feb 14, 2023 at 22:37

Try one of the following

o You are not the owner of the directory

ls -ld /path/to/directory

o You do not have permissions to remove the directory name from the parent directory

o The directory or it's parent has an ACL that is preventing you from deleting the directory

ls -ldeO@ /path/to/directory

ls -ldeO@ /path/to/directory/..

chmod to mess with ACLs

o The directory or its parent has 'uchg' or 'schg' flag

ls -ldeO@ /path/to/directory

ls -ldeO@ /path/to/directory/..

chflags to mess with flags.

and finally this sudo chflags -R nouchg <parent>

  • Op ran the command under sudo so does not matter who is the owner.
    – mmmmmm
    Nov 9, 2018 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .