Installing in Homebrew errors - ruby

Attempting to install rvm and ruby 1.9.2
I already installed homebrew and git, but couldn't get complete updates because I kept getting permission errors. Re-installed Snow Leopard and repaired permissions.
Now this happens...
$ brew install wget
Error: Cannot write to /usr/local/Cellar

sudo chown -R $USER /usr/local
You'll have to give yourself ownership of /usr/local/ using that line right there. I had to do this myself after using the ruby one-liner at the top of the official docs to install Homebrew. Worked like a charm for me. It ought to be the only time you'll ever need to sudo with Homebrew.
I'm not sure if the ruby one-liner does this. If it did, then something else on my system took control of /usr/local since.
Edit: I completely missed this, but #samvermette didn't (see replies to my answer): if you run this command above and have something installed via homebrew that requires special user permissions, like mysql, make sure to give those permissions back (as the above command gives recursive ownership to everything inside /usr/local to you ($USER). In the case of mysql, it's…
sudo chown -RL mysql:mysql /usr/local/mysql/data

I had this issue after upgrading to Mavericks, and this page was the top search result when googling the error message. I continued searching and found this answer on stack overflow.com. Put concisely, it is:
sudo chmod a+w /usr/local/Cellar
This fixed the issue for me, and as it only changes permissions for the specific path referenced in the error message, seemed unlikely to have negative side effects with other installations.
I'm putting this answer here for anyone else who may find this page first like I did. However, credit should go to jdi.

You can allow only Admin users writing into /usr/local/?
chgrp -R admin /usr/local
chmod -R g+w /usr/local
chgrp -R admin /Library/Caches/Homebrew
chmod -R g+w /Library/Caches/Homebrew
Since that each user who belongs to Admin group, will be able to install new dependencies.

