What's the easiest way to install a missing Perl module?

前端 未结 24 2634
情深已故
情深已故 2020-11-21 05:28

I get this error:

Can\'t locate Foo.pm in @INC

Is there an easier way to install it than downloading, untarring, making, etc?

相关标签:
24条回答
  • 2020-11-21 05:48

    Sometimes you can use the yum search foo to search the relative perl module, then use yum install xxx to install.

    0 讨论(0)
  • 2020-11-21 05:49

    Easiest way for me is this:

    PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install DateTime::TimeZone'
    

    a) automatic recursive dependency detection/resolving/installing

    b) it's a shell onliner, good for setup-scripts

    0 讨论(0)
  • 2020-11-21 05:50

    On Unix:

    usually you start cpan in your shell:

    $ cpan

    and type

    install Chocolate::Belgian

    or in short form:

    cpan Chocolate::Belgian

    On Windows:

    If you're using ActivePerl on Windows, the PPM (Perl Package Manager) has much of the same functionality as CPAN.pm.

    Example:

    $ ppm
    ppm> search net-smtp
    ppm> install Net-SMTP-Multipart

    see How do I install Perl modules? in the CPAN FAQ

    Many distributions ship a lot of perl modules as packages.

    • Debian/Ubuntu: apt-cache search 'perl$'
    • Arch Linux: pacman -Ss '^perl-'
    • Gentoo: category dev-perl

    You should always prefer them as you benefit from automatic (security) updates and the ease of removal. This can be pretty tricky with the cpan tool itself.

    For Gentoo there's a nice tool called g-cpan which builds/installs the module from CPAN and creates a Gentoo package (ebuild) for you.

    0 讨论(0)
  • 2020-11-21 05:50

    I note some folks suggesting one run cpan under sudo. That used to be necessary to install into the system directory, but modern versions of the CPAN shell allow you to configure it to use sudo just for installing. This is much safer, since it means that tests don't run as root.

    If you have an old CPAN shell, simply install the new cpan ("install CPAN") and when you reload the shell, it should prompt you to configure these new directives.

    Nowadays, when I'm on a system with an old CPAN, the first thing I do is update the shell and set it up to do this so I can do most of my cpan work as a normal user.

    Also, I'd strongly suggest that Windows users investigate strawberry Perl. This is a version of Perl that comes packaged with a pre-configured CPAN shell as well as a compiler. It also includes some hard-to-compile Perl modules with their external C library dependencies, notably XML::Parser. This means that you can do the same thing as every other Perl user when it comes to installing modules, and things tend to "just work" a lot more often.

    0 讨论(0)
  • 2020-11-21 05:54

    If you're on Ubuntu and you want to install the pre-packaged perl module (for example, geo::ipfree) try this:

        $ apt-cache search perl geo::ipfree
        libgeo-ipfree-perl - A look up country of ip address Perl module
    
        $ sudo apt-get install libgeo-ipfree-perl
    
    0 讨论(0)
  • 2020-11-21 05:54

    Already answered and accepted answer - but anyway:

    IMHO the easiest way installing CPAN modules (on unix like systems, and have no idea about the wondows) is:

    curl -L http://cpanmin.us | perl - --sudo App::cpanminus
    

    The above is installing the "zero configuration CPAN modules installer" called cpanm. (Can take several minutes to install - don't break the process)

    and after - simply:

    cpanm Foo
    cpanm Module::One
    cpanm Another::Module
    
    0 讨论(0)
提交回复
热议问题