Perl linux установка модулей

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

I get this error: Can’t locate Foo.pm in @INC Is there an easier way to install it than downloading, untarring, making, etc?

Be very careful concerning the security: what is needed to ensure that the modules have not been modified must be downloaded in a secure way from a trusted site. See my answer about the use of cpan .

24 Answers 24

usually you start cpan in your shell:

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

$ 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.

Just «ppm» opens the GUI, but followed by commands it stays at the command line. So, «ppm help», «ppm install . «, etc.

Note that ppm uses dashes for the module path separator not the usual double colons. (Perhaps because colons mean drives in dos?) That has got me a few times 😉

@MatthewLock: ppm uses hyphens — because you specify the distribution that you want to install, which is a lot more honest. For instance, if you use cpan to install LWP , LWP::Simple or LWP::UserAgent it will install the distribution libwww-perl for you. The majority of distributions contain a single module with an equivalent name, but there are several exceptions like that

For UNIX and MacOS, need to execute as root or with sudo. Otherwise, there will be a permission error.

It’s great for just getting stuff installed. It provides none of the more complex functionality of CPAN or CPANPLUS, so it’s easy to use, provided you know which module you want to install. If you haven’t already got cpanminus, just type:

It is also possible to install it without using cpan at all. The basic bootstrap procedure is,

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

For more information go to the App::cpanminus page and look at the section on installation.

Using cpan to install App::cpanminus is a bit odd. The normal install instructions involve a bootstrapping procedure of downloading a part of it from cpanmin.us and using that to install the rest. This avoids the configuration of cpan and the creation of a (thereafter) useless .cpan directory.

Читайте также:  Полностью удалить virtualbox linux

On Ubuntu, you can just install cpanminus from terminal. I find cpanm better than cpan because it doesn’t put error logs on screen rather stores them in temporary log files and gives the path in case of errors.

I am getting this error when trying your command: Can’t locate strict.pm in @INC (you may need to install the strict module) (@INC contains: /etc/perl

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.

@Lao Tzu: no, as CPAN is Perl core module and is not available as separate DEB package. I think in most situations is even better to use App::cpanminus , it is such a joy to use it. Philip Potter suggest it in his answer here and you could try this Chas. Owens answer.

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

apt-cache search perl seems only to work for simple cases (probably only if the search term resembles the debian package name). It fails for e.g. apt-cache search perl DDP — the correct answer would be libdata-printer-perl .

A couple of people mentioned the cpan utility, but it’s more than just starting a shell. Just give it the modules that you want to install and let it do it’s work.

If you don’t give it any arguments it starts the CPAN.pm shell. This works on Unix, Mac, and should be just fine on Windows (especially Strawberry Perl).

Читайте также:  Диспетчер устройств linux manjaro

There are several other things that you can do with the cpan tool as well. Here’s a summary of the current features (which might be newer than the one that comes with CPAN.pm and perl):

-a Creates the CPAN.pm autobundle with CPAN::Shell->autobundle. -A module [ module . ] Shows the primary maintainers for the specified modules -C module [ module . ] Show the Changes files for the specified modules -D module [ module . ] Show the module details. This prints one line for each out-of-date module (meaning, modules locally installed but have newer versions on CPAN). Each line has three columns: module name, local version, and CPAN version. -L author [ author . ] List the modules by the specified authors. -h Prints a help message. -O Show the out-of-date modules. -r Recompiles dynamically loaded modules with CPAN::Shell->recompile. -v Print the script version and CPAN.pm version. 

Источник

How to install CPAN modules

Here are some recommended approaches to installing modules from CPAN, as with much of Perl there are several alternatives.

Some basics

Most Perl modules are written in Perl, some use XS (they are written in C) so require a C compiler (it’s easy to get this setup — don’t panic), see your OS of choice below to find out how to get the right compiler. Modules may have dependencies on other modules (almost always on CPAN) and cannot be installed without them (or without a specific version of them). It is worth throughly reading the documentation for the options below. Many modules on CPAN require a somewhat recent version of Perl (version 5.8 or above).

Quick start

Install cpanm to make installing other modules easier (you’ll thank us later). You need to type these commands into a Terminal emulator (Mac OS X, Win32, Linux)

Now install any module you can find.

Tools

To help you install and manage your modules:

local::lib enables you to install modules into a specified directory, without requiring root or administrator access. See the bootstrapping technique for how to get started. You can create a directory per user/project/company and deploy to other servers, by copying the directory (as long as you are on the same operating system and perl version).

cpanm from App::cpanminus is a script to get, unpack, build and install modules from CPAN. It’s dependency free (can bootstrap itself) and requires zero configuration (install instructions). It automates the entire build process for the majority of modules on CPAN and works well with local::lib and perlbrew. Many experienced Perl developers use this as their tool of choice. Related tools: cpan-outdated, pm-uninstall, cpan-listchanges.

perlbrew from App::perlbrew is useful if your system perl is too old to support modern CPAN modules, or if it’s troublesome in other capacities (RedHat/CentOS are included in this list). perlbrew makes the process of installing a Perl in any directory much easier, so that you can work completely independently of any system Perl without needing root or administrator privileges. You can use multiple versions of Perl (maybe as you upgrade) across different projects. The separation from your system Perl makes server maintenance much easier and you more confident about how your project is setup. Currently Windows is not supported.

Читайте также:  Все драйверы ядра linux

cpan from CPAN has been distributed with Perl since 1997 (5.004). It has many more options than cpanm, it is also much more verbose.

cpanp from CPANPLUS had been distributed with Perl since 5.10 (2007) until 5.20 (2014). This offers even more options than cpanm or cpan and can be installed just like cpanminus.

Perl on Windows (Win32 and Win64)

Strawberry Perl is an open source binary distribution of Perl for the Windows operating system. It includes a compiler and pre-installed modules that offer the ability to install XS CPAN modules directly from CPAN. It also comes with lots of modules pre-installed, including cpanm.

ActiveState provide a binary distribution of Perl (for many platforms), as well as their own perl package manager (ppm). Some modules are not available as ppm’s or have reported errors on the ppm build system, this does not mean they do not work. You can use the cpan script to build modules from CPAN against ActiveState Perl.

Perl on Mac OSX

OSX comes with Perl pre-installed. in order to build and install your own modules you will need to install the «Command Line Tools for XCode» or «XCode» package — details on our ports page. Once you have done this you can use all of the tools mentioned above.

Perl on other Unix like OSs

Install ‘make’ through your package manager. You can then use all of the tools mentioned above.

Other tools

CPAN::Mini can provide you with a minimal mirror of CPAN (just the latest version of all modules). This makes working offline easy.

CPAN::Mini::Inject allows you to add your own modules to your local CPAN::Mini mirror of CPAN. So you can install and deploy your own modules through the same tools you use for CPAN modules.

Which modules should I use?

Task::Kensho lists suggested best practice modules for a wide range of tasks. https://metacpan.org/ will let you search CPAN. You could also get involved with the community, ask on a mailing list or find your nearest Perl Mongers group.

Yours Eclectically, The Self-Appointed Master Librarians (OOK!) of the CPAN.
© 1995-2010 Jarkko Hietaniemi. © 2011-2023 Perl.org. All rights reserved. Disclaimer.

Master mirror hosted by and

Источник

Оцените статью
Adblock
detector