How to fix homebrew permissions? - macos

I have uninstalled and installed Homebrew 3 times now because it seems to never allow me to install anything as it denies me permissions at the end of most installations.
As an example I will post this libjpeg download scenario that I'm currently facing.
I try to install libjpeg and get:
$ brew install libjpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mountain_lion.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/jpeg-8d.mountain_lion.bottle.1.tar.gz
==> Pouring jpeg-8d.mountain_lion.bottle.1.tar.gz
Warning: Could not link jpeg. Unlinking...
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link jpeg'
Error: Permission denied - /usr/local/opt/jpeg
'brew link jpeg' results in
Error: Permission denied - /usr/local/opt/jpeg
Here is what my brew doctor reads
$ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
./configure scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link on these:
jpeg
This permission issue has been making it impossible to use brew on anything and I would really appreciate any suggestions.

I was able to solve the problem by using chown on the folder:
sudo chown -R "$USER":admin /usr/local
Also you'll (most probably) have to do the same on /Library/Caches/Homebrew:
sudo chown -R "$USER":admin /Library/Caches/Homebrew
Apparently I had used sudo before in a way that altered my folder permission on /usr/local,
from here on forward all installations with brew have proven to be successful.
This answer comes courtesy of gitHub's homebrew issue tracker

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

As a first option to whomever lands here like I did, follow whatever this suggests you to do:
brew doctor
It's the safest path, and amongst other things, it suggested me to:
sudo chown -R $(whoami) /usr/local
which solved that permissions issue.
The OP did just that but apparently didn't get the above suggestion; you might, and it's always better to start there, and only then look for non trivial solutions if it didn't help.

