-
Notifications
You must be signed in to change notification settings - Fork 0
Gems, Eggs and Perl Modules
On a fresh OS X installation there are three empty directories:
/Library/Ruby /Library/Python /Library/Perl
When you gem install
, easy_install
or cpan -i
stuff gets installed to these directories in a nicely segregated fashion similar to Homebrew.
These directories start empty — you are meant to fill them with your stuff and not worry about it.
On fresh OS X installing to these three directories doesn’t require sudo. Please note that since Lion these directories are no longer staff-group writable. As yet we are not sure what to suggest as an alternative. One option is a chgrp -R
, but do so with caution. Another option is to use an access control list: chmod +a 'user:YOUR_NAME_HERE allow add_subdirectory,add_file,delete_child,directory_inherit' /Library/Python/2.7/site-packages
, for example, will let you add packages to Python 2.7 as yourself. That is probably safer than changing the group ownership of the directory.
Habit maybe?
One reason is executables go in /usr/local/bin
. Usually this isn’t a writable location. But if you installed Homebrew as we recommend, /usr/local
will be writable without sudo. So now you are good to install the development tools you need without risking a sudo.
If you use RVM then you should ignore this stuff.
Ruby installs executables to ~/.gem/bin
without sudo. This is non-ideal, so this section is about making it install to /usr/local
instead.
We need to add gem: -n/usr/local/bin
to your ~/.gemrc
. It’s YAML…so do it manually or use this:
echo "gem: -n/usr/local/bin" >> ~/.gemrc
However all versions of RubyGems before 1.3.6 are buggy and ignore the above setting. Sadly a fresh install of Snow Leopard comes with 1.3.5. Currently the only known way to get round this is to upgrade rubygems as root:
sudo gem update --system
Just install everything into the Homebrew prefix like this:
echo "export GEM_HOME='$(brew --prefix)'" >> ~/.bashrc
Note, maybe you shouldn’t do this on Lion, since Apple have decided it is not a good default.
If you ever did a sudo gem
, etc. before then a lot of files will have been created chown root. Fix with:
sudo chown -R $USER /Library/Ruby /Library/Perl /Library/Python
The Perl module local::lib works similarly to rvm (although for modules only, not perl installations). A simple solution that only pollutes your /Library/Perl a little is to install local::lib with sudo:
sudo cpan local::lib
Note that will install some other dependencies like Module::Install
. Then put the appropriate incantation in your shell’s startup, eg. for .bash_profile you insert the below, for others see the local::lib docs.
eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)
Now (after you restart your shell) cpan
or perl -MCPAN -eshell
etc. will install modules and binaries in ~/perl5
and the relevant subdirectories will be in your PATH
and PERL5LIB
etc.
If you don’t even want (or can’t) use sudo for bootstrapping local::lib
just manually install local::lib
in ~/perl5 (or wherever you want) and add the relevant path to PERL5LIB
before the .bashrc eval incantation.