Like an idiot, I managed to delete my system ruby install.
I've re-installed xcode, and also installed RVM
Doing this:
$ which ruby
returns this:
/Users/alex/.rvm/bin/ruby
However, Homebrew still seems to be broken:
$ brew
-bash: /usr/local/bin/brew: /usr/bin/ruby: bad interpreter: No such file or directory
The system ruby on OS X is symlinked to the Ruby.framework. Since you reinstalled Xcode, it should be installed, but you need to restore the symlinks.
First, check that this file exists and works.
$ /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
If that command works, you should be able to setup the sym links again
cd /usr/bin
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby /usr/bin/ruby
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/erb /usr/bin/erb
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/gem /usr/bin/gem
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/irb /usr/bin/irb
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rake /usr/bin/rake
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rdoc /usr/bin/rdoc
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ri /usr/bin/ri
sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/testrb /usr/bin/testrb
This should get you started, hopefully I haven't forgotten any of the binaries that need linked. There are other suggestions to reinstall ruby here: https://superuser.com/questions/171433/is-it-possible-to-reinstall-fix-mac-os-xs-system-ruby-without-doing-a-complete
Another method in a gist: https://gist.github.com/1418384
brew is hardcoded to use the system ruby. You could try change brew's shebang (the first line) to /usr/bin/env ruby, but it's not guaranteed to work with anything but the system Ruby (I'm not sure it's fully compatible with Ruby 1.9).
Or you could reinstall your system Ruby, which should be possibly by reinstalling OS X.
If you don't want to have to reinstall the system ruby, the following should do the trick.
IMPORTANT: replace MY_USER_NAME with the name of your home folder, which is the "short name" of your user in OS X.
sudo ln -s /Users/MY_USER_NAME/.rvm/bin/ruby /usr/bin/ruby
There is a new link for Homebrew install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Installation link for homebrew has been moved.
Here is the new one:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
sudo rm -rf /usr/local/Cellar /usr/local/.git
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
I solved by reinstall brew.
Related
My question is what would be a good way to run two admin accounts for developing in regards to running Homebrew, Zsh and Oh My Zsh and configuring the .zshrc file?
My reasoning for this is that I recently started a new job and would like to use my Mac with two accounts, both of which will be admins and both of which I will require devtools so as to keep my work life/dev and personal life/dev cleanly separated. I just erased my hard drive and cleanly installed OS X 10.12.3 and created two Admin accounts.
I've had a shot at setting it up however keep getting permission errors whenever I switch accounts and run terminal, usually specific to zsh completions.
My steps:
Install Homebrew on both users /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
Install zsh with brew brew install zsh and change to it chsh -s /bin/zsh.
Install oh my zsh with curl via sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)".
run sudo chown -R $(whoami):admin /usr/local.
Then I've tried a whole mess of things which I'll refrain from adding as I believe they may only lead others down a dark path.
Although this step is safe to run as root, I still recommend running the installation as non-root user to prevent catastrophic problems with root switching shell while the shell isn't working. superuser shell should never be changed.
Here's the proper way to install oh-my-zsh for multiple users.
Step 1: Ensure umask is not stricter than 022. If not set it to 022.
$ umask 022
Step 2: set and export ZSH with the destination path where the shared oh-my-zsh will be installed.
export ZSH=/usr/local/.zsh/oh-my-zsh
Step 3: Create the parent directory and make it owned by the user installing the scripts.
$ sudo mkdir /usr/local/.zsh
$ sudo chown ${USER} /usr/local/.zsh
Step 4: Run the installer.
$ bash -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Step 5: Change ownership of the installation path back to root.
$ sudo chown -R root /usr/local/.zsh
Step 6: Update location of ZSH in ${ZSH}/templates/zshrc.zsh-template
$ sudo sed -i 's|export ZSH=.*|export ZSH='${ZSH}'|' ${ZSH}/templates/zshrc.zsh-template
(Optional)
Step 7: Disable auto update. This is recommended as the installation is now owned by root.
$ sudo sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/' ${ZSH}/templates/zshrc.zsh-template
From here on, each user can copy ${ZSH}/templates/zshrc.zsh-template as ~/.zshrc
Whilst #alvits answer may have been correct I was unable to get it to work for me. I however, was able to get it to work by doing the following.
Install Homebrew (check https://brew.sh/ for up to date command):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Zsh with Homebrew:
brew install zsh
Close terminal and reopen with ZSH as default shell:
Install Oh My Zsh as root user
sudo su
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Close terminal to exit root user mode.
Install Oh My Zsh as each admin (therefore install on both users):
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
That stopped all the auto-completions and permission errors for me. I believe this to be overkill and that there would be a way with symlinks however this way is easy.
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
I have installed git-crypt (https://github.com/shadowhand/git-encrypt) on Windows and it's work fine.
But when i try on MacOSX (Mavericks), it's not successful.
From the guide this command on Linux:
$ sudo ln -s "$(pwd)/gitcrypt" /usr/local/bin/gitcrypt
But i can not make it work on MacOSX.
I also try this command without success:
sudo -s 'echo "/usr/local/bin/gitcrypt" > /etc/paths.d/$(pwd)/gitcrypt'
I have found solution. I post here for anyone find it:
$ clone https://github.com/shadowhand/git-encrypt /usr/local/git-encrypt
$ sudo vi /etc/paths
Add /usr/local/git-encrypt to the end save and quit terminal.
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
I have executed the commands as prescribed in the instructions at the rvm website but things don't seem to work..
Fetching the code from the git repository runs smoothly but when I try to use
rvm notes
Error:
/usr/local/bin/rvm: line 73: /home/cody/.rvm/scripts/rvm: No such file or directory
flashes in multiple lines and doesn't stop till I hit ctrl+C..
I am running Ubuntu 8.04 and currently I am running ruby 1.9.2..
Sorry, if I am missing out any necessary information. Thanks in advance.
Ack, I didn't mean to post this as a comment on the question. Anyway, if I had to guess, I'd say you installed rvm using sudo or as root. If that is the case, remove it and reinstall without sudo:
sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh \
/usr/local/rvm /usr/local/bin/rvm
sudo /usr/sbin/groupdel rvm # this might fail, it's not that important
Open new terminal window/tab and make sure rvm is removed:
env | grep rvm
The output should be empty, sometimes it's needed to relogin, after it's empty you can continue:
curl -sSL https://get.rvm.io | bash -s stable
It works perfectly fine installed for the local user.
Ok, for anyone who tried to install RVM using sudo and is now pulling
their hair out trying to get it to install in $HOME/.rvm, here's what
did it for me:
When you installed RVM using sudo, it created a file /etc/rvmrc, which contains the following:
umask g+w
export rvm_path="/usr/local/rvm"
This makes all future attempts at installation (even when not run as sudo)
install into /usr/local/rvm, which is NOT what you want for a single
user installation. So remove /etc/rvmrc and then you can run
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
and it will install properly into $HOME/.rvm
DId you add this line to your ~/.bashrc?
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
I have executed the commands as prescribed in the instructions at the rvm website.
WHICH commands? There are several pages containing instructions to install RVM depending on whether you want a single-user "sandbox" or are installing system-wide for a multi-user system as the administrator.
Because you have RVM in /usr/local, I think you tried to do a system-wide install but didn't get it right. For 99% of us, that is the wrong installation method, and instead you should use the single-user installation, which is simple and puts everything in ~/.rvm.
Either way, be sure to read the entire instructions. And, if doing a single-user install, finish the install with the "Post Install" modifications to ~/.bashrc or ~/.bash_profile for a single-user, then start a new terminal session.
When using the single-user install NEVER use sudo to install gems to a RVM-managed Ruby, even though the instructions for a gem might say to.
Look at the section "Troubleshooting your install" here. Since you are on Ubuntu, you probably need to make further mods to you .bashrc
in .bashrc have you changed the
[ -z "$PS1" ] && return
to
if [[ -n "$PS1" ]]; then
and added this to the end of the file:
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
I just had a similar problem.
It turned out that many files in ~/.rvm/scripts/ and ~/.rvm/src/rvm/scripts/ which obviously should be executable did not have execute permissions. Running a script on both directories to set all files to executable solved that immediate problem.
I have got same problem after installation. Then I restarted terminal and it started working poperly.