codecowboy
codecowboy

Reputation: 10095

What is the correct way to install brews and gems on OS X

It seems every time I want to install something locally on Snow Leopard, I run into an issue about whether to install to /usr/local or whether or not to run install commands using sudo. I've read conflicting advice on this, including on stackoverflow

Gem install errors writable and PATH (use sudo) gem install permission problem (do not use sudo in comments)

Should I be installing brew formula and gems using sudo? How can I avoid errors and warnings when I install without sudo privileges?

e.g when running gem update:

WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
      /usr/bin aren't both writable.
WARNING:  You don't have /Users/luke/.gem/ruby/1.8/bin in your PATH,
      gem executables will not run.

I'm not a ruby developer but want to use sass and compass, so it seems like overkill to install rvm. Will just adding ruby to my path resolve all these issues? I also saw somewhere that I should chown /usr/local. It would be good to finally get to the bottom of this.

Upvotes: 0

Views: 1588

Answers (2)

skorks
skorks

Reputation: 4366

You're doing yourself a great disservice by dismissing RVM. I don't think it is overkill at all, in the time it would have taken you to write this SO question, RVM would have installed AND you would have also finished installing Ruby (1.8 or 1.9 whichever you prefer). Then your gem warnings and sudo problems would have been non-issues. Pretty much everyone in the ruby community is using RVM these days (unless they are on windows), including, in some cases, in production.

Having said all of that, Homebrew (which you mentioned) has a wiki page that talks about sudo, installing gems to /usr/local, rubygems etc. You could do worse than follow their advice.

Upvotes: 3

LaC
LaC

Reputation: 12824

I prefer to use sudo, so I am sure that programs running with normal privileges can't mess with system-wide files. I also normally run as a non-administrator user for the same reason. This means that I am protected from damaging the system even accidentally, but when I decide to install something to /usr/local I have to use sudo, so I only do that when I'm sure that it won't make a mess. For stuff that I'm not sure about, or that I simply want to try, etc., I install to a prefix in my home.

Other people have a more single-user mentality, and chown /usr/local to themselves. They're ok with the risk of messing up its contents with normal usage: for instance, if they try to install something to a prefix in their home, but the configure is borked, it could install some pieces in /usr/local without so much as a warning. OTOH, when they install to /usr/local they are sure that they won't affect the rest of the system, only /usr/local and their own home.

But then, /usr/local is just an extension of their home directory, since it has the same ownership and the same privileges. They might as well install to ~/usr/ and add ~/usr/bin to their PATH, which is what I do when I want to install things for myself.

The very best way would probably be to chgrp /usr/local to some special group, and sudo to a special user in that group that can write to that directory, but not do other random sudo stuff. Maybe someday I'll get around to configuring it that way. In the meantime, I prefer to use sudo when I want to install to /usr/local. The advantage of using a package manager like homebrew is that formulas have been checked to ensure that they install cleanly, and they can easily be uninstalled.

Upvotes: 1

Related Questions