How to recreate /usr/local with SIP/rootless mode on El Capitan? With rootless mode enabled (a.k.a System Integrity Protection) it turns out you can remove /usr/local but cannot recreate it:

$ sudo rm -rf /usr/local
$ sudo mkdir /usr/local
mkdir: /usr/local: Operation not permitted


How to (re)create /usr/local or any such folder?
/usr/local has been both re-creatable and writable on El Capitan since 2015-10-21 when Apple released /System/Library/Sandbox/Compatibility.bundle version 12 in software update 031-40358 patching 10.11 and 10.11.1, and installed as part of the 10.11.2 update, 10.11.2 combo update, and 10.11.2 clean installs. You do not need to do anything special unless you have not updated to the latest point release of El Capitan.

A patched system will have compatibility bundle greater than or equal to 12 and show

iMac-TMP:~ joe$ grep /usr/local /System/Library/Sandbox/rootless.conf 
*               /usr/local
iMac-TMP:~ joe$ grep /usr/local /System/Library/Sandbox/Compatibility.bundle/Contents/Resources/paths
/usr/local
iMac-TMP:~ joe$ defaults read /System/Library/Sandbox/Compatibility.bundle/Contents/Info.plist CFBundleVersion
12.0
iMac-TMP:~ joe$


An unpatched system will have compatibility bundle less than 12.0 and not have the /usr/local entry in /System/Library/Sandbox/Compatibility.bundle/Contents/Resources/paths.