How to disable Swapfile in OS X El Capitan

I've tried these commands in OS X El Capitan, but it doesn't work:

$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

$ sudo rm /private/var/vm/swapfile*

$ sysctl vm.swapusage
vm.swapusage: total = 2048.00M  used = 596.00M  free = 1452.00M  (encrypted)

I have 16GB of RAM and 256GB SSD, I just don't want the SSD to tear down faster just because I enable the swapfile.


Solution 1:

El Capitan has its System Integrity Protection system, which you must disable before you can touch some OS inner workings, such as swap.

You'll need to reboot your Mac in Recovery Mode (holding Command+R at boot time). Open Terminal as root, then disable System Integrity with:

csrutil disable

Now you can disable swap.

After all done, you should enable System Integrity again using:

csrutil enable