My rule-of-thumb approach to issues in terminal is to kill the process, quit terminal and restart my MAC. If that fails, I call an exorcist and retire to a safe distance and assume the recovery position. Recently I’ve occasionally been getting the following error when running “vagrant up”:

vagrant /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/safe_chdir.rb:25:in `chdir': Too many open files - getcwd (Errno::EMFILE)

This morning I decided to ignore my rule-of-thumb approach and revert to approach two “google the error and hope that someone already raised it on Stack Exchange, and that someone else solved it”. Fortunately, they had, and, they had. Apparently Apple, in their infinite wisdom, decided to change the default ulimit to 256 somewhere along the line (OS X Maverick seems to be the general consensus). I’d love to climb into Apple for this (mainly because iTunes still irritates me on a daily basis), but I didn’t even know what a ulimit was until this morning (“ulimit provides control over the resources available to the shell and to processes started by it, on systems that allow such control” – for anyone who can’t be bothered to google it like I just did).

So fixing the issue is simple. Just change your ulimit to 1024 in your bash_profile.

Simple if you know where your bash profile is, how to edit it, the correct syntax for the line to add, and how to get nano editor to save and close without using swear words, bribes or voodoo.

If, like me, you can’t achieve any or all of those tasks (swearing and black magic aside), here is the result of googling “where is my bash profile”, “why can’t I close my bash_profile”, “seriously, I want to close it now”, and “where can I get crows foot, eye of newt and a hair from Steve Wozniak’s head”, and various other things.

First, open your terminal.

Make sure you’re in your home directory:

$ cd ~/

Check the current setting for ulimit

$ sudo ulimit -n

You will be prompted for your sudo password, once you do this, a number will be output. I got 256.

Next, open bash_profile

$ nano ~/.bash_profile

I find nano intimidating, and I’ve lost count of how many times a tutorial has left me hanging with no clue how to save and exit, I won’t do that to you, promise.

Add the following to next blank line (if you have no bash_profile and are creating a new one, the document will be blank, don’t worry, that’s ok):

ulimit -n 1024

CTRL + o to exit file
Enter to write to .bash_profile
CTRL + x to exit nano

Nearly there, to apply new settings:

$ source ~/.bash_profile

Finally, test that the update worked:

sudo ulimit -n

should now output 1024.

I haven’t had any issues with vagrant since. I’ll update the post if I do, promise.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s