Update RBI files for parser.
[Homebrew/brew.git] / docs / Gems,-Eggs-and-Perl-Modules.md
blobaf20804fca52201518404230d018ff7cd43cee99
1 ---
2 last_review_date: "1970-01-01"
3 ---
5 # Gems, Eggs and Perl Modules
7 On a fresh macOS installation there are two empty directories for
8 add-ons available to all users:
10 * `/Library/Ruby`
11 * `/Library/Perl`
13 You need sudo to install to these like so: `sudo gem install`
14 or `sudo cpan -i`.
16 ## Python packages (eggs) without sudo using system Python
18 An option to avoid sudo is to use an access control list. For example:
20 ```sh
21 chmod +a 'user:<YOUR_NAME_HERE> allow add_subdirectory,add_file,delete_child,directory_inherit' /Library/Python/3.y/site-packages
22 ```
24 will let you add packages to Python 3.y as yourself, which
25 is probably safer than changing the group ownership of the directory.
27 ### So why was I using sudo?
29 Habit maybe?
31 One reason is executables go in `/usr/local/bin`. Usually this isn’t a
32 writable location. But if you installed Homebrew as we recommend on macOS Intel,
33 `/usr/local` will be writable without sudo. So now you are good to
34 install the development tools you need without risking the use of sudo.
36 ### An alternative package path
38 _This is only recommended if you **don't** use a brewed Python._
40 On macOS, any Python version X.Y [also searches in
41 `~/Library/Python/X.Y/lib/python/site-packages` for
42 modules](https://docs.python.org/2/install/index.html#alternate-installation-the-user-scheme).
43 That path might not yet exist, but you can create it:
45 ```sh
46 mkdir -p ~/Library/Python/2.7/lib/python/site-packages
47 ```
49 To teach `easy_install` and `pip` to install there, either use the
50 `--user` switch or create a `~/.pydistutils.cfg` file with the
51 following content:
53     [install]
54     install_lib = ~/Library/Python/$py_version_short/lib/python/site-packages
56 ### Using virtualenv (with system Python)
58 [Virtualenv](https://virtualenv.pypa.io/) ships `pip` and
59 creates isolated Python environments with separate `site-packages`,
60 which therefore don’t need sudo.
62 ## Rubygems without sudo
64 _This is only recommended if you **don't** use rbenv or RVM._
66 Brewed Ruby installs executables to `$(brew --prefix ruby)/bin`
67 without sudo. You should add this to your path. See the caveats in the
68 `ruby` formula for up-to-date information.
70 ### With system Ruby
72 To make Ruby install to `/usr/local`, we need to add
73 `gem: -n/usr/local/bin` to your `~/.gemrc`. It’s YAML, so do it manually
74 or use this:
76 ```sh
77 echo "gem: -n/usr/local/bin" >> ~/.gemrc
78 ```
80 **However, all versions of RubyGems before 1.3.6 are buggy** and ignore
81 the above setting. Sadly a fresh install of Snow Leopard comes with
82 1.3.5. Currently the only known way to get around this is to upgrade
83 rubygems as root:
85 ```sh
86 sudo gem update --system
87 ```
89 ### An alternative gem path
91 Just install everything into the Homebrew prefix like this:
93 ```sh
94 echo "export GEM_HOME=\"$(brew --prefix)\"" >> ~/.bashrc
95 ```
97 ### It doesn’t work! I get some “permissions” error when I try to install stuff
99 _Note that you may not want to do this, since Apple has decided it
100 is not a good default._
102 If you ever did a `sudo gem`, etc. before then a lot of files will have
103 been created owned by root. Fix with:
105 ```sh
106 sudo chown -R $(whoami) /Library/Ruby/* /Library/Perl/* /Library/Python/*
109 ## Perl CPAN modules without sudo
111 The Perl module `local::lib` works similarly to rbenv/RVM (although for
112 modules only, not Perl installations). A simple solution that only
113 pollutes your `/Library/Perl` a little is to install
114 [`local::lib`](https://metacpan.org/pod/local::lib) with sudo:
116 ```sh
117 sudo cpan local::lib
120 Note that this will install some other dependencies like `Module::Install`.
121 Then put the appropriate incantation in your shell’s startup, e.g. for
122 `.profile` you'd insert the below; for others see the
123 [`local::lib`](https://metacpan.org/pod/local::lib) docs.
125 ```sh
126 eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
129 Now (after you restart your shell) `cpan` or `perl -MCPAN -eshell` etc.
130 will install modules and binaries in `~/perl5` and the relevant
131 subdirectories will be in your `PATH` and `PERL5LIB`.
133 ### Avoiding sudo altogether for Perl
135 If you don’t even want to (or can’t) use sudo for bootstrapping
136 `local::lib`, just manually install `local::lib` in
137 `~/perl5` and add the relevant path to `PERL5LIB` before the `.bashrc` eval incantation.
139 Another alternative is to use `perlbrew` to install a separate copy of Perl in your home directory, or wherever you like:
141 ```sh
142 curl -L https://install.perlbrew.pl | bash
143 perlbrew install perl-5.16.2
144 echo ".~/perl5/perlbrew/etc/bashrc" >> ~/.bashrc