Yosemite Upgrade Changes Open File Limit

OSX has a ridiculously low limit on the maximum number of open files. If you use OSX to develop Node applications -- or even if you just use Node tools like grunt or gulp -- you've no doubt run into this issue.

To address this, I have this line in my $HOME/.bash_profile:

ulimit -n 1000000 unlimited

And a corresponding entry in /etc/launchd.conf:

limit maxfiles 1000000

That solved the problem until I upgraded to OSX Yosemite, after which I began seeing the following error every time I opened a terminal window:

bash: ulimit: open files: cannot modify limit: Invalid argument


Luckily, I a little Google foo yielded this Superuser post (and answer).

So it was a quick fix:

$ echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
$ echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -w kern.maxfiles=65536
$ sudo sysctl -w kern.maxfilesperproc=65536
$ ulimit -n 65536 65536    

Then I updated my $HOME/.bash_profile to change the ulimit directive to match that last command, above, and I was back in business.


  1. Hi, I need to increase maxfiles to use in an application that is not run from the shell. I wrote the sysctl.conf file, but it does not work on its own. Is there somewhere else I can place ulimit so that it will work? The previous solution you mentioned worked fine for me (I had a launchd.conf and a rc.local).


  2. No luck with reboot. Maxfiles are not updated when I look at launchctl maxfiles, even though the sysctl.conf is rewritten. Thanks anyway though!

  3. @RZ did you create a new launchd.conf with the correct changes in it? This is the file that controls maxfiles for non shell apps I believe. It’s omitted from the Yosemite instructions but I think is still required. Let us know if that works.

    Something I noticed is that even for a minor update (like 10.10.1 that I got today) both sysctl.conf and launchd.conf are wiped completely.

  4. @Pat, I thought I had solved the issue using the instructions on this website: http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X

    It says the file limit has been changed when I query it in terminal, but my application I’m trying to run does not actually reflect these “system wide” changes. I also have a sysctl.conf file with the “kern.” info. But I do not currently have a launchd.conf. I will give that a shot and see if it helps. Although if I have a LaunchDaemon to do this already, I’m not sure if the launch.conf file is necessary.

    Is it possible that specific applications do not use the system-wide changes? And if so, is there a script I could add to the program to allow it to accept the changes, or to change it only for the launch of the application?

    Thanks again!

  5. you need to put a “-a” (append) option to your 2nd tee command above or it overwrites the previous entry, should be:
    $echo kern.maxfiles=65536 | sudo tee /etc/sysctl.conf
    $ echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf

Comments are closed.