source: gs3-extensions/hathitrust-downloadfrom/trunk/docs/Installing-Perl-Modules-Under-User-Control.html@ 26436

Last change on this file since 26436 was 26436, checked in by davidb, 11 years ago

Initial cut at code for exporting content out of the Hathitrust, suitable for ingest by Greenstone

File size: 12.4 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"><head>
3<title>Installing Perl Modules as a Non-Root User LG #139</title>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<link rel="stylesheet" href="Installing-Perl-Modules-Under-User-Control_files/lg.css" type="text/css" media="screen, projection">
6<link rel="alternate" type="application/rss+xml" title="LG RSS" href="http://linuxgazette.net/139/lg.rss">
7<link rel="alternate" type="application/rdf+xml" title="LG RDF" href="http://linuxgazette.net/139/lg.rdf">
8<link rel="alternate" type="application/atom+xml" title="LG Atom" href="http://linuxgazette.net/139/lg.atom.xml">
9<link rel="shortcut icon" href="http://linuxgazette.net/favicon.ico">
10
11<style type="text/css" media="screen, projection">
12<!--
13
14-->
15</style>
16
17</head>
18<body>
19
20<a href="http://linuxgazette.net/">
21<img src="Installing-Perl-Modules-Under-User-Control_files/newlogo-blank-200-gold2.jpg" id="logo" alt="Linux Gazette">
22</a>
23<p id="fun">...making Linux just a little more fun!</p>
24
25<div id="navigation">
26<table summary="masthead" width="100%">
27<tbody><tr>
28<td colspan="3" style="font-size: 10px; font-weight: bold" align="center">
29<a href="http://linuxgazette.net/index.html">Home</a>
30<a href="http://linuxgazette.net/">Main Site</a>
31<a href="http://linuxgazette.net/faq/index.html">FAQ</a>
32
33<a href="http://linuxgazette.net/lg_index.html">Site Map</a>
34<a href="http://linuxgazette.net/mirrors.html">Mirrors</a>
35<a href="http://linuxgazette.net/mirrors.html">Translations</a>
36<a href="http://linuxgazette.net/search.html">Search</a>
37<a href="http://linuxgazette.net/archives.html">Archives</a>
38<a href="http://linuxgazette.net/authors/index.html">Authors</a>
39<a href="http://lists.linuxgazette.net/mailman/listinfo/">Mailing Lists</a>
40<a href="http://linuxgazette.net/jobs.html">Join Us!</a>
41<a href="http://linuxgazette.net/contact.html">Contact Us</a>
42
43<hr style="border: 1px inset #000033" width="99%">
44</td>
45</tr>
46<tr>
47<td style="font-size: 10px; font-weight: bold" align="left" width="40%">
48The Free International Online Linux Monthly
49</td>
50<td style="font-size: 10px; font-weight: bold" align="center" width="20%">
51ISSN: 1934-371X
52</td>
53<td style="font-size: 10px; font-weight: bold" align="right" width="40%">
54Main site: <a href="http://linuxgazette.net/">http://linuxgazette.net</a>
55</td>
56</tr></tbody></table>
57</div>
58
59
60<div id="breadcrumbs1">
61
62<a href="http://linuxgazette.net/index.html">Home</a> &gt;
63<a href="http://linuxgazette.net/139/index.html">June 2007 (#139)</a> &gt;
64Article
65
66</div>
67
68<div class="articlecontent1">
69<div class="content">
70
71<div id="previousnexttop">
72<a href="http://linuxgazette.net/139/jordan.html">&lt;-- prev</a> | <a href="http://linuxgazette.net/139/peterson.html">next --&gt;</a>
73</div>
74
75<h1>Installing Perl Modules as a Non-Root User</h1>
76<p id="by"><b>By <a href="http://linuxgazette.net/authors/okopnik.html">Ben Okopnik</a></b></p>
77
78<h3>Introduction</h3>
79
80<p>
81If you use Perl for anything more complex than the traditional (and boring)
82generation of "Hello, World", then it's also likely that you're familiar
83with those wonderful work-saving devices - Perl modules. Furthermore,
84chances are that you're also familiar with CPAN, the <a href="http://cpan.org/">Comprehensive Perl Archive Network</a>, and the
85easy interface to it that is provided by the CPAN module. That all works
86just great - assuming that you a) run a sensible modern OS like Linux, and
87b) have root access to the machine you're using (or have a friendly and
88cooperative sysadmin). But what if those assumptions don't hold true? What
89if, for example, you have a shell account on a machine run by some
90mega-corporation that doesn't feel like installing the
91Foo::Bar::Zotz::Blagger-0.01 module in their /usr/lib/perl? I, for one,
92can't blame them; a system-wide installation could open them up to unknown
93bugs galore. When your interests and theirs conflict, you lose every time -
94since they own the system.
95</p>
96
97<p>
98So, what can we do if we really, really need that module but can't get it
99installed on a system-wide basis? The answer is to install it elsewhere -
100in some directory where you have write permissions.
101</p>
102
103<h3>Configuring the Environment</h3>
104
105<p>
106Clearly, if you're not root, you're not going to be able to save the files
107to their default locations under '/usr/' - which is where they would
108normally go. Therefore, we need to tell Perl where to find the modules
109that we'll install. Fortunately, this is the easy part: just decide on the
110location where you'll install the modules, create that directory if it
111doesn't already exist, append '/lib' to its name, and set the PERL5LIB
112variable to that string. E.g., if you're using Bash, then edit your
113~/.bash_profile and add the following:
114</p>
115
116<pre>if [ -z "$PERL5LIB" ]
117then
118 # If PERL5LIB wasn't previously defined, set it...
119 PERL5LIB=~/myperl/lib
120else
121 # ...otherwise, extend it.
122 PERL5LIB=$PERL5LIB:~/myperl/lib
123fi
124
125MANPATH=$MANPATH:~/myperl/man
126
127export PERL5LIB MANPATH
128</pre>
129
130<p>
131Now, create the three necessary directories:
132</p>
133
134<pre>mkdir -p ~/myperl/lib
135mkdir -p ~/myperl/man/man{1,3}
136</pre>
137
138<p>
139After you've logged out and back in, Perl will treat that location as a
140part of @INC (the list of directories to search for libraries and modules.)
141If you want to confirm that it's actually happened, just execute the
142following and use your directory name as the argument to 'grep':
143</p>
144
145<pre>perl -wle'print for grep /myperl/, @INC'
146</pre>
147
148<h3>Installing the Modules</h3>
149
150<pre>perl -MCPAN -we 'shell'
151</pre>
152
153<p>
154First, you'll need to configure the CPAN module. If you've never done this,
155it's really simple; just execute the above at your command line, and you're
156on your way. Some people have referred to it as a "pecking chicken" install
157(that is, if you set a chicken over the 'Enter' key and it then keeps
158pecking at the key, it'll get through the installation successfully). For
159our purposes, however, we need to make two small modifications to the
160standard procedure: when the script asks you for any extra arguments for
161Makefile.PL, you need to supply it with the following list (assuming that
162you chose '~/myperl' as your private lib directory):
163</p>
164
165<pre>LIB=~/myperl/lib INSTALLSITEMAN1DIR=~/myperl/man/man1 INSTALLSITEMAN3DIR=~/myperl/man/man3
166</pre>
167
168<p>
169You also need to make sure that the UNINST parameter is turned off; you can
170do this by setting 'UNINST=0' when that question comes up during the
171installation. (This is the default behavior unless you set it, but you
172might as well make sure.)
173</p>
174
175<p>
176If you had already configured the CPAN shell at some point in the past, you
177simply need to modify the configuration. Again, start the shell as above,
178and issue the following commands at the "cpan&gt; " prompt:
179</p>
180
181<p>
182``
183o conf makepl_arg "LIB=~/myperl/lib INSTALLSITEMAN1DIR=~/myperl/man/man1 INSTALLSITEMAN3DIR=~/myperl/man/man3"
184o conf make_install_arg UNINST=0
185o conf commit
186''
187</p>
188
189<p>
190and you're done. From this point forward, using the CPAN shell (or any of
191the other CPAN functions and methods) should work just like usual:
192</p>
193
194<pre># Invoke the shell
195perl -MCPAN -we shell
196
197# Install the Net::FTP module
198perl -MCPAN -we 'install "Net::FTP"'
199
200# Update all outdated modules on this system
201perl -MCPAN -we 'CPAN::Shell-&gt;install(CPAN::Shell-&gt;r)'
202</pre>
203
204
205<h3>Conclusion</h3>
206
207<p>
208Both the CPAN module and its documentation - which are, incidentally,
209included as part of the standard Perl installation - have always been good,
210but they've become even better in the recent years. If you have not taken
211the time to become familiar with them, you should do so, since the end result
212will be a great savings in time and effort. The CPAN itself should also be
213your first stop before you embark on any complex project - I've wasted many
214an hour trying to accomplish some task only to find out later (or part-way
215through the project, if I was lucky) that a module to perform that task
216already exists. Give it a shot - and happy hacking!
217</p>
218
219<p></p>
220<script type="text/javascript">
221digg_url = 'http://linuxgazette.net/139/okopnik.html';
222digg_title = 'Installing Perl Modules as a Non-Root User';
223digg_bodytext = 'If you use Perl for anything more complex than the traditional (and boring)
224generation of "Hello, World", then it\'s also likely that you\'re familiar
225with those wonderful work-saving devices - Perl modules. Furthermore,
226chances are that you\'re also familiar with CPAN, the <a
227href="http://cpan.org/">Comprehensive Perl Archive Network</a>, and the
228easy interface to it that is provided by the CPAN module. That all works
229just great - assuming that you a) run a sensible modern OS like Linux, and
230b) have root access to the machine you\'re using (or have a friendly and
231cooperative sysadmin). But what if those assumptions don\'t hold true? What
232if, for example, you have a shell account on a machine run by some
233mega-corporation that doesn\'t feel like installing the
234Foo::Bar::Zotz::Blagger-0.01 module in their /usr/lib/perl? I, for one,
235can\'t blame them; a system-wide installation could open them up to unknown
236bugs galore. When your interests and theirs conflict, you lose every time -
237since they own the system.';
238digg_topic = 'programming';
239</script>
240<script src="Installing-Perl-Modules-Under-User-Control_files/diggthis.js" type="text/javascript"></script>
241
242
243
244<p class="talkback">
245Talkback: <a href="mailto:[email protected]?subject=Talkback:139/okopnik.html">Discuss this article with The Answer Gang</a>
246</p>
247
248<!-- *** BEGIN author bio *** -->
249<!-- *** BEGIN bio *** -->
250<hr>
251<p>
252<img alt="picture" src="Installing-Perl-Modules-Under-User-Control_files/okopnik.jpg" class="bio" align="left" hspace="10" vspace="10">
253</p>
254
255<p>
256Ben is the Editor-in-Chief for Linux Gazette and a member of The Answer Gang.
257</p>
258
259<p>
260<em>
261Ben was born in Moscow, Russia in 1962. He became interested in electricity
262at the tender age of six, promptly demonstrated it by sticking a fork into
263a socket and starting a fire, and has been falling down technological
264mineshafts ever since. He has been working with computers since the Elder
265Days, when they had to be built by soldering parts onto printed circuit
266boards and programs had to fit into 4k of memory. He would gladly pay good
267money to any psychologist who can cure him of the recurrent nightmares.
268</em>
269</p>
270
271<p>
272<em>
273His subsequent experiences include creating software in nearly a dozen
274languages, network and database maintenance during the approach of a
275hurricane, and writing articles for publications ranging from sailing
276magazines to technological journals. After a seven-year Atlantic/Caribbean
277cruise under sail and passages up and down the East coast of the US, he is
278currently anchored in St. Augustine, Florida. He works as a technical
279instructor for Sun Microsystems and a private Open Source consultant/Web
280developer. His current set of hobbies includes flying, yoga, martial arts,
281motorcycles, writing, and Roman history; his Palm Pilot is crammed full of
282alarms, many of which contain exclamation points.
283</em>
284</p>
285
286<p>
287<em>
288He has been working with Linux since 1997, and credits it with his complete
289loss of interest in waging nuclear warfare on parts of the Pacific Northwest.
290</em>
291</p>
292
293<br clear="all">
294<!-- *** END bio *** -->
295
296<!-- *** END author bio *** -->
297
298<div id="articlefooter">
299
300<p>
301Copyright © 2007, Ben Okopnik. Released under the <a href="http://linuxgazette.net/copying.html">Open Publication License</a>
302unless otherwise noted in the body of the article. Linux Gazette is not
303produced, sponsored, or endorsed by its prior host, SSC, Inc.
304</p>
305
306<p>
307Published in Issue 139 of Linux Gazette, June 2007
308</p>
309
310</div>
311
312<div id="previousnextbottom">
313<a href="http://linuxgazette.net/139/jordan.html">&lt;-- prev</a> | <a href="http://linuxgazette.net/139/peterson.html">next --&gt;</a>
314</div>
315
316</div>
317</div>
318
319<script src="Installing-Perl-Modules-Under-User-Control_files/urchin.js" type="text/javascript">
320</script>
321<script type="text/javascript">
322_uacct = "UA-1204316-1";
323urchinTracker();
324</script>
325
326
327
328
329
330
331
332<img src="Installing-Perl-Modules-Under-User-Control_files/tux_86x95_indexed.png" id="tux" alt="Tux">
333
334
335
336
337</body></html>
Note: See TracBrowser for help on using the repository browser.