Instantly share code, notes, and snippets.

@abernix abernix/ Secret
Last active Feb 16, 2019

What would you like to do?

Raise Open File Limits in OS X

in OS X 10.4 to macOS sierra 10.12 and maybe higher!

Create Launcher Script:


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"
<plist version="1.0">
     <true />


To activate this launcher without rebooting, run:

$ sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist


There are three different things you should check (thus adding to the overall confusion of this process)

  1. launchctl limit maxfiles

    $ launchctl limit maxfiles
      maxfiles    524288         524288

    Both values should be 524288 (these are the 'soft' and 'hard' limits)

  2. sysctl kern.maxfiles kern.maxfilesperproc

    $ sysctl kern.maxfiles kern.maxfilesperproc
    kern.maxfiles: 524288
    kern.maxfilesperproc: 524288

    Again, both should be 524288!

  3. ulimit -n

    You must open a new terminal for this!

    $ ulimit -n

    The value returned should be 524288! If it's not, proceed to "Troubleshooting" below. If it is 524288, 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

Cleanup Old Configurations

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

In General

  • /Users/YOUR_USERNAME/.profile

This comment has been minimized.

Copy link

hwillson commented Nov 17, 2016

This is excellent - thanks for putting this together!


This comment has been minimized.

Copy link
Owner Author

abernix commented Nov 21, 2016

Thanks, @hwillson! I hope to eventually propose incorporating the 'troubleshooting' into automated checks when this line fails in meteor.

This document came as a result of me potentially being too authoritative with this not-super-tested and currently-abandoned script which was meant to do this all automatically for a user who I thought might be affected by it. They figured it out before I had them test it.

Sadly, Apple doesn't really have a "right" way documented to do this process, which has probably led to so many different recommended approaches. I like this LaunchDaemon approach most because:

  • It's at least a somewhat recommended way of changing the system by Apple.
  • Is at least somehow recognizable by other tools (sudo launchctl list, and some GUI tools).

This comment has been minimized.

Copy link

mimamuh commented Nov 22, 2016

@abernix Thx, saved my day!


This comment has been minimized.

Copy link

emenoh commented Jan 26, 2017

Had to restart for ulimit -n to report correct value


This comment has been minimized.

Copy link

zeroasterisk commented Feb 1, 2017

Excellent and very well documented solution - thanks!


This comment has been minimized.

Copy link
Owner Author

abernix commented Feb 16, 2017

@emenoh Thanks for reporting that peculiarity. I found that a new shell was sufficient, but absolutely mandatory as ulimit settings are set (once) when the shell parent process is created by the kernel and can only be lowered after that. Anyhow, glad the reboot still fixed it for you!


This comment has been minimized.

Copy link

timfulmer commented Feb 22, 2017

👍 on reboot for ulimit -n to report correctly, thanks @emenoh!


This comment has been minimized.

Copy link

derwaldgeist commented Jul 29, 2017

+1 for reboot for ulimit -n to report correctly. This should be added to the guide.

And thx @abernix for creating this guide. Just ran into that issue with Meteor 1.5 for the first time.


This comment has been minimized.

Copy link

daisy-ycguo commented Aug 20, 2018

+1 for reboot for ulimit -n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment