in OS X 10.4 to macOS sierra 10.12 and maybe higher!
Copy this entire code block and paste it into your terminal and push Return to create this file for you with correct permissions. It will (probably) ask for your password:
cat <<EOM|sudo tee /Library/LaunchDaemons/limit.maxfiles.plist > /dev/null 2>&1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>524288</string>
<string>524288</string>
</array>
<key>RunAtLoad</key>
<true />
</dict>
</plist>
EOM
To activate this launcher without rebooting:
-
Run the following command
$ sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
-
At least log out of your current shell and open a new one
-
On the more extreme side of things, close and re-open your terminal application.
-
At the very most, restart your computer if you still haven't had luck. 😉
There are three different things you should check (thus adding to the overall confusion of this process)
-
launchctl limit maxfiles
$ launchctl limit maxfiles maxfiles 524288 524288
Both values should be
524288
(these are the 'soft' and 'hard' limits) -
sysctl kern.maxfiles kern.maxfilesperproc
$ sysctl kern.maxfiles kern.maxfilesperproc kern.maxfiles: 524288 kern.maxfilesperproc: 524288
Again, both should be
524288
! -
You must open a new terminal for this!:
ulimit -n
$ ulimit -n 524288
The value returned should be
524288
! If it's not, proceed to "Troubleshooting" below. If it is524288
, then you're all done!
Permissions on the /Library/LaunchDaemons/limit.maxfiles.plist
file are very important. If you used these instructions, they should be correct by default, but make sure it is owned by user root
and group wheel
and umask 0644 (i.e. -rw-r--r-- root:wheel
when you do ls -l
on it)
$ sudo chmod 0644 /Library/LaunchDaemons/limit.maxfiles.plist
$ sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
There has never been an officially recommended way of doing this and Apple has randomly changed the way it could be done throughout the years. If you're still finding that the ulimit -n
is not returning the proper value, you should check some other places where it may be misconfigured. This should fix the problem for you, but sometimes old files may be getting in the way.
Make sure to remove any other sysctl
commands involving maxfiles
or maxfilesperproc
and any ulimit -n <blah>
commands that you may have in:
- /etc/sysctl.conf
- /etc/launchd.conf
- /etc/profile
Additionally, check your shell profile settings:
- /Users/YOUR_USERNAME/.bash_profile
- /Users/YOUR_USERNAME/.bashrc
- /Users/YOUR_USERNAME/.zshrc
- /Users/YOUR_USERNAME/.zshenv
- /Users/YOUR_USERNAME/.profile
This is excellent - thanks for putting this together!