Permission Error with homebrew - macos

Whenever I try to install something with homebrew, I get this error:
Error: Permission denied - /Library/Caches/Homebrew/Formula/tmux.brewing
and I am just using the normal command
brew install tmux
Any ideas on how I can fix this?
Thanks.

sudo chown -R your_username /Library/Caches/Homebrew should do it. Possible but unlikely you'll also need to chmod -R o+w /Library/Caches/Homebrew.
If you have a multi-user Homebrew setup, consider using brewdo.

The solution posted here to a similar question worked.
Namely:
sudo chown -R $(whoami) /usr/local

Related

Unable to Install any package using homebrew

I'm newbie to macOS. I ran into an issue where when ever I try to install any package. The dependencies get downloaded but it doesn’t get installed. Please help me regarding this.
The issues was the permissions of the system.
What I did is that I reinstalled brew and then I found that
New command for users on macOS High Sierra as it is not possible to chown on /usr/local:
bash/zsh:
sudo chown -R $(whoami) $(brew --prefix)/*
fish:
sudo chown -R (whoami) (brew --prefix)/*
Reference: Can't chown /usr/local in High Sierra

Cannot install homebrew packages because permission is denied

When I run brew install {package}, I get the following:
ln: /usr/local/bin/{package}: Permission denied
But if I try to use sudo brew install {package}, I get the following:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
How do I get homebrew working again?
You can fix permissions for Homebrew by running:
cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var Frameworks
See this answer for details: https://stackoverflow.com/a/44208097/1807667

Homebrew: Could not symlink, /usr/local/share/man/man7 is not writable

I'm installing LightGBM on OSX, following the installation guide. While installing cmake, Homebrew gives such warning message:
Warning: cmake-3.8.1 already installed, it's just not linked.
Then I try:
$brew link cmake
it gives:
Linking /usr/local/Cellar/cmake/3.8.1...
Error: Could not symlink share/man/man7/cmake-buildsystem.7
/usr/local/share/man/man7 is not writable.
The proposition of Mark Setchell to use sudo chown -R $(whoami):admin /usr/local/share/man is right. According to the Homebrew troubleshooting page:
If commands fail with permissions errors, check the permissions of /usr/local’s subdirectories. If you’re unsure what to do, you can run cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var Frameworks
but the proposition of Nano to use sudo is not a good one. According to the Homebrew FAQ:
Homebrew is designed to work without using sudo. You can decide to use it but we strongly recommend not to do so. If you have used sudo and run into a bug then this is likely to be the cause. Please don’t file a bug report unless you can reproduce it after reinstalling Homebrew from scratch without using sudo.
Just follow these 4 steps
sudo chown -R $(whoami) $(brew --prefix)/*
brew doctor
brew prune
brew link cmake

Installing MongoDB

I get this error when installing MongoDB on OSX, even though the second time I tried it with sudo command. Any thought?
==> Checking out tag r3.0.3
==> ./build.sh
==> /usr/local/opt/scons/bin/scons install --prefix=/usr/local/Cellar/mongodb/3.0.3 -j4 --osx-version-min=10.9 --cc=/usr/bin/clang --cxx=/usr/bin/clang++ --use-new-tools
Error: Permission denied - /usr/local/var/mongodb
Monas-MacBook-Pro:meanio mona$ sudo brew install mongodb
Password:
Error: Cowardly refusing to `sudo brew install`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.
It's a permissions problem. The solution being:
sudo chown -R `whoami` /usr/local/var/mongodb
Per the comment:
Try creating the directory, prior to setting ownership:
sudo mkdir /usr/local/var/mongodb && sudo chown -R `whoami` /usr/local/var/mongodb
I just open /usr/local/ via finder and manually create folder with name var. Mac asked for a password. After that I successfully install MongoDB.
You shouldn't use brew with sudo. To check the overall brew sanity, run:
$ brew doctor
It will pinpoint potencial problems and it's corresponding solutions. If it really is a permission problem, as pointed by #hd1, you should fix the permissions of /usr/local/var/, where brew is trying to create the /mongodb folder.

Ghostscript not writable

Trying to install octave on a new Macbook, but keep running into problems using Homebrew. I am following directions here:
http://wiki.octave.org/Octave_for_MacOS_X
I run into the error:
Linking /usr/local/Cellar/ghostscript/9.14...
Error: Could not symlink share/ghostscript/Resource
/usr/local/share/ghostscript is not writable.
After entering:
sudo chown -R username:admin /usr/local/bin
brew link ghostscript
I still get the same error. How do I make ghostscript writable?
Using this command worked for me:
sudo chown -R `whoami` /usr/local/share/ghostscript
After that it was possible to create the symlink with:
brew link --overwrite ghostscript
Notice that /usr/local/share is outside /usr/local/bin.
Try sudo chown -R username:admin /usr/local.

Resources