If you're on OSX High Sierra, /usr/local can no longer be chown'd. You can use:
sudo chown -R $(whoami) $(brew --prefix)/*

I didn't want to muck around with folder permissions yet so I did the following:
brew doctor
brew upgrade
brew cleanup
I was then able to continue installing my other brew formula successfully.

I did not have the /usr/local/Frameworks folder, so this fixed it for me
sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks
The first line creates a new Frameworks folder for homebrew (brew) to use.
The second line gives that folder your current user permissions, which are sufficient.
Used commands are as follows:
mkdir - make directories [-p no error if existing, make parent directories as needed]
chown - change file owner and group [-R operate on files and directories recursively]
whoami - print effective userid
I have OSX High Sierra

I had this issue ..
A working solution is to change ownership of /usr/local
to current user instead of root by:
sudo chown -R $(whoami):admin /usr/local
But really this is not a proper way. Mainly if your machine is a server or multiple-user.
My suggestion is to change the ownership as above and do whatever you want to implement with Brew .. ( update, install ... etc ) then reset ownership back to root as:
sudo chown -R root:admin /usr/local
Thats would solve the issue and keep ownership set in proper set.

This worked for me in 2022 on an M1 Mac with Monterey
sudo chown -R $(whoami) $(brew --prefix)/*

Command from top-voted answer not work for me.
It got output:
chown: /usr/{my_username}dmin: illegal user name
This command works fine (group for /usr/local was admin already):
sudo chown -R $USER /usr/local

This worked for me:
sudo chown -R "$USER":admin /usr/local/Cellar/*
brew cleanup

If you would like a slightly more targeted approach than the blanket chown -R, you may find this fix-homebrew script useful:
#!/bin/sh
[ -e `which brew` ] || {
echo Homebrew doesn\'t appear to be installed.
exit -1
}
BREW_ROOT="`dirname $(dirname $(which brew))`"
BREW_GROUP=admin
BREW_DIRS=".git bin sbin Library Cellar share etc lib opt CONTRIBUTING.md README.md SUPPORTERS.md"
echo "This script will recursively update the group on the following paths"
echo "to the '${BREW_GROUP}' group and make them group writable:"
echo ""
for dir in $BREW_DIRS ; do {
[ -e "$BREW_ROOT/$dir" ] && echo " $BREW_ROOT/$dir "
} ; done
echo ""
echo "It will also stash (and clean) any changes that are currently in the homebrew repo, so that you have a fresh blank-slate."
echo ""
read -p 'Press any key to continue or CTRL-C to abort.'
echo "You may be asked below for your login password."
echo ""
# Non-recursively update the root brew path.
echo Updating "$BREW_ROOT" . . .
sudo chgrp "$BREW_GROUP" "$BREW_ROOT"
sudo chmod g+w "$BREW_ROOT"
# Recursively update the other paths.
for dir in $BREW_DIRS ; do {
[ -e "$BREW_ROOT/$dir" ] && (
echo Recursively updating "$BREW_ROOT/$dir" . . .
sudo chmod -R g+w "$BREW_ROOT/$dir"
sudo chgrp -R "$BREW_GROUP" "$BREW_ROOT/$dir"
)
} ; done
# Non-distructively move any git crud out of the way
echo Stashing changes in "$BREW_ROOT" . . .
cd $BREW_ROOT
git add .
git stash
git clean -d -f Library
echo Finished.
Instead of doing a chmod to your user, it gives the admin group (to which you presumably belong) write access to the specific directories in /usr/local that homebrew uses. It also tells you exactly what it intends to do before doing it.

I resolved my issue with these commands:
sudo mkdir /usr/local/Cellar
sudo mkdir /usr/local/opt
sudo chown -R $(whoami) /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/opt

In my case the /usr/local/Frameworks didn't even exist, so I did:
sudo mkdir /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks
And then everything worked as expected.

Firstly, with MacOS Catalina, the basic ways to change the ownership of /usr/local are no longer allowed. For example:
$ sudo chown -R "$USER":wheel /usr/local
Password:
chown: /usr/local: Operation not permitted
$ sudo chown -R "$USER" /usr/local
chown: /usr/local: Operation not permitted
$ sudo chown -R $(whoami) /usr/local
chown: /usr/local: Operation not permitted
Hence, the popular answers above cannot be used. Secondly, however, taking a step back, if the main concern is to install or upgrade Homebrew, rather than wanting to change the permissions for /usr/local per se, then it may be overkill (like taking a sledgehammer to hammer a nail) to change the permissions for /usr/local. It affects your whole machine and other software may also be using /usr/local. For example, I have files related to maven and mySQL in /usr/local.
A more precise solution is to follow the instructions to install Homebrew, given at the Homebrew GitHub site, namely
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
which installs Homebrew inside /usr/local without changing ownership of /usr/local itself. Instead, Cellar, Caskroom, Frameworks, Homebrew, etc. are installed inside /usr/local. This seems to be a more elegant, precise solution in my opinion.

This solved the issue fore me.
sudo chown -R "$USER":admin /Users/$USER/Library/Caches/Homebrew
sudo chown -R "$USER":admin /usr/local

For a multiuser Mac, this worked for me:
sudo chown -R $(whoami):admin $(brew --prefix)/*

For me, it worked after
brew doctor
Change permission commands resulted in another error
chown: /usr/local: Operation not permitted

All of these suggestions may work. In the latest version of brew doctor, better suggestions were made though.
Firstly - 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...

On MacOS Mojave, I did not have permission to chown the /usr/local folder either (sudo chown -R "$USER":admin /usr/local).
sudo chown -R "$USER":admin /usr/local/* did work for me however, altering the permissions of everything within the local folder.
Hopefully this will help others with the same issue.

There's a killer script on github that fixes perms on /usr/local and brew directories to be accessible by anyone who is a member of the 'admin' group.
https://gist.github.com/jaibeee/9a4ea6aa9d428bc77925
This is a better solution than the chosen answer, since if you chown the /usr/local/___ directories to $USER, then you break any other admin users of homebrew on that machine.
Here are the guts of the script at the time I posted this:
chgrp -R admin /usr/local
chmod -R g+w /usr/local
chgrp -R admin /Library/Caches/Homebrew
chmod -R g+w /Library/Caches/Homebrew
chgrp -R admin /opt/homebrew-cask
chmod -R g+w /opt/homebrew-cask

Actually it's really simple, execute this command:
brew doctor
And it will tell you what to do, to fix permission issues, for example in my case:
This was the problem:
Warning: The following directories are not writable by your user:
/usr/local/share/man/man5
/usr/local/share/man/man7
And this was the solution:
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/man/man5 /usr/local/share/man/man7

I'm on Catalina and I got this error:
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
I only needed to chown the Homebrew directory
sudo chown -R "$USER":admin /usr/local/Homebrew

uninstall brew & re-install with the below command to ensure the linking to the brew github and associated permissions to the local folder work correctly:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This worked perfectly. No mucking around with permissions myself, just reinstalled Homebrew and it works!
source: https://gist.github.com/irazasyed/7732946#gistcomment-2298740

cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Frameworks

If you happen to have multiple accounts on your mac, chances are, your current account belongs to different user group as the primary account that originally owned /usr/local meaning that none of the solutions above will work.
You can check that by trying to ls -la /usr/local and see what user and group that have permissions to write on the directory.
In my case it was root wheel. It may be root admin.
I solved it by adding the current user to the group that primary account has by using the following command.
sudo dseditgroup -o edit -a $(whoami) -t user admin
sudo dseditgroup -o edit -a $(whoami) -t user wheel
There after it worked like a charm. Hopefully it helps someone out there.

If you don't have the latest Homebrew: I "fixed" this in the past by forcing Homebrew to run as root, which could only be done by changing the ownership of the Homebrew executables to root. At some point, they removed this feature.
And I know they'll give lots of warnings saying it shouldn't run as root, but c'mon, it doesn't work properly otherwise.

I tried everything on this page, I ended up using this solution:
brew uninstall --force brew-cask; brew untap $tap_name; brew update; brew cleanup; brew cask cleanup;
My situation was similar to the OP, however my issue was specifically caused by running sudo with brew cask, and then getting my password incorrect. After this, I was stuck with permissions preventing the installation.

To resolve errors for Brew permissions on folder run
brew prune
This will resolve the issues & we don't have to chown any directories.

In my case, I has having problems removing and reinstalling SaltStack.
After running:
ls -lah /usr/local/Cellar/salt/
I noticed that the group owner was "staff". (BTW, I'm running macOS Mojave version 10.14.3.) The staff group could be related to my workplace configuration, but I don't really know. Regardless, I preserved the group to prevent myself from breaking anything further.
I then ran:
sudo chown -R "$USER":staff /usr/local/Cellar/salt/
After that, I was successfully able to remove it with this command (not as root):
brew uninstall --force salt

I used these two commands and saved my problem
sudo chown -R $(whoami) /usr/local
sudo chown -R $(whoami) /usr/local/etc/bash_completion.d /usr/local/lib/python3.7/site-packages /usr/local/share/aclocal /usr/local/share/locale /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew/locks

Related

How to use Homebrew on a Multi-user MacOS Sierra Setup

I have a Mac that is shared between two engineers. Both have separate user accounts. Both need to run brew update and brew install... occasionally.
How do I set this up without getting errors like:
/usr/local must be writable!?
Yeah, I could have UserA take over the permissions of /usr/local every time he wants to use brew (and same with UserB), but that seems like a lot of unnecessary trouble.
You can also change the group permissions to admin or another group that both of your users are in:
chgrp -R admin /usr/local
chmod -R g+w /usr/local
Original source: https://gist.github.com/jaibeee/9a4ea6aa9d428bc77925
UPDATE:
In macOS High Sierra you can't change the owner, group or permissions of /usr/local. So you have to change the group and permissions of the subfolders:
chgrp -R admin /usr/local/*
chmod -R g+w /usr/local/*
UPDATE September 2018, High Sierra 10.13.6
Determine the path of the brew prefix, ie. the path that will be used to store files related to working with homebrew
Check that all users on the system who need access to brew are in the admin group
Optional Add a user to the admin group if a user needs access to brew
Will require access / privileges to use the sudo command
Set the brew prefix path to be recursively owned by the admin group
Set the brew prefix path to be recursively writable by all users who are in the admin group
Verify the permissions of the brew prefix
brew 🍻
echo $(brew --prefix)
echo $(groups $(whoami))
sudo dseditgroup -o edit -a $(whoami) -t user admin
sudo chgrp -R admin $(brew --prefix)
sudo chmod -R g+rwX $(brew --prefix)
ls -lah $(brew --prefix)
Every answer that tries to hack permissions, or use sudo is wrong.
Do not use sudo and do not share a single brew installation across user accounts.
The correct answer per the Homebrew docs is to use zero or one global brew installation on a machine, and for all other users install a local version of brew.
This is especially important on Mac, but works on Linux too.
This can be done by one of the following approaches
Git approach: doing a git checkout of the source repo
Untar-anywhere approach: expanding a tarball into some directory – owned by your user
Git approach
For the git approach you'll need to clone brew.
Arbitrarily choosing my user home directory for my checkout:
cd $HOME
git clone https://github.com/Homebrew/brew.git
./brew/bin/brew tap homebrew/core
Untar-Anywhere Approach
As documented at docs.brew.sh, run this command in your home directory, which will create ~/brew.
cd $HOME
mkdir brew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C brew
Finishing up
For either installation method, you'll need to change your PATH to prefer the new brew bin directory, adding something like this to your shell's dot file.
export PATH=$HOME/brew/bin:$PATH >> ~/.zshrc # or ~/.bashrc
Then running this to reload and test
exec $SHELL
which brew # see that brew is found in your path
Since this is a new installation, you have to install all your desired brew packages (again).
Install homebrew for each user
According to the brew documentation you can install it inside each User Home folder
That way all packages are going to stay inside your user folder, and will not be visible or affect other users. As a good side effect if you delete that user, no trash is left behind on your system. So system wide pollution is minimised.
This comes at the cost of more storage being used, if you install the same package for multiple users. Just something to be aware if you have a very small SSD.
Instructions
If you currently have brew installed on your system globally, I recommend uninstalling brew first. (You can see where brew is installed running which brew)
If you don't have Command Line Tools installed, you have to run this first:
xcode-select --install
Open terminal and Run:
MacOS Catalina 10.15 or newer:
cd $HOME
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
echo 'export PATH="$HOME/homebrew/bin:$PATH"' >> .zprofile
MacOS Mojave 10.14 or older:
cd $HOME
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
echo 'export PATH="$HOME/homebrew/bin:$PATH"' >> .bash_profile
Close the Terminal window
Open Terminal again, and run this to ensure your installation is correct:
brew doctor
Done!
Disabling auto update
This is not required
I also find useful to disable brew to update all packages before every time you install something.
MacOS Catalina 10.15 or newer
echo 'HOMEBREW_NO_AUTO_UPDATE=1' >> $HOME/.zprofile
MacOS Mojave 10.14 or older
echo 'HOMEBREW_NO_AUTO_UPDATE=1' >> $HOME/.bash_profile
EDIT: Please use the answer by Vitim, it's the correct one :)
Hacky workaround solution for macOS Mojave 10.14
This is a edited version of user4815162342's answer, which didn't work for me out-of-the-box.
In System Preferences, go to Users & Groups, click the lock symbol in the bottom left corner to unlock user/group creation, then create a new group called brew-usergroup. Add all users who work with brew to the group (like in the attached screenshot from a german macOS).
In terminal, do this:
echo $(brew --prefix)
echo $(groups $(whoami))
sudo dseditgroup -o edit -a $(whoami) -t user brew-usergroup
sudo chgrp -R brew-usergroup $(brew --prefix)/*
sudo chmod -R g+rwX $(brew --prefix)/*
ls -lah $(brew --prefix)
Note that this doesn't change rights of brew folders anymore (like in other answers), it changes subfolders/files of brew folders.
brew install should now work fine without errors.
The above works fine, but if you want new files to automatically inherit those permissions, set an ACL which gets inherited (otherwise only the user that pours a bottle can remove it). Found hints how to do this here: https://gist.github.com/nelstrom/4988643
As root run once (assuming all users of group "admin" should have access):
cd /usr/local
/bin/chmod -R +a "group:admin allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" Homebrew Caskroom Cellar bin
/usr/bin/chgrp -R admin Homebrew Caskroom Cellar bin
/bin/chmod -R g+rwX Homebrew Caskroom Cellar bin
ls -lae .
the -e on ls shows ACLs.
Update: now I use specific directories (see above) as it failed (sth. like out of memory)
Homebrew is not designed to be used by different Unix users. From the FAQ:
If you need to run Homebrew in a multi-user environment, consider creating a separate user account especially for use of Homebrew.
The chmod solution is not viable unless you ensure that every newly created file in the Homebrew prefix also has the group write permission, which is not the case with the default umask – or unless you keep running that chmod command every time a program writes to the Homebrew prefix.
Maintaining separate Homebrew installations for each user do sort the permissions issues but will create a number of other issues, which is why it's not recommended by Homebrew:
However do yourself a favour and use the installer to install to the default prefix. Some things may not build when installed elsewhere. One of the reasons Homebrew just works relative to the competition is because we recommend installing here. Pick another prefix at your peril!
To ease the official recommendation of using a dedicated account for Homebrew, you can use sudo to easily impersonate that user account. Assuming you named that user homebrew:
sudo -H -u homebrew brew update
-H makes sure HOME is set to the homebrew user home (e.g. /Users/homebrew) so that Homebrew can do its housekeeping there.
-u homebrew tells sudo to impersonate the homebrew user account instead of the default of root.
Here is the official answer of the Homebrew maintainer.
In addition to it I suggest to do 3 more steps. Suppose you have an admin user niki who owns the /usr/local/* dir and you are logged in as another admin user niki_at_work.
Create ~/brew.sh with these contents:
#!/bin/bash
comm="brew $#"
su niki -c "$comm"
chmod +x ~/brew.sh
Add this alias to .zshrc or equivalent: alias brew="~/brew.sh"
Now you can brew from niki_at_work like always (it will ask for niki's password):
brew update
brew install swiftlint
If you want to use a dedicated admin user for brew ex. brewadmin you should first chown brew dirs:
sudo chown -R brewadmin:admin /usr/local/*
The best solution is to add a sudoers record to allow unprivileged user 'joe' to execute any 'brew' related command as the administrative user.
Create a file at /etc/sudoers.d/joe with following content:
joe ALL=(administrator) NOPASSWD: /usr/local/bin/brew
Then you can run brew like this:
sudo -Hu administrator brew install <smth>
The above solutions didn't work for me. But running the command below worked for me.
sudo chown -R $(whoami) $(brew --prefix)/*
Source: https://github.com/Homebrew/brew/issues/3228#issuecomment-333858695

Homebrew user, group, permissions for admin - how to script chown, chgrp, chmod?

Homebrew brew doctor is printing many permissions errors, on a system that has multiple users.
Some of the users are fully trusted, and need to be able to run typical brew commands such as brew install and brew update.
Some stackoverflow posts are recommending things like:
changing the user via chown
changing the group via chgrp
changing permissions via chmod
Some posts suggest these:
set the user to the current "$USER", or create a user "brew"
set the group to the built-in OS X group "admin" or "staff", or create a group "brew"
set permissions recursively to group-read and group-write
create a custom brew directory, such as "/opt/brew"
Is there a script that "does the right thing", such as by creating any custom user or group as needed, setting the user, setting the group, setting the permissions for directories and files?
Or is there any better way to accomplish the core goal, i.e. how to use brew on a system that has multiple users, and enable some of these users to be able to run all the usual brew commands successfully?
My work-in-progress is open source here.
#!/bin/sh
#
# brew-authorize
#
# https://github.com/sixarm/sixarm_brew_scripts/brew-authorize
#
user="$USER"
group="admin"
path=$(brew --prefix)
sudo chown -R "$user" "$path"
sudo chgrp -R "$group" "$path"
sudo find "$path" -type f -exec chmod g+rw {} \;
sudo find "$path" -type d -exec chmod g+rwx {} \;

Meteor will not run without Sudo?

On OSX Yosemite and the latest version of meteor (1.0.1), no matter how many times I uninstall and reinstall it, I can't seem to get it running without sudo. My user account is an administrator account. But meteor refuses to run without sudo. The errors I'm getting are all:
-bash: meteor: command not found
I've seen a few posts on here with similar problems. I've tried repairing disk permissions with disk utility. I've tried:
sudo chown -R $myUsername /usr/local/bin/meteor
I'm not sure what else I can do, because it seems to be a permissions issue. Does anyone have any suggestions?
Additional info that might help:
$ sudo which meteor
/usr/local/bin/meteor
$ sudo ls -l /usr/local/bin/meteor
-rwxrwxrwx 1 root wheel 3528 Dec 18 23:14 /usr/local/bin/meteor
$ ls -ld /usr/local/bin
drwx------ 6 502 wheel 204 Dec 18 23:14 /usr/local/bin
By the way, ls -l /usr/local/bin/meteor only works with sudo.
After we clarified the permissions of the meteor executable and its base directory,
the problem became quite clear:
The Meteor binary is located in /usr/local/bin/meteor
Your user didn't have permission to the directory /usr/local/bin
The steps to resolve:
Add permission on the base directory: sudo chmod +rx /usr/local/bin
If necessary, add the base directory to PATH: PATH=$PATH:/usr/local/bin
For future reference:
When you get this kind of error: -bash: XYZ: command not found
The first thing to check is find the absolute path of XYZ, for example /path/to/XYZ
Try to run with the absolute path /path/to/XYZ
If running with /path/to/XYZ gives -bash: /path/to/XYZ: Permission denied that means you have a problem with permissions on the file and/or directories:
You need read and exec permission on the file itself: sudo chmod +rx /path/to/XYZ
You need exec permission on all path elements leading up to the file: sudo chmod +x /path /path/to
After fixing permission issues, running with /path/to/XYZ should work
After fixing permission issues, if running with XYZ (without full path) still doesn't work, that means /path/to is not on your PATH. Fix with PATH=$PATH:/path/to
Note: the above sudo chmod commands give permissions (read and exec) to all users: owner + group + other. In the case of the OP (and in most common cases), this is perfectly fine.
In situations with more sophisticated permission setup, you might need to be more specific, and use g+rx instead of +rx.
(for the record)
If it works with sudo, and without sudo you get command not found, that means that meteor is on the PATH for root but not for your user. To make it work for your user, you need to find the path to meteor and add it to your user's PATH. For example:
Become root with sudo su -
Find the path of meteor, run command: which meteor
Logout from root (Control-D) to return to your user
Add the base directory to PATH, for example if earlier which meteor gave you /usr/local/bin/meteor, then do this: PATH=$PATH:/usr/local/bin
After this, it should work with your user. To make it "permanent", add the last step in your ~/.bashrc.
If this still doesn't work, then perhaps your user doesn't have the execute permission on the file. Fix that with this command:
sudo chmod +x /usr/local/bin/meteor
From your comments it also seems your user doesn't have permission on the /usr/local/bin directory itself. Fix that with this command:
sudo chmod +rx /usr/local/bin
Shouldn't need an admin account to run it, standard user account works fine. You can locate the meteor file by typing which meteor. It will tell you what file is being used to execute.
Try removing the .meteor folder in your home directory, something like rm -rf ~/.meteor and the script from the bin folder rm /usr/local/bin/meteor or rm 'which meteor' (speech marks there are the ones above ~)
And then reinstall meteor without sudo using the curl https://install.meteor.com/ | sh command.
Should hopefully install with all the correct permissions...

What does "You should probably `chown` them" mean?

I've just installed Homebrew. When I run brew doctor I get this
Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:
/usr/local/share/man/de
What does "You should probably `chown' them" mean? Can someone explain what exactly Homebrew wants me to do?
Ok, so chown is the unix command to change the ownership of a file.
Homebrew is asking me to change the ownership of /usr/local/share/man/de so that Homebrew can write to it. Homebrew runs with the same permissions as I do, so making myself the file's owner should solve the problem.
Running the following fixes the problem:
sudo chown $(whoami) /usr/local/share/man/de
Check the owner and the permission rights:
ls -la /usr/local/share/man/ | grep de; ls -la /usr/local/share/man/de/ | grep man1
Change it:
/usr/bin/sudo /usr/bin/chgrp admin /usr/local/share/man/de /usr/local/share/man/de/man1
/usr/bin/sudo /bin/chmod g+rwx /usr/local/share/man/de /usr/local/share/man/de/man1
Now you can use brew without any problems ;-)
Your system is ready to brew.
In fact, a simple command should do all the work.
sudo chown $(whoami) /usr/local/share/man/*/man1
chown is used to change who has the ownership of a file. In this case the reference to sudo implies that files installed as the superuser will not be accesible by homebrew when run by a regular user rendering these options useless, and most likely causing an error or undesired result if such a file is attempted to be accessed