On High Sierra you need the following command cause chown will not work:
sudo chown -R $(whoami) $(brew --prefix)/*
Link:
https://github.com/Homebrew/brew/issues/3228

uninstall and re install HomeBrew that will do the trick

I suggest ensuring that the current user is a member of the group that owns /usr/local. I believe by default, that group is wheel. To make yourself a member of that group:
$ sudo dscl . append /Groups/wheel GroupMembership $USER
Although something of an inelegant hammer, it has the intended effect - enabling access to items in /usr/local that are intended only for use (read/write) by elevated members. This approach has benefits of the other above because it takes advantage of the group memberships, enabling multiple (authorized) users on the system to use homebrew.

How did you install Homebrew? Their official installation instructions include running a ruby script. That should take care of the permission issues for you.
If you don't want to run a script, there is a section of that page called "Installing to /usr/local for Developers" that explains the change in permissions needed for the /usr/local directory.

EDIT: As mentioned in the comments it's a bad idea to use sudo with homebrew, so don't use the following answer!
You can also prevent this error if you execute the command with sudo:
$ sudo brew install wget
But take care of using sudo because you can make a lot of mistakes.

Related

"You don't have [PATH ]in your PATH, gem executables will not run." while using "gem install --user-install bundler"

I was trying to install jekyll in my Mac and got the warning as following:
WARNING: You don't have /Users/Carrot/.gem/ruby/2.3.0/bin in
your PATH, gem executables will not run.
I checked through gem list and it shows it is installed; and I can find the jekyll through the path "/Users/Carrot/.gem/ruby/2.3.0/bin". I read a post which seems like my situation. I would like to know if it's a must to go through sudo? I now prefer to uninstall everything (since it also installed sass and bunch of things at the same time) and go through homebrew. How can I do the uninstallation?
Many thanks!
For those who have problems with #lamech-desai answer, (actually, when they do Desai's commands, it apparently works temporarily for them).
So you can easily do these:
open ~/.bshrc if you would like to use bash or ~/.zshrc if your are using zsh or etc...
$ sudo nano .bashrc ## bash users
$ sudo nano .zshrc ## zsh users
then copy and past these two lines of code at the end of the .*rc file:
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"
then simply press ctrl+s and ctrl+x. This will save the changes to .bashrc but you won't see them immediately - directly on your next shell login with your current user. One way to see the changes immediately is to switch user to root with su root and then switch back to your previous user with su <username> - and voila, your .bashrc will be reloaded. You can also check this with echo $PATH.
Thanks to #lamech-desai for great answer
If you are using arch linux just use the commands below in your terminal
[user~]$ export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
[user~]$ export PATH="$PATH:$GEM_HOME/bin"
[user~]$ gem list
[user~]$ gem update
You need to add the directory to your PATH environment variable
https://askubuntu.com/questions/406643/warning-you-dont-have-a-directory-in-your-path-gem-executables-will-not-run
If you are on a Mac like me, you need to add the PATH to the PATH environmental variable. You can do it with export command:
export PATH="/Users/Carrot/.gem/ruby/2.3.0/bin:$PATH"
If you wanna know more about this process, here is a blog post about this: Adding a Path to the Linux PATH Variable
Probably a bit odd to answer my own question but I did finally fix it somehow like a blind fly. I hope to write down the experience maybe who else is totally like me as a absolute beginner with everything wouldn't get struggling overnight.
Stage 1: from gem to homebrew (failed)
At the beginning, I did remove items that install in gem item-by-item, then I install brew-gem to do it. At some stage, it work for jekyll but not my theme. It kept popping out I didn't install a package that the theme needs even I installed it manually. So in the end, I remove everything related to jekyll from homebrew.
Stage 2: back to gem (very long path but finally made it)
I later found a page tell step-by-step to install jekyll. I am using OSX 10.13 (High Sierra) that cause me the permission problem. So I just granted access with this line:
sudo chown -R $(whoami) /usr/local/*
The * is a must or it won't work. I did the same to the ruby part
sudo chown -R $(whoami) /Library/Ruby/Gems/2.3.0/*
After that I install jekyll and bundler carefully following the instruction. And install the packages that the theme needs manually through gem install, which you can find at the Gemfile. I got the problem of jekyll-sitemap similar as this, I followed the method to install pygment.rb through gem install pygments.rb. And now my site is locally work.

vagrant: command not found after install on Mac OSX 10.10.4

Downloaded Vagrant, and went through th installation process.
When I ran vagrant -v it says vagrant: command not found
It has put the files in /opt/vagrant/...
It should install in the Applications folder with a link to the /usr/bin so it is added to the shell path.
There is no directory that has been created during this process.
I am afraid I can't even get started with it. ITs obviously not creating all the shortcuts it needs to be able to run the commands.
I have looked for support on this issue and reported a bug.
I also accepted the xcode licence agreement.
Has anybody else had this issue.
My next step is to manually create the shortcuts.
If you look at the uninstall script including in the Vagrant DMG, it is referring to /usr/local/bin which does not exist. It should be error handling (the Vagrant pkg installer) and create it (permissions/ownership etc) but it doesn't.
You need to mkdir the /usr/local/bin. I tried a symlink between /usr/bin/vagrant (as /usr/bin exists, and in-path) to /opt/vagrant/bin/vagrant BUT this does not work, as later on in life, Vagrant refers in a hard fashion to /usr/local/bin/vagrant because its stupid.
$ sudo mkdir /usr/local/bin
If you sudo it, it should be made with correct ownership etc. Now just re-run the Vagrant installer pkg.
Make sure the Virtual Box setup is installed on Mac before installing Vagrant.
I raised the bug with https://github.com/mitchellh/vagrant/issues/6034
The issue is that I had no /usr/local directory at all.
It is an apple issue.
After I created the directories as you described I was able to install vagrant vitrual boax and laravel.
Here is what I did.
sudo mkdir /usr/local
Then bin.
cd /usr/local
sudo mkdir bin
I uninstalled Vagrant, re-installed and when I ran vagrant -v I then got the version.
cd /usr/local/bin
ls
sudo chmod 755 vagrant
Thanks for your Answer.
Weird, on 1.8.5 I couldn't run Vagrant either, noticed that /usr/local/bin was owned by root. Ran command
# chown -R User:Group /usr/local/bin
as root and works from my username now.

Installed, just not linked

Note: I'm not so good at using shell.
I was trying to install Valgrind using brew on Yosemite.
brew install --HEAD valgrind
Towards the end, I got an error having to do with linking so when I tried to reinstall, I got:
Warning: valgrind-HEAD already installed, it's just not linked
So apparently I've already installed it. Then based on other SO questions and answers, I tried:
brew link valgrind
This seemed to solve other people's problems with linking an already installed software but this gave me an error:
Linking /usr/local/Cellar/valgrind/HEAD...
Error: Could not symlink lib/pkgconfig/valgrind.pc
/usr/local/lib/pkgconfig is not writable.
I also tried to update brew but it didn't solve the issue. If it is not writable, maybe sudo would give me permission but I don't want to use sudo without knowing exactly what I am doing.
What is happening and how to I fix it?
Looks like a permission issue. I would try doing this
chmod 755 /usr/local/lib/pkgconfig
This should make that available, then try
brew link valgrind
If that doesn't work I would try doing a check on it
brew doctor
First run
brew link <package>
If it gives an error, try for an automated diagnosis
brew doctor
brew doctor gives a list of problems that could be leading to errors in installation process.
To fix problems in case of conflicting files,
run to get a list of all actions which will be performed by overwrite without actually performing them.
To list all files that would be deleted:
brew link --overwrite --dry-run <package>
followed by this run which will execute the overwrite, assuming you feel that the actions performed by overwrite will take your system to a more stable state.
To force the link and overwrite all conflicting files:
brew link --overwrite <package>
If none of above the solution works, try this.
sudo chown -R $USER:admin /usr/local
brew link <package-name>
In my case, brew doctor got it right. At some point /usr/local/lib/pkgconfig was set to be owned by root rather than my account. The prescribed remedy worked -
sudo chown -R $(whoami) /usr/local/lib/pkgconfig
I had same problem and i resolved with next solution:
Run brew doctor from Terminal to check all your errors
then run next command:
sudo chown -R $USER:admin /usr/local/bin /usr/local/etc /usr/local/sbin /usr/local/share
after run:
brew link <package_name>
Type
link valgrind
It will show an error that it can't be linked because such-and-such directory is not writable. Cool, we make it writable now. Type
sudo chmod a+w the/directory/shown/as/error
If the directory is not writable, you wont be able to change its permission and make it writable either. Sudo will make this operation possible. chmod will change the mode and will make all(a) users be able to write(w) it.
Next you will be prompted to type your system's password. After this, again type
link valgrind
and it will work this time.
Here is what I tried and it worked:
$ brew link --overwrite sdl
Linking /usr/local/Cellar/sdl/1.2.15...
Error: Could not symlink lib/pkgconfig/sdl.pc
/usr/local/lib/pkgconfig is not writable.
Looked for pkgconfig: (after chmod 750)
drwxr-xr-x 4 root wheel 136B Mar 30 2013 pkgconfig
I tried chown as below:
$ sudo chown -R avkashchauhan:admin /usr/local/lib/pkgconfig
it should look like as below:
drwxr-xr-x 4 avkashchauhan admin 136B Mar 30 2013 pkgconfig
After I tried it:
$ brew link sdl
Linking /usr/local/Cellar/sdl/1.2.15... 182 symlinks created
brew install cocoapods --build-from-source
brew link --overwrite cocoapods
The only commands that worked for me on after upgrading to MAC OS Mojave 10.14.6
I got a similar problem,
$ brew install sqlite
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
No changes to formulae.
Warning: sqlite-3.17.0 already installed, it's just not linked.
I tried to link it,
$ brew link sqlite
Warning: sqlite is keg-only and must be linked with --force
Note that doing so can interfere with building software.
Then do it by force,
$ brew link --force sqlite
Linking /usr/local/Cellar/sqlite/3.17.0... 8 symlinks created
I had same a problem about permission, but after I give my permission, still error permission. And here I do, first:
brew unlink valgrind
and then,
brew link valgrind
hope this help.
I had the similar issue. I needed to brew link carthage.
But none of answers worked for me.
I've also seen the next error for any command I tried:
Error: Could not symlink .
/usr/local/opt is not writable
Only one solution helped:
Open the Finder;
Command + Shift + G;
Pass the /usr/local path;
Create opt folder manually (that was the folder name from my error message, but in your case it can be something different, such as lib/pkgconfig in the original question, so check yours in the Terminal);
re-run your command again.

Fixing brew doctor warnings/errors

I have recently installed Homebrew and RVM. However, when I tried to install a new version of Ruby into RVM:...
rvm install 2.2
I got the following error:
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.9/x86_64/ruby-2.2.0.tar.bz2
Checking requirements for osx.
ERROR: '/usr/local/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.
So I ran the doctor command to view errors and saw:
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: /usr/local/bin isn't writable.
This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.
I found the same issue with various other directories:
/Library/Caches/Homebrew
/usr/local/Cellar
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/lib/pkgconfig
/usr/local/opt
/usr/local/share
/usr/local/share/man
/usr/local
When I installed RVM, I did a single user install into a non admin account. This non admin account I will be using as my development account. Is this ok, or should I be developing using an admin account? I am running into all sorts of permissions type issues; eg trying to install a gem, because of write permissions failures and am now questioning what is the proper way to develop code, without being an admin, or should I be an admin?
I was going to start using chown to fix these errors ie
chown $USER -R /usr/local/bin
but, this worries me. Do I want to be changing the owner of all these system directories to my non admin account? Just want some re-assurance really before I go ahead, it just feels, wrong. (PS; is that the correct use of chown?)
I've seen other articles that suggest using sudo, but I've also seen artciles that say you shouldn't use sudo. Err-ing on the side of caution, I would rather not use sudo.
Thanks.
Most of these questions are pretty well covered by the Homebrew FAQ.
Do I want to be changing the owner of all these system directories to my non admin account?
System libraries are not installed to /usr/local. Apple doesn't include that directory on a clean install. Most likely some other installer put things there as root or another user.
I've seen other articles that suggest using sudo, but I've also seen artciles that say you shouldn't use sudo.
Homebrew should not be used with sudo, but it does assume the user is an admin and has rights to /usr/local. If you are just referring to fixing the permissions with chown, that will require sudo (and admin account).

Using rbenv doesn't work with sudo?

Any commands that use sudo don't seem to work with RBenv.
I'm trying to install ActiveRecord and it says I don't have write permission, so when I try this:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/local/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1 directory.
It says:
sudo: gem: command not found
How can I get around this?
The idea behind tools like rbenv and RVM is that you don't need to use sudo, because your entire Ruby environment exists inside your own workspace as a sandbox.
RVM allows multi-user configurations though it was originally designed for single users.
As far as I've ever seen or read, rbenv is single-user only. At no time should you need to use sudo to manipulate or change your Ruby environment when using rbenv. If you do, something is wrong. If you try to use sudo, you'll screw things up. You might not find out immediately but eventually something will pop up and you'll need to change the ownership of the files back to you.
On Linux and Mac OS you can do that pretty easily using:
sudo chown -R <your_user_name>:<your_group> ~/.rbenv
You have to run that as sudo because only the super-user can change ownership of files owned by root. sudo escalates your privileges to allow you to change those things.
I realise this is kind of old now, but this may help people in future:
rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.
https://github.com/dcarley/rbenv-sudo
My answer in "Installing Ruby 2.0 and Rails 4.0.0beta on AWS EC2" might be useful to you.
In short, the root user needs to have rbenv loaded in its environment for you to use the gems installed by rbenv. This can be done by adding the following
# /etc/profile.d/rbenv.sh
export RBENV_ROOT=/usr/local/rbenv
export PATH="${RBENV_ROOT}/bin:$PATH"
eval "$(rbenv init -)"
This should be sufficient for sudo to work. If you are writing a shell script, you might need to use
. /etc/profile.d/rbenv.sh
before using executables from other gems.
My answer is a little bit late but I have simple solution for this issue. Use symbolic links to be able use binstubs and other Ruby stuff.
ln -s ~/.rbenv/bin/rbenv /usr/local/bin/rbenv
ln -s ~/.rbenv/shims/* /usr/local/bin
I hope that helps to other users who is having the same issue.

Resources