Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

[Solved]: How to install modules for local perl without changing anything on system perl?

by Perl300 (Friar)
on Dec 23, 2015 at 20:43 UTC ( #1151083=perlquestion: print w/replies, xml ) Need Help??

Perl300 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a question related to system perl and local perl (that we are planning to use for our application)

The system perl is at /usr/bin/perl and the local that we have installed for our application is at /opt/apps/perl/perl5220/bin/perl (both on the same host/linux box)

Now if I want to install modules from CPAN for the app perl (the one at /opt/apps/perl/perl5220/bin/perl) without changing anything on the system perl (the one at /usr/bin/perl) then will it be ok to do: /opt/apps/perl/perl5220/bin/cpan -i Template?

I didn't want to try it and see what happens if it has a chance to mess things up.

Per Llama book, "by default, the CPAN tools want to install new modules into the same directories where perl is." So I think if I use cpan for the local perl then it should install modules for itself rather than system perl, but not 100% sure about it.

  • Comment on [Solved]: How to install modules for local perl without changing anything on system perl?
  • Select or Download Code

Replies are listed 'Best First'.
Re: How to install modules for local perl without changing anything on system perl?
by graff (Chancellor) on Dec 23, 2015 at 23:48 UTC
    So I think if I use cpan for the local perl then it should install modules for itself rather than system perl, but not 100% sure about it.

    You're right, and you can be sure about it. When you run /usr/bin/perl -V you'll see the directories that will be affected by installing modules via /usr/bin/perl -MCPAN -e shell

    Likewise, when you run /opt/apps/perl/perl5220/bin/perl -V you'll see the directories that are affected when you run CPAN via this instance of perl.

Re: How to install modules for local perl without changing anything on system perl?
by beech (Parson) on Dec 23, 2015 at 23:44 UTC
      But will that not mess up any updates you (later) need to make to the system Perl?

      Or worse, the system Perl will start using the local perl modules which may be incompatible between the versions of local and system Perl?

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

        But will that not mess up any updates you (later) need to make to the system Perl? Or worse, the system Perl will start using the local perl modules which may be incompatible between the versions of local and system Perl?

        Thats a good question :)

        I don't think you can mess up the system perl

        any installs would be done as root and root ought to have a different %ENV :)

        but if root doesn't, then the system installs just go in a different directory

        now that might cause something tricky to happen, but if you're using system tools to update the system perl, then those tools should remove PERL_ vars from the equation

        But yeah, the possibility exists, maybe :D

        However , the system perl shouldn't start using incompatible versions, as using INSTALL_BASE ought to include both version number and archname -- it doesn't do this on win32 (for some unknown reason), but it should do it on other operating systems

Re: How to install modules for local perl without changing anything on system perl?
by jcb (Parson) on Dec 23, 2015 at 23:38 UTC

    A method for this that I've used in the past is to have an account other than root for building software (then only run the install step as root). If you have (or can make) such an account, simply chown -R not-root /opt/apps/perl/perl5220, run the CPAN tools as not-root, and see if it works.

    Since you are not running the install as root, it will fail if an attempt is made to write to the system perl, and you can be confident that, at worst, only the app perl that you were trying to change can be messed up.

    Afterwards, chown -R root /opt/apps/perl/perl5220 will put things back the way they were.

    Unless, of course, /opt/app/perl/perl5220 is already owned by an account other than root, in which case you can avoid the chown dance and can simply run the CPAN tools under that account, where they will not be allowed to touch the system perl.

    A final caveat: This assumes that the system perl is owned by root. If the system perl is not owned by root, then you will need to figure out who changed that and why.

Re: [Solved]: How to install modules for local perl without changing anything on system perl?
by flexvault (Monsignor) on Dec 24, 2015 at 19:10 UTC

    Hello Perl300,

    Since you are running *nix, I'll comment on what I do.

    Typically, I have at least 3 or 4 Perls on any *nix boxes that I am the admin for. I use the '/usr/local/bin/' to have a symbolic link to the 'non-system' Perl, which I usually install in '/usr/opt/'. Today, I never touch the system Perl and all updates come from the OS update mechanism.

    So let's do an example:

    • I download Perl ( 5.22.1 ) to '/home/Perl/Perl5.22.1/'.
    • I follow the directions for a quick install (usually works perfectly) and configure to install with:
          config_args='-des -Dprefix=/usr/opt/perl5.22.1 -Dusethreads . . .'
    • After all makes work, I issue:
          ln -s /usr/opt/perl5.22.1/bin/perl5.22.1   myperl # myperl is unique name for each Perl
          Test: myperl -V

    If you want to use 'cpan' on the command line, then do a link to the specific one ( ie, mycpan ). I find it easier to
        myperl -MCPAN -e 'install "..."'

    Note 1: I've found problems with Perls that are not owned by root. YMMV.

    Note 2: I usually have 2 Perls for each version, 1 with threads and 1 without. On the *nixes I use, threads has a lot of overhead.

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

Re: [Solved]: How to install modules for local perl without changing anything on system perl?
by Perl300 (Friar) on Dec 24, 2015 at 18:23 UTC
    It worked when I tried /opt/apps/perl/perl5220/bin/cpan -i App::cpanminus and installed the module under /opt/apps/perl/perl5220/

    Somehow it didn't work when I tried /opt/apps/perl/perl5220/bin/perl -MCPAN -e shell and then cpan[1]> install cpanm as mentioned in the documentation of cpanm. Gave "Warning: Cannot install cpanm, don't know what it is." But I am good to go now so updated title of post as resolved.

    Thank you for all your inputs.

      as mentioned in the documentation of cpanm
      Where did you find it? See INSTALLATION.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: How to install modules for local perl without changing anything on system perl?
by Perl300 (Friar) on Dec 24, 2015 at 16:46 UTC
    Thank you all for your inputs! jcb, I forgot to mention that system perl is owned by root and /opt/apps/perl/perl5220 is owned by a different account (created for the application). I'll run CPAN under /opt/apps/perl/perl5220 as the application user (sudo to application user/account) and will post outcome here to let everyone know.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2022-05-18 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?