1local::lib(3) User Contributed Perl Documentation local::lib(3)
2
3
4
6 local::lib - create and use a local lib/ for perl modules with PERL5LIB
7
9 In code -
10
11 use local::lib; # sets up a local lib at ~/perl5
12
13 use local::lib '~/foo'; # same, but ~/foo
14
15 # Or...
16 use FindBin;
17 use local::lib "$FindBin::Bin/../support"; # app-local support library
18
19 From the shell -
20
21 # Install LWP and its missing dependencies to the '~/perl5' directory
22 perl -MCPAN -Mlocal::lib -e 'CPAN::install(LWP)'
23
24 # Just print out useful shell commands
25 $ perl -Mlocal::lib
26 export PERL_MB_OPT='--install_base /home/username/perl5'
27 export PERL_MM_OPT='INSTALL_BASE=/home/username/perl5'
28 export PERL5LIB='/home/username/perl5/lib/perl5/i386-linux:/home/username/perl5/lib/perl5'
29 export PATH="/home/username/perl5/bin:$PATH"
30
31 The bootstrapping technique
32 A typical way to install local::lib is using what is known as the
33 "bootstrapping" technique. You would do this if your system
34 administrator hasn't already installed local::lib. In this case,
35 you'll need to install local::lib in your home directory.
36
37 If you do have administrative privileges, you will still want to set up
38 your environment variables, as discussed in step 4. Without this, you
39 would still install the modules into the system CPAN installation and
40 also your Perl scripts will not use the lib/ path you bootstrapped with
41 local::lib.
42
43 By default local::lib installs itself and the CPAN modules into
44 ~/perl5.
45
46 Windows users must also see "Differences when using this module under
47 Win32".
48
49 1. Download and unpack the local::lib tarball from CPAN (search for
50 "Download" on the CPAN page about local::lib). Do this as an ordinary
51 user, not as root or administrator. Unpack the file in your home
52 directory or in any other convenient location.
53
54 2. Run this:
55
56 perl Makefile.PL --bootstrap
57
58 If the system asks you whether it should automatically configure as
59 much as possible, you would typically answer yes.
60
61 In order to install local::lib into a directory other than the default,
62 you need to specify the name of the directory when you call bootstrap,
63 as follows:
64
65 perl Makefile.PL --bootstrap=~/foo
66
67 3. Run this: (local::lib assumes you have make installed on your
68 system)
69
70 make test && make install
71
72 4. Now we need to setup the appropriate environment variables, so that
73 Perl starts using our newly generated lib/ directory. If you are using
74 bash or any other Bourne shells, you can add this to your shell startup
75 script this way:
76
77 echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >>~/.bashrc
78
79 If you are using C shell, you can do this as follows:
80
81 /bin/csh
82 echo $SHELL
83 /bin/csh
84 perl -I$HOME/perl5/lib/perl5 -Mlocal::lib >> ~/.cshrc
85
86 If you passed to bootstrap a directory other than default, you also
87 need to give that as import parameter to the call of the local::lib
88 module like this way:
89
90 echo 'eval $(perl -I$HOME/foo/lib/perl5 -Mlocal::lib=$HOME/foo)' >>~/.bashrc
91
92 After writing your shell configuration file, be sure to re-read it to
93 get the changed settings into your current shell's environment. Bourne
94 shells use ". ~/.bashrc" for this, whereas C shells use "source
95 ~/.cshrc".
96
97 If you're on a slower machine, or are operating under draconian disk
98 space limitations, you can disable the automatic generation of manpages
99 from POD when installing modules by using the "--no-manpages" argument
100 when bootstrapping:
101
102 perl Makefile.PL --bootstrap --no-manpages
103
104 To avoid doing several bootstrap for several Perl module environments
105 on the same account, for example if you use it for several different
106 deployed applications independently, you can use one bootstrapped
107 local::lib installation to install modules in different directories
108 directly this way:
109
110 cd ~/mydir1
111 perl -Mlocal::lib=./
112 eval $(perl -Mlocal::lib=./) ### To set the environment for this shell alone
113 printenv ### You will see that ~/mydir1 is in the PERL5LIB
114 perl -MCPAN -e install ... ### whatever modules you want
115 cd ../mydir2
116 ... REPEAT ...
117
118 For multiple environments for multiple apps you may need to include a
119 modified version of the "use FindBin" instructions in the "In code"
120 sample above. If you did something like the above, you have a set of
121 Perl modules at "~/mydir1/lib". If you have a script at
122 "~/mydir1/scripts/myscript.pl", you need to tell it where to find the
123 modules you installed for it at "~/mydir1/lib".
124
125 In "~/mydir1/scripts/myscript.pl":
126
127 use strict;
128 use warnings;
129 use local::lib "$FindBin::Bin/.."; ### points to ~/mydir1 and local::lib finds lib
130 use lib "$FindBin::Bin/../lib"; ### points to ~/mydir1/lib
131
132 Put this before any BEGIN { ... } blocks that require the modules you
133 installed.
134
135 Differences when using this module under Win32
136 To set up the proper environment variables for your current session of
137 "CMD.exe", you can use this:
138
139 C:\>perl -Mlocal::lib
140 set PERL_MB_OPT=--install_base C:\DOCUME~1\ADMINI~1\perl5
141 set PERL_MM_OPT=INSTALL_BASE=C:\DOCUME~1\ADMINI~1\perl5
142 set PERL5LIB=C:\DOCUME~1\ADMINI~1\perl5\lib\perl5;C:\DOCUME~1\ADMINI~1\perl5\lib\perl5\MSWin32-x86-multi-thread
143 set PATH=C:\DOCUME~1\ADMINI~1\perl5\bin;%PATH%
144
145 ### To set the environment for this shell alone
146 C:\>perl -Mlocal::lib > %TEMP%\tmp.bat && %TEMP%\tmp.bat && del %TEMP%\temp.bat
147 ### instead of $(perl -Mlocal::lib=./)
148
149 If you want the environment entries to persist, you'll need to add then
150 to the Control Panel's System applet yourself or use
151 App::local::lib::Win32Helper.
152
153 The "~" is translated to the user's profile directory (the directory
154 named for the user under "Documents and Settings" (Windows XP or
155 earlier) or "Users" (Windows Vista or later)) unless $ENV{HOME} exists.
156 After that, the home directory is translated to a short name (which
157 means the directory must exist) and the subdirectories are created.
158
160 The version of a Perl package on your machine is not always the version
161 you need. Obviously, the best thing to do would be to update to the
162 version you need. However, you might be in a situation where you're
163 prevented from doing this. Perhaps you don't have system administrator
164 privileges; or perhaps you are using a package management system such
165 as Debian, and nobody has yet gotten around to packaging up the version
166 you need.
167
168 local::lib solves this problem by allowing you to create your own
169 directory of Perl packages downloaded from CPAN (in a multi-user
170 system, this would typically be within your own home directory). The
171 existing system Perl installation is not affected; you simply invoke
172 Perl with special options so that Perl uses the packages in your own
173 local package directory rather than the system packages. local::lib
174 arranges things so that your locally installed version of the Perl
175 packages takes precedence over the system installation.
176
177 If you are using a package management system (such as Debian), you
178 don't need to worry about Debian and CPAN stepping on each other's
179 toes. Your local version of the packages will be written to an
180 entirely separate directory from those installed by Debian.
181
183 This module provides a quick, convenient way of bootstrapping a user-
184 local Perl module library located within the user's home directory. It
185 also constructs and prints out for the user the list of environment
186 variables using the syntax appropriate for the user's current shell (as
187 specified by the "SHELL" environment variable), suitable for directly
188 adding to one's shell configuration file.
189
190 More generally, local::lib allows for the bootstrapping and usage of a
191 directory containing Perl modules outside of Perl's @INC. This makes it
192 easier to ship an application with an app-specific copy of a Perl
193 module, or collection of modules. Useful in cases like when an upstream
194 maintainer hasn't applied a patch to a module of theirs that you need
195 for your application.
196
197 On import, local::lib sets the following environment variables to
198 appropriate values:
199
200 PERL_MB_OPT
201 PERL_MM_OPT
202 PERL5LIB
203 PATH
204 PATH is appended to, rather than clobbered.
205
206 These values are then available for reference by any code after import.
207
209 See lib::core::only for one way to do this - but note that there are a
210 number of caveats, and the best approach is always to perform a build
211 against a clean perl (i.e. site and vendor as close to empty as
212 possible).
213
215 ensure_dir_structure_for
216 Arguments: $path
217 Return value: None
218
219 Attempts to create the given path, and all required parent directories.
220 Throws an exception on failure.
221
222 print_environment_vars_for
223 Arguments: $path
224 Return value: None
225
226 Prints to standard output the variables listed above, properly set to
227 use the given path as the base directory.
228
229 build_environment_vars_for
230 Arguments: $path, $interpolate
231 Return value: \%environment_vars
232
233 Returns a hash with the variables listed above, properly set to use the
234 given path as the base directory.
235
236 setup_env_hash_for
237 Arguments: $path
238 Return value: None
239
240 Constructs the %ENV keys for the given path, by calling
241 "build_environment_vars_for".
242
243 install_base_perl_path
244 Arguments: $path
245 Return value: $install_base_perl_path
246
247 Returns a path describing where to install the Perl modules for this
248 local library installation. Appends the directories "lib" and "perl5"
249 to the given path.
250
251 install_base_arch_path
252 Arguments: $path
253 Return value: $install_base_arch_path
254
255 Returns a path describing where to install the architecture-specific
256 Perl modules for this local library installation. Based on the
257 "install_base_perl_path" method's return value, and appends the value
258 of $Config{archname}.
259
260 install_base_bin_path
261 Arguments: $path
262 Return value: $install_base_bin_path
263
264 Returns a path describing where to install the executable programs for
265 this local library installation. Based on the "install_base_perl_path"
266 method's return value, and appends the directory "bin".
267
268 resolve_empty_path
269 Arguments: $path
270 Return value: $base_path
271
272 Builds and returns the base path into which to set up the local module
273 installation. Defaults to "~/perl5".
274
275 resolve_home_path
276 Arguments: $path
277 Return value: $home_path
278
279 Attempts to find the user's home directory. If installed, uses
280 "File::HomeDir" for this purpose. If no definite answer is available,
281 throws an exception.
282
283 resolve_relative_path
284 Arguments: $path
285 Return value: $absolute_path
286
287 Translates the given path into an absolute path.
288
289 resolve_path
290 Arguments: $path
291 Return value: $absolute_path
292
293 Calls the following in a pipeline, passing the result from the previous
294 to the next, in an attempt to find where to configure the environment
295 for a local library installation: "resolve_empty_path",
296 "resolve_home_path", "resolve_relative_path". Passes the given path
297 argument to "resolve_empty_path" which then returns a result that is
298 passed to "resolve_home_path", which then has its result passed to
299 "resolve_relative_path". The result of this final call is returned from
300 "resolve_path".
301
303 Be careful about using local::lib in combination with "make install
304 UNINST=1". The idea of this feature is that will uninstall an old
305 version of a module before installing a new one. However it lacks a
306 safety check that the old version and the new version will go in the
307 same directory. Used in combination with local::lib, you can
308 potentially delete a globally accessible version of a module while
309 installing the new version in a local place. Only combine "make install
310 UNINST=1" and local::lib if you understand these possible consequences.
311
313 The perl toolchain is unable to handle directory names with spaces in
314 it, so you cant put your local::lib bootstrap into a directory with
315 spaces. What you can do is moving your local::lib to a directory with
316 spaces after you installed all modules inside your local::lib
317 bootstrap. But be aware that you cant update or install CPAN modules
318 after the move.
319
320 Rather basic shell detection. Right now anything with csh in its name
321 is assumed to be a C shell or something compatible, and everything else
322 is assumed to be Bourne, except on Win32 systems. If the "SHELL"
323 environment variable is not set, a Bourne-compatible shell is assumed.
324
325 Bootstrap is a hack and will use CPAN.pm for ExtUtils::MakeMaker even
326 if you have CPANPLUS installed.
327
328 Kills any existing PERL5LIB, PERL_MM_OPT or PERL_MB_OPT.
329
330 Should probably auto-fixup CPAN config if not already done.
331
332 Patches very much welcome for any of the above.
333
334 On Win32 systems, does not have a way to write the created environment
335 variables to the registry, so that they can persist through a reboot.
336
338 If you've configured local::lib to install CPAN modules somewhere in to
339 your home directory, and at some point later you try to install a
340 module with "cpan -i Foo::Bar", but it fails with an error like:
341 "Warning: You do not have permissions to install into
342 /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux at
343 /usr/lib64/perl5/5.8.8/Foo/Bar.pm" and buried within the install log is
344 an error saying "'INSTALL_BASE' is not a known MakeMaker parameter
345 name", then you've somehow lost your updated ExtUtils::MakeMaker
346 module.
347
348 To remedy this situation, rerun the bootstrapping procedure documented
349 above.
350
351 Then, run "rm -r ~/.cpan/build/Foo-Bar*"
352
353 Finally, re-run "cpan -i Foo::Bar" and it should install without
354 problems.
355
357 SHELL
358 COMSPEC
359 local::lib looks at the user's "SHELL" environment variable when
360 printing out commands to add to the shell configuration file.
361
362 On Win32 systems, "COMSPEC" is also examined.
363
365 IRC:
366
367 Join #local-lib on irc.perl.org.
368
370 Matt S Trout <mst@shadowcat.co.uk> http://www.shadowcat.co.uk/
371
372 auto_install fixes kindly sponsored by http://www.takkle.com/
373
375 Patches to correctly output commands for csh style shells, as well as
376 some documentation additions, contributed by Christopher Nehren
377 <apeiron@cpan.org>.
378
379 Doc patches for a custom local::lib directory, more cleanups in the
380 english documentation and a german documentation contributed by Torsten
381 Raudssus <torsten@raudssus.de>.
382
383 Hans Dieter Pearcey <hdp@cpan.org> sent in some additional tests for
384 ensuring things will install properly, submitted a fix for the bug
385 causing problems with writing Makefiles during bootstrapping,
386 contributed an example program, and submitted yet another fix to ensure
387 that local::lib can install and bootstrap properly. Many, many thanks!
388
389 pattern of Freenode IRC contributed the beginnings of the
390 Troubleshooting section. Many thanks!
391
392 Patch to add Win32 support contributed by Curtis Jewell
393 <csjewell@cpan.org>.
394
395 Warnings for missing PATH/PERL5LIB (as when not running interactively)
396 silenced by a patch from Marco Emilio Poleggi.
397
398 Mark Stosberg <mark@summersault.com> provided the code for the now
399 deleted '--self-contained' option.
400
401 Documentation patches to make win32 usage clearer by David Mertens
402 <dcmertens.perl@gmail.com> (run4flat).
403
404 Brazilian portuguese translation and minor doc patches contributed by
405 Breno G. de Oliveira <garu@cpan.org>.
406
408 Copyright (c) 2007 - 2010 the local::lib "AUTHOR" and "CONTRIBUTORS" as
409 listed above.
410
412 This library is free software and may be distributed under the same
413 terms as perl itself.
414
415
416
417perl v5.12.2 2011-01-09 local::lib(3)