Bench Install in Mac OS Sierra

I have been trying to install bench locally and I am getting the following error, got couple of other errors before for permission which I fixed by giving the right permissions

TASK [install prequisites] *****************************************************
failed: [localhost] (item=cmake) => {"failed": true, "item": "cmake", "msg": "/usr/local/Homebrew/Library/Homebrew/utils/lock.sh: line 19: /usr/local/var/homebrew/locks/update: Permission denied\n-e:1:in `initialize': Bad file descriptor (Errno::EBADF)\n\tfrom -e:1:in `new'\n\tfrom -e:1:in `<main>'\nError: Another active Homebrew process is already in progress.\nPlease wait for it to finish or terminate it to continue.\nWarning: You are using a pre-release version of Xcode.\nYou may encounter build failures or other breakages.\nPlease create pull-requests instead of filing issues.\nError: Permission denied - /usr/local/var/homebrew/locks/cmake.brewing"}
ok: [localhost] => (item=redis)
failed: [localhost] (item=mariadb) => {"failed": true, "item": "mariadb", "msg": "/usr/local/Homebrew/Library/Homebrew/utils/lock.sh: line 19: /usr/local/var/homebrew/locks/update: Permission denied\n-e:1:in `initialize': Bad file descriptor (Errno::EBADF)\n\tfrom -e:1:in `new'\n\tfrom -e:1:in `<main>'\nError: Another active Homebrew process is already in progress.\nPlease wait for it to finish or terminate it to continue.\nWarning: You are using a pre-release version of Xcode.\nYou may encounter build failures or other breakages.\nPlease create pull-requests instead of filing issues.\nError: Permission denied - /usr/local/var/homebrew/locks/mariadb.brewing"}
ok: [localhost] => (item=nodejs)

In case if you point out that there is a existing process which is running hence the lock could not be released then, I have checked homebrew locks folder and there are none.

I have also updated homebrew to the latest version but the error is still there.

Homebrew permission messed up:

As a first option to whomever lands here like I did, follow whatever this suggests you to do:

brew doctor

Fix the mess you have probably already made of /usr/local by running this in the command line:

sudo chown -R root:wheel /usr/local

Then take ownership of the paths that should be specifically for this user:

sudo chown -R $(whoami) /usr/local/lib /usr/local/sbin /usr/local/var /usr/local/Frameworks /usr/local/lib/pkgconfig /usr/local/share/locale

All of this information is available if you run sudo brew update and then read all of the warnings and errors you will run into…

Thank you for the reply but I have already tried the above mentioned steps. Its my mistake that I didn’t include what all I did in my post.

I have tried all the solution available to fix the permission issue, made sure that even no ruby process is running. I am still getting the following errors

failed: [localhost] (item=cmake) => {“failed”: true, “item”: “cmake”, “msg”: “/usr/local/Homebrew/Library/Homebrew/utils/lock.sh: line 19: /usr/local/var/homebrew/locks/update: Permission denied\n-e:1:in initialize': Bad file descriptor (Errno::EBADF)\n\tfrom -e:1:in new’\n\tfrom -e:1:in `'\nError: Another active Homebrew process is already in progress.\nPlease wait for it to finish or terminate it to continue.\nError: Permission denied - /usr/local/var/homebrew/locks/cmake.brewing”}

failed: [localhost] (item=mariadb) => {“failed”: true, “item”: “mariadb”, “msg”: “/usr/local/Homebrew/Library/Homebrew/utils/lock.sh: line 19: /usr/local/var/homebrew/locks/update: Permission denied\n-e:1:in initialize': Bad file descriptor (Errno::EBADF)\n\tfrom -e:1:in new’\n\tfrom -e:1:in `'\nError: Another active Homebrew process is already in progress.\nPlease wait for it to finish or terminate it to continue.\nError: Permission denied - /usr/local/var/homebrew/locks/mariadb.brewing”}

I also tried clearing the locks folder even though I could not find any locks which are mentioned in the error. I have been trying a lot to install frappe and make it up and running from quite sometime. Please help if I am missing something here with the installation.

Note: I am running mysql in no root password mode

EDIT: Tried after setting mysql password, still same issue.