Brew doctor says: "Warning: /usr/local/include isn't writable."

Brew doctor says:
Warning: /usr/local/include isn't writable. This can happen if you "sudo make install" software that isn't managed by Homebrew.
If a brew tries to write a header file to this directory, the install
will fail during the link step.
You should probably chown /usr/local/include
I've tried different commands to solve this but I'm still stuck here.
I'm running homebrew on 10.8.2
Take ownership of it and everything in it.
Mac OS High Sierra or newer: (ty to Kirk in the comments below)
$ sudo chown -R $(whoami) $(brew --prefix)/*
Previous versions of macos:
$ sudo chown -R $USER:admin /usr/local/include
Then do another
$ brew doctor
What worked for me was too
sudo chmod g+w /usr/local
sudo chgrp staff /usr/local
What worked for me was
$ sudo chown -R yourname:admin /usr/local/bin
The only one that worked for me on El Capitan was:
sudo chown -R $(whoami) /usr/local
If you are on High Sierra and experiencing this issue, follow the steps below (Note: /usr/local cannot be chown'd in High Sierra):
sudo mkdir /usr/local/include
sudo chown -R $(whoami) $(brew --prefix)/*
Then try linking with brew link. I was experiencing similar issue and none of the solutions above worked for High Sierra. Hope this helps someone.
For High Sierra:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then, try your brew commands.
Issue #3285
You can alias the command to fix this problem in your .bash_profile and run it every time you encounter it:
At the end of the file ~/.bash_profile, add:
alias fix_brew='sudo chown -R $USER /usr/local/'
And now inside your terminal you can run:
$ fix_brew
This worked for me on macOS 10.12
sudo chown -R $(whoami) /usr/local
I had the problem updating homebrew with the following error:
/usr/local is not writable. You should change the ownership
and permissions of /usr/local back to your user account:
sudo chown -R $(whoami) /usr/local
First you need to create the directory:
sudo mkdir /usr/local/include
Second:
sudo chown -R $(whoami) $(brew --prefix)/*
For some it's going to be:
sudo chown -R JonJames:admin /usr/local/lib
where "lib" is used as opposed to "bin" or "include" or "whatever else"
The Homebrew Warning "should" explain what specifically is not writable and then give you a command syntax for follow, however you will need to use the ":" as opposed to what the Warning mentions which is actually not correct syntax??
Work for me
$ sudo chown -R $(whoami):admin /usr/local
$ cd /usr/local/Library && git stash && git clean -d -f
Same error on MacOS 10.13
/usr/local/include and /usr/local/ /usr/lib were not created. I manually created and brew link finally worked.
What Worked for me, while having I have more than 1 user on my computer.
Using terminal:
Running brew doctor
Seeing multiple /usr/local/... isn't writable error's
Disabling Mac's System Integrity Protection: https://apple.stackexchange.com/a/208481/55628
Run the following
sudo chown -R $(whoami) /usr/local/*
brew doctor && brew upgrade && brew doctor
Running Macbook Pro OSX High Sierra (version 10.13.3.)
EDIT 1:
FYI - Please be Advised this causes an issue with running MySQL on your MAC.
To be able to start my local server, I had to run:
sudo chown -R mysql:mysql /usr/local/mysql/data
After you run this you can start your local MySQL Server.
You need to create /usr/local/include and /usr/local/lib if they don't exists:
$ sudo mkdir -p /usr/local/include
$ sudo chown -R $USER:admin /usr/local/include
sudo mkdir -p /usr/local/include /usr/local/lib /usr/local/sbin
sudo chown -R $(whoami) /usr/local/include /usr/local/lib /usr/local/sbin
This will create all required directories and give it the correct ownership.
After running these commands check with: brew doctor
This works for Mojave.
You need to get control of entire /usr/local to do that you need to do a recursive chown under /usr/local
sudo chown -R YOUR_USERNAME:admin /usr/local/
I just want to echo sam9046's modest comment as an alternative and potentially much easier solution that worked in my case: uninstall and install homebrew again from scratch. No sudo commands required.
You can also browse/modify the uninstall script from that link above if you need to ensure it won't affect your previously installed packages. In my case this was just my home machine so I just started over.
I have had this happen in my organization after all our users were bound to active directory (effectively changing the UID from 50x to ######).
Now it is simply a case of changing the ownership of all files where were owned by x to y.
Where 501 is my old numeric user id which is still associated with all the homebrew files.
The old user id can be found using ll /usr/local/Cellar
Now update the ownership
sudo find /usr/local -user 501 -exec chown -h $USER {} \;
This way we avoid changing the ownership on files which are not controlled by homebrew or belong to some other system user.
Go into the /bin directory and type:
chown -R $(whoami):admin /usr/local/bin

Resources