Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How to change @INC permanently?

by spiritway (Vicar)
on Aug 24, 2005 at 04:09 UTC ( #486084=perlquestion: print w/ replies, xml ) Need Help??
spiritway has asked for the wisdom of the Perl Monks concerning the following question:

Beloved brethren and sistren - I am getting an error when I try to use a module. It is not in the @INC array. I know where the module lives, but I don't know how to make Perl add that directory to @INC permanently. I understand from SuperSearch that I can use lib to add the directory at compile time, but I would like to simply add the directory once and for all. So the question is:

Where does the information for @INC live on a Linux system? I would be grateful for any help. Thank you.

UPDATE: Thank you for your help. I just spent seven hours on this issue, only to find that I had typed an incorrect character, and the problem had nothing whatsoever to do with @INC.

The good news is: 1) I learned a whole lot of stuff I normally wouldn't know; and 2) I will probably never make this particular mistake again.

Comment on How to change @INC permanently?
Select or Download Code
Re: How to change @INC permanently?
by merlyn (Sage) on Aug 24, 2005 at 04:11 UTC

      Thank you kindly, Merlin.

        A somewhat simpler approach for a "semi-permanent" solution may be to set the PERL5LIB environment variable to the directories you want to always make available. See perlrun.

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: How to change @INC permanently?
by techra (Pilgrim) on Aug 24, 2005 at 13:57 UTC

    And yet another solution is to make use of the myriad paths that Perl scans for modules in. </p

    Notice that Perl scans /etc/perl by default. Most distributions of Linux don't put anything there, so why not just softlink the directory structure your modules live under into /etc/perl?

      Notice that Perl scans /etc/perl by default.

      doesn't seem to be the case on my machines. if it were, that might be a nice trick to use.

      on debian perl 5.8.7

      $ perl -e 'print join "\n",@INC' /etc/perl /usr/local/lib/perl/5.8.7 /usr/local/share/perl/5.8.7 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4
      on RH perl 5.8.0
      $ perl -e 'print join "\n",@INC' /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
      on solaris perl 5.00503
      > perl -e 'print join "\n",@INC' /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005
Re: How to change @INC permanently?
by AJRod (Scribe) on Aug 24, 2005 at 15:46 UTC
    If you have theoretically the power to change @INC permanently on your system, wouldn't you also have the power to more simply reinstall the module in a place defined by @INC?

      As root, yes. However, I make an effort to avoid being root whenever possible, because bad things can (and do) happen when I'm root. I'm way too familiar with reinstalling Linux, because of playing around as root...

        It's a good practice to avoid being root if you can. I just use sudo and get the same results with a safety net. You can either run the CPAN shell using sudo to install things or use sudo on the final install step for a manual install.
        perl Makefile.PL make make test sudo make install
        That will put the new modules in the places perl expects and make them available for everyone and you don't need to log in as root.
Re: How to change @INC permanently?
by z3d (Scribe) on Aug 24, 2005 at 17:00 UTC
    You'll need to rebuild perl (and libperl if it was built separately). Here's an example snippet of the patch used by a distro i work with:
    --- perl.c.orig 2005-07-26 13:04:54.000000000 -0400 +++ perl.c 2005-07-26 13:05:05.000000000 -0400 @@ -4397,9 +4397,9 @@ S_init_perllib(pTHX) incpush(APPLLIB_EXP, TRUE, TRUE, TRUE); #endif -#ifdef ARCHLIB_EXP - incpush(ARCHLIB_EXP, FALSE, FALSE, TRUE); -#endif + /* for configuration where /usr is mounted ro (CPAN::Config, Net: +:Config) */ + incpush("/etc/perl", FALSE, FALSE, TRUE); + #ifdef MACOS_TRADITIONAL { Stat_t tmpstatbuf;



    "I have never written bad code. There are merely unanticipated features."
Re: How to change @INC permanently?
by johnnywang (Priest) on Aug 24, 2005 at 23:07 UTC
Re: How to change @INC permanently?
by Anonymous Monk on Mar 26, 2007 at 14:08 UTC
    I see that there are a lot of people wanting to know how to add directories to their @INC permanently. I accomplished this by adding the following line to the end of my startup.pl file: push(@INC, "Put path to directory here"); Restart apache and you should be good to go! Hope this helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://486084]
Approved by sk
Front-paged by sk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-12-28 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls