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%">
|
---|
48 | The Free International Online Linux Monthly
|
---|
49 | </td>
|
---|
50 | <td style="font-size: 10px; font-weight: bold" align="center" width="20%">
|
---|
51 | ISSN: 1934-371X
|
---|
52 | </td>
|
---|
53 | <td style="font-size: 10px; font-weight: bold" align="right" width="40%">
|
---|
54 | Main 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> >
|
---|
63 | <a href="http://linuxgazette.net/139/index.html">June 2007 (#139)</a> >
|
---|
64 | Article
|
---|
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"><-- prev</a> | <a href="http://linuxgazette.net/139/peterson.html">next --></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>
|
---|
81 | If you use Perl for anything more complex than the traditional (and boring)
|
---|
82 | generation of "Hello, World", then it's also likely that you're familiar
|
---|
83 | with those wonderful work-saving devices - Perl modules. Furthermore,
|
---|
84 | chances are that you're also familiar with CPAN, the <a href="http://cpan.org/">Comprehensive Perl Archive Network</a>, and the
|
---|
85 | easy interface to it that is provided by the CPAN module. That all works
|
---|
86 | just great - assuming that you a) run a sensible modern OS like Linux, and
|
---|
87 | b) have root access to the machine you're using (or have a friendly and
|
---|
88 | cooperative sysadmin). But what if those assumptions don't hold true? What
|
---|
89 | if, for example, you have a shell account on a machine run by some
|
---|
90 | mega-corporation that doesn't feel like installing the
|
---|
91 | Foo::Bar::Zotz::Blagger-0.01 module in their /usr/lib/perl? I, for one,
|
---|
92 | can't blame them; a system-wide installation could open them up to unknown
|
---|
93 | bugs galore. When your interests and theirs conflict, you lose every time -
|
---|
94 | since they own the system.
|
---|
95 | </p>
|
---|
96 |
|
---|
97 | <p>
|
---|
98 | So, what can we do if we really, really need that module but can't get it
|
---|
99 | installed on a system-wide basis? The answer is to install it elsewhere -
|
---|
100 | in some directory where you have write permissions.
|
---|
101 | </p>
|
---|
102 |
|
---|
103 | <h3>Configuring the Environment</h3>
|
---|
104 |
|
---|
105 | <p>
|
---|
106 | Clearly, if you're not root, you're not going to be able to save the files
|
---|
107 | to their default locations under '/usr/' - which is where they would
|
---|
108 | normally go. Therefore, we need to tell Perl where to find the modules
|
---|
109 | that we'll install. Fortunately, this is the easy part: just decide on the
|
---|
110 | location where you'll install the modules, create that directory if it
|
---|
111 | doesn't already exist, append '/lib' to its name, and set the PERL5LIB
|
---|
112 | variable 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" ]
|
---|
117 | then
|
---|
118 | # If PERL5LIB wasn't previously defined, set it...
|
---|
119 | PERL5LIB=~/myperl/lib
|
---|
120 | else
|
---|
121 | # ...otherwise, extend it.
|
---|
122 | PERL5LIB=$PERL5LIB:~/myperl/lib
|
---|
123 | fi
|
---|
124 |
|
---|
125 | MANPATH=$MANPATH:~/myperl/man
|
---|
126 |
|
---|
127 | export PERL5LIB MANPATH
|
---|
128 | </pre>
|
---|
129 |
|
---|
130 | <p>
|
---|
131 | Now, create the three necessary directories:
|
---|
132 | </p>
|
---|
133 |
|
---|
134 | <pre>mkdir -p ~/myperl/lib
|
---|
135 | mkdir -p ~/myperl/man/man{1,3}
|
---|
136 | </pre>
|
---|
137 |
|
---|
138 | <p>
|
---|
139 | After you've logged out and back in, Perl will treat that location as a
|
---|
140 | part of @INC (the list of directories to search for libraries and modules.)
|
---|
141 | If you want to confirm that it's actually happened, just execute the
|
---|
142 | following 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>
|
---|
154 | First, you'll need to configure the CPAN module. If you've never done this,
|
---|
155 | it's really simple; just execute the above at your command line, and you're
|
---|
156 | on 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
|
---|
158 | pecking at the key, it'll get through the installation successfully). For
|
---|
159 | our purposes, however, we need to make two small modifications to the
|
---|
160 | standard procedure: when the script asks you for any extra arguments for
|
---|
161 | Makefile.PL, you need to supply it with the following list (assuming that
|
---|
162 | you 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>
|
---|
169 | You also need to make sure that the UNINST parameter is turned off; you can
|
---|
170 | do this by setting 'UNINST=0' when that question comes up during the
|
---|
171 | installation. (This is the default behavior unless you set it, but you
|
---|
172 | might as well make sure.)
|
---|
173 | </p>
|
---|
174 |
|
---|
175 | <p>
|
---|
176 | If you had already configured the CPAN shell at some point in the past, you
|
---|
177 | simply need to modify the configuration. Again, start the shell as above,
|
---|
178 | and issue the following commands at the "cpan> " prompt:
|
---|
179 | </p>
|
---|
180 |
|
---|
181 | <p>
|
---|
182 | ``
|
---|
183 | o conf makepl_arg "LIB=~/myperl/lib INSTALLSITEMAN1DIR=~/myperl/man/man1 INSTALLSITEMAN3DIR=~/myperl/man/man3"
|
---|
184 | o conf make_install_arg UNINST=0
|
---|
185 | o conf commit
|
---|
186 | ''
|
---|
187 | </p>
|
---|
188 |
|
---|
189 | <p>
|
---|
190 | and you're done. From this point forward, using the CPAN shell (or any of
|
---|
191 | the other CPAN functions and methods) should work just like usual:
|
---|
192 | </p>
|
---|
193 |
|
---|
194 | <pre># Invoke the shell
|
---|
195 | perl -MCPAN -we shell
|
---|
196 |
|
---|
197 | # Install the Net::FTP module
|
---|
198 | perl -MCPAN -we 'install "Net::FTP"'
|
---|
199 |
|
---|
200 | # Update all outdated modules on this system
|
---|
201 | perl -MCPAN -we 'CPAN::Shell->install(CPAN::Shell->r)'
|
---|
202 | </pre>
|
---|
203 |
|
---|
204 |
|
---|
205 | <h3>Conclusion</h3>
|
---|
206 |
|
---|
207 | <p>
|
---|
208 | Both the CPAN module and its documentation - which are, incidentally,
|
---|
209 | included as part of the standard Perl installation - have always been good,
|
---|
210 | but they've become even better in the recent years. If you have not taken
|
---|
211 | the time to become familiar with them, you should do so, since the end result
|
---|
212 | will be a great savings in time and effort. The CPAN itself should also be
|
---|
213 | your first stop before you embark on any complex project - I've wasted many
|
---|
214 | an hour trying to accomplish some task only to find out later (or part-way
|
---|
215 | through the project, if I was lucky) that a module to perform that task
|
---|
216 | already exists. Give it a shot - and happy hacking!
|
---|
217 | </p>
|
---|
218 |
|
---|
219 | <p></p>
|
---|
220 | <script type="text/javascript">
|
---|
221 | digg_url = 'http://linuxgazette.net/139/okopnik.html';
|
---|
222 | digg_title = 'Installing Perl Modules as a Non-Root User';
|
---|
223 | digg_bodytext = 'If you use Perl for anything more complex than the traditional (and boring)
|
---|
224 | generation of "Hello, World", then it\'s also likely that you\'re familiar
|
---|
225 | with those wonderful work-saving devices - Perl modules. Furthermore,
|
---|
226 | chances are that you\'re also familiar with CPAN, the <a
|
---|
227 | href="http://cpan.org/">Comprehensive Perl Archive Network</a>, and the
|
---|
228 | easy interface to it that is provided by the CPAN module. That all works
|
---|
229 | just great - assuming that you a) run a sensible modern OS like Linux, and
|
---|
230 | b) have root access to the machine you\'re using (or have a friendly and
|
---|
231 | cooperative sysadmin). But what if those assumptions don\'t hold true? What
|
---|
232 | if, for example, you have a shell account on a machine run by some
|
---|
233 | mega-corporation that doesn\'t feel like installing the
|
---|
234 | Foo::Bar::Zotz::Blagger-0.01 module in their /usr/lib/perl? I, for one,
|
---|
235 | can\'t blame them; a system-wide installation could open them up to unknown
|
---|
236 | bugs galore. When your interests and theirs conflict, you lose every time -
|
---|
237 | since they own the system.';
|
---|
238 | digg_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">
|
---|
245 | Talkback: <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>
|
---|
256 | Ben is the Editor-in-Chief for Linux Gazette and a member of The Answer Gang.
|
---|
257 | </p>
|
---|
258 |
|
---|
259 | <p>
|
---|
260 | <em>
|
---|
261 | Ben was born in Moscow, Russia in 1962. He became interested in electricity
|
---|
262 | at the tender age of six, promptly demonstrated it by sticking a fork into
|
---|
263 | a socket and starting a fire, and has been falling down technological
|
---|
264 | mineshafts ever since. He has been working with computers since the Elder
|
---|
265 | Days, when they had to be built by soldering parts onto printed circuit
|
---|
266 | boards and programs had to fit into 4k of memory. He would gladly pay good
|
---|
267 | money to any psychologist who can cure him of the recurrent nightmares.
|
---|
268 | </em>
|
---|
269 | </p>
|
---|
270 |
|
---|
271 | <p>
|
---|
272 | <em>
|
---|
273 | His subsequent experiences include creating software in nearly a dozen
|
---|
274 | languages, network and database maintenance during the approach of a
|
---|
275 | hurricane, and writing articles for publications ranging from sailing
|
---|
276 | magazines to technological journals. After a seven-year Atlantic/Caribbean
|
---|
277 | cruise under sail and passages up and down the East coast of the US, he is
|
---|
278 | currently anchored in St. Augustine, Florida. He works as a technical
|
---|
279 | instructor for Sun Microsystems and a private Open Source consultant/Web
|
---|
280 | developer. His current set of hobbies includes flying, yoga, martial arts,
|
---|
281 | motorcycles, writing, and Roman history; his Palm Pilot is crammed full of
|
---|
282 | alarms, many of which contain exclamation points.
|
---|
283 | </em>
|
---|
284 | </p>
|
---|
285 |
|
---|
286 | <p>
|
---|
287 | <em>
|
---|
288 | He has been working with Linux since 1997, and credits it with his complete
|
---|
289 | loss 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>
|
---|
301 | Copyright © 2007, Ben Okopnik. Released under the <a href="http://linuxgazette.net/copying.html">Open Publication License</a>
|
---|
302 | unless otherwise noted in the body of the article. Linux Gazette is not
|
---|
303 | produced, sponsored, or endorsed by its prior host, SSC, Inc.
|
---|
304 | </p>
|
---|
305 |
|
---|
306 | <p>
|
---|
307 | Published 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"><-- prev</a> | <a href="http://linuxgazette.net/139/peterson.html">next --></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";
|
---|
323 | urchinTracker();
|
---|
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> |
---|