168

When I try to do this:

brew install node

I get this message:

 /usr/local/Homebrew/Library/Homebrew/utils/lock.sh: line 19: /usr/local/var/homebrew/locks/update: Permission denied
-e:1:in `initialize': Bad file descriptor (Errno::EBADF)
    from -e:1:in `new'
    from -e:1:in `<main>'
Error: Another active Homebrew process is already in progress.
Please wait for it to finish or terminate it to continue.
Error: Permission denied - /usr/local/var/homebrew/locks/node.brewing

Any idea on how to solve this?

omikes
  • 8,064
  • 8
  • 37
  • 50
akaliza
  • 3,641
  • 6
  • 24
  • 31

9 Answers9

380

Try removing the Homebrew process locks with this command:

rm -rf $(brew --prefix)/var/homebrew/locks
sorin
  • 161,544
  • 178
  • 535
  • 806
omikes
  • 8,064
  • 8
  • 37
  • 50
  • 2
    why not stay safer with `for file in `ls *lock`; do mv $file $file.old; done`? – isomorphismes Aug 20 '19 at 11:08
  • 2
    THANK YOU this was perfect! – lizziepika Mar 03 '20 at 22:52
  • 1
    This is not advisable. The error is in the wrong permissions; the `locks` files had a purpose and deleting it is **not** the safest option. – Kamafeather Sep 08 '20 at 11:56
  • 1
    I specified to try this if the other answer didn't work; I was referring to @kalibrain's solution. I had to do both. – omikes Oct 06 '20 at 00:19
  • 2
    Using `rm -rf $(brew --prefix)/var/homebrew/locks` will take account of different brew install locations if the command above is not working. – thomas Jul 07 '22 at 10:27
  • 1
    Should `$(brew --prefix)` not be quoted? What if it returns a space separated `~` - this would surely end up wiping your home directory? Or actually if it returns a path with any spaces - it'll likely cause you some trouble. – Chris Stryczynski Jan 26 '23 at 14:40
55

As this thread suggests at some point, my problem was to run brew command with sudo privileges for the first time. This causes brew to try to access privileged files and folders and it fails. If that's the case for you, run these commands and try installing node again.

sudo chown -R "$USER":admin /usr/local

brew cleanup

Lin Du
  • 88,126
  • 95
  • 281
  • 483
kalibrain
  • 888
  • 7
  • 15
  • Yes, the issue happened after moving files for a backup and then restoring them. The files owner was set to an unknown GID; restoring with `chown` brought all the functionality back without errors. – Kamafeather Sep 08 '20 at 11:55
  • Also, ensure the permissions are fixed, with `ls -la /usr/local/`. If they are not, try to add an asterisk to imply all the subfiles (like `sudo chown -R "$USER":admin /usr/local/*`). – Kamafeather Sep 08 '20 at 11:58
  • 4
    This answer worked well but chown on `/usr/local/*` is better otherwise there is a permissions error – j314erre Mar 19 '21 at 00:01
45

Simply type the following into your terminal:

brew cleanup

This should clean up any issues. Follow the command with:

brew doctor

All done.

Zakariah Siyaji
  • 989
  • 8
  • 27
  • This seems to be the most valid answer since no locks file are apparently created under Mac OS X 11.5.2 – Andrea Moro Sep 29 '21 at 16:27
  • 1
    This helped me greatly, thanks a lot :) For anyone else, I also ran CMD+Q after this to terminate the terminal, and make sure the processes had stopped – djinne95 May 28 '22 at 11:50
39

just close the terminal and reopen another

chenxuZhu
  • 451
  • 4
  • 5
  • 2
    This might work only in some cases. The reason is, if you just close the terminal, it might not be able to remove the lock created on `/usr/local/var/homebrew/locks` path. Hence, the next time you run `brew update` you will see the error that is given in this question – Eranga Heshan Dec 07 '20 at 02:30
  • I did that and a full reboot and that did not help...@kalibrain's answer worked – j314erre Mar 18 '21 at 23:59
  • 1
    This is the way to resolve the issue. Simple and worked perfectly! Thanks – gdibble Jun 02 '22 at 00:49
15

In my case on OSX, I interrupted node install and then I try to start install node again so I got the error mentioned in the question.
I tried below steps from other responses:

sudo chown -R "$USER":admin /usr/local

brew cleanup

and

rm -rf /usr/local/var/homebrew/locks

but this message appear again - so don't know if above steps helped.

Then I closed the terminal tab and in new one ran

brew install -v node

It took 11 minutes to finish successfully node installation

Lin Du
  • 88,126
  • 95
  • 281
  • 483
pbaranski
  • 22,778
  • 19
  • 100
  • 117
  • 3
    on *macOS* is safer to do `sudo chown -R "$USER":admin /usr/local/*`. Without the asterisks I didn't get a correct expansion and most of the sub-files/-folders weren't touch by the command. – Kamafeather Sep 08 '20 at 11:57
  • 1
    Removing the locks helped me! Fixed my install for BasicTex. Thanks! – CodeSammich Apr 29 '21 at 03:37
8

To unlock with any homebrew install location:

rm -rf $(brew --prefix)/var/homebrew/locks

bric3
  • 40,072
  • 9
  • 91
  • 111
Aure77
  • 3,034
  • 7
  • 33
  • 53
3

Change file permission will avoid this error:

sudo chown <your-username>:admin /usr/local/Homebrew/Library/Homebrew/utils/lock.sh

For permission issues with homebrew install or update:

Change your homebrew permission setting

sudo chown -R <your-username>:admin /usr/local/Homebrew

sudo chown -R <your-username>:admin /usr/local/var/homebrew

Then run homebrew install or update

Emilie Y
  • 39
  • 2
  • Changing permissions for `/usr/local/Homebrew` and `/usr/local/var/homebrew` is exactly what helped me – brigadir May 25 '18 at 08:33
0

I don't know what was going on. My only active terminal was waiting for input, no jobs running in the background. I had just tried to run an RVM install that failed and asked me to update Homebrew but that was supposed to be finished since the terminal was waiting for input. After several repeat command invocations and a couple of minutes later I stopped receiving the message.

This is on Mac OSX 10.13.6 with iTerm2.

⋊> brew --version
Homebrew 2.1.4
Homebrew/homebrew-core (git revision 97b15a; last commit 2019-06-07)
Homebrew/homebrew-cask (git revision 2a010; last commit 2019-06-07)
Pysis
  • 1,452
  • 2
  • 17
  • 31
0

Home brew itself gave a suggestion to run the below command and give permissions to the user.

sudo chown -R $(whoami) /opt/homebrew

This worked for me.

rahul
  • 1,133
  • 12
  • 17