1. Perl
  2. Module
  3. here

CPAN - Module installation from CPAN

You can use the CPAN module to install the module from CPAN. CPAN is a collection of modules that you can use for free. The CPAN module is supposed to be used from the command line, and you can use various functions from the cpan command.

You can install the module by running the cpan command on the command line.

# Install module
cpan module name

There is also a feature called the cpan shell that allows you to install interactively. If you don't specify any arguments to the cpan command, the cpan shell will start. (You may get a YAML error in ActivePerl, but the solution is here.)

# cpan shell launch
cpan

# Module installation (cpan shell)
install module name

Use the exit command to exit the cpan shell.

# Exit cpan shell (cpan shell)
exit

If you're new to running cpan, you'll need to configure cpan the first time you start it. You may be surprised to hear about a lot of settings, but let's press Enter to proceed with the default settings. You can also change the settings later.

Recent cpan sets everything automatically, but if it's a bit older, there are some items that need to be set manually.

This item determines from which mirror site to install. CPAN has mirror sites around the world, so choose the closest mirror site.

# CPAN Mirror Selection

First, pick a nearby continent and country (you can pick several of
each, separated by spaces, or none if you just want to keep your
existing selections). Then, you will be presented with a list of URLs
of CPAN mirrors in the countries you selected, along with previously
selected URLs. Select some of those URLs, or just keep the old list.
Finally, you will be prompted for any extra URLs - file :, ftp :, or
http: - that host a CPAN mirror.

(1) Africa
(2) Asia <- -- -- - Select this
(3) Australasia
(4) Central America
(5) Europe
(6) North America
(7) South America
Select your continent (or several nearby continents) [] 2

(1) China
(2) Hong Kong
(3) Indonesia
(4) Israel
(5) Japan <- -- -- -- Select this
(6) Saudi-Arabia
(7) Singapore
(8) South Korea
(9) Taiwan
(10) Thailand
Select your country (or several nearby countries) [] 5

(1) ftp://ftp.dti.ad.jp/pub/lang/CPAN/
(2) ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
(3) ftp://ftp.lab.kdd.co.jp/lang/perl/CPAN/
(4) ftp://ftp.meisei-u.ac.jp/pub/CPAN/
(5) ftp://ftp.ring.gr.jp/pub/lang/perl/CPAN/ <- --- Any one is fine, but 5 is selected this time.
(6) ftp://mirror.nucba.ac.jp/mirror/Perl/

Select as many URLs as you like [] 5

If you want to reconfigure cpan, use the "o conf init" command in the cpan shell.

# Reconfigure (cpan shell)
o conf init

Change cpan settings

To change the cpan settings, start the cpan shell and then use the "o conf" command. Type "o conf" to see all settings.

# See all settings (cpan shell)
o conf

A list of settings is displayed as shown below.

# List of cpan settings
    applypatch []
    auto_commit [0]
    build_cache [100]
    build_dir [/root/.cpan/build]
    ..
    . (omit)
    ..
    username undef
    wait_list undef
    wget [/ usr/bin/wget]
    yaml_load_code [0]
    yaml_module [YAML]

The setting items can be changed.

# Change settings (cpan shell)
o conf build_cache 200

The items you set are valid only while the cpan shell is running. You need to do a commit to save your settings.

# Save settings (cpan shell)
o conf commit

If the setting item is a list, you can also use the unshift, push, pop, and shift commands.

# Add to the beginning
o conf urllist unshift http://cpan.dev.local/CPAN

# Add to the end
o conf urllist push http://cpan.dev.local/CPAN

# Delete the end
o conf urllist pop

# Delete the beginning
o conf urllist shift

If the CPAN module installation fails

Installation of CPAN modules often fails. It's difficult to pinpoint the cause of this, but here are some possible situations.

1. The CPAN mirror is down

->Add an available CPAN mirror to the beginning of the urllist

2. The module is huge, so there is not enough space to reserve for building the module.

->Try increasing the value of build_cache to about 100M

3. The module only assumes a Unix environment. Alternatively, it includes tests that fail on Windows.

->If you think it's just because the test is failing, you can try a forced installation, but it's a good idea to report it.

4. XS is included but cannot be installed because there is no gcc compiler.

->If the gcc package is Linux, install gcc with yum or apt-get, if it is Windows, MinGW is packed if it is 5.10.1 or later ActivePerl, and there is a gcc environment.

5. You are in an environment where you can only use the Internet with a proxy connection.

->In the case of a corporate network, you may not be able to connect to the Internet via proxy server. In that case, you can set a proxy. You need to find out the domain name and port number of the proxy. Twice

# Proxy settings
o conf http_proxy ftp_proxy = http: //proxy.you.com: 8000/o conf ftp_proxy http_proxy = http: //proxy.you.com: 8000/</pre>

Also, even though only HTTP connection is allowed to the outside, if the urllist contains the ftp URL, the connection will fail. Include one of the URLs below at the beginning of your urllist.

<pre>
# When installing with HTTP connection
http://ftp.nara.wide.ad.jp/pub/CPAN/
http://ftp.jaist.ac.jp/pub/CPAN/
http://ftp.riken.jp/lang/CPAN/
http://ftp.yz.yamagata-u.ac.jp/pub/lang/cpan/

6. The module depends on another (non-Perl) library

->For example XML::LibXML depends on a library called libxml2. If that library is not installed, CPAN installation will fail. You need to install the package containing libxml2 with commands such as yum and apt-get.

FAQ about CPAN modules

Q. Can I automatically answer yes when installing dependent modules?

A. Yes. I can do it. prerequisites_polic from cpan shellSet y to follow.

# Automatically install dependent modules
o conf prerequisites_policy follow
o conf commit

If ask is specified, it will be confirmed whether to install. If ignore is specified, the dependent modules will not be installed.

Q. Is there a site that has a list of CPAN mirror URLs?

A. It will be the following site.

CPAN SITES

Q. Can I use cpan on Windows?

A. Yes you can. Previously, using cpan on Windows required a command called nmake instead of the make command. Currently, if ActivePerl is 5.10.1 or later, a development tool called MinGW is packed. It includes an alternative to the make command and a C compiler, so cpan is now working well on Windows.

Q. Can I see the module installation history?

A. The installation history is recorded in a document called perllocal.

# View installation history
perldoc perllocal

The installation history is displayed as shown below.

       Tue Jun 8 20:15:01 2010:"Module" Mail::Address::MobileJp

       -"Installed into: /usr/lib/perl5/site_perl/5.8.8"

       ・ "LINKTYPE: dynamic"

       ・ "VERSION: 0.09"

       ・ "EXE_FILES:"

       Tue Jun 8 20:24:46 2010:"Module" Business::CreditCard

       -"Installed into: /usr/lib/perl5/site_perl/5.8.8"

       ・ "LINKTYPE: dynamic"

       ・ "VERSION: 0.31"

       ・ "EXE_FILES:"

Q. I just want the name of the list of installed modules.

A. Use the following script. ExtUtils::Installed is available.

# List of installed module names
use ExtUtils::Installed;
print join "\n", ExtUtils::Installed->new->modules;

Q. How can I install the modules in a new environment?

A. Feed cpan the file created above. It's a good idea to combine it with xargs.

# Install all CPAN modules together
cat installed.txt | xargs cpan

Q. I would like to know the distribution name of the installed module.

A. The distribution name is something like "ADAMK/DBD-SQLite-1.29.tar.gz"

It has a structure like "author name/module name-version.tar.gz".

You can find this out on "cpan -a".

# View installed modules and distribution names
cpan -a

But this has a lot of module duplication, so to get rid of the duplication: It will take some time.

cpan -a | awk'{print $4;}' | sort -u

Q. I don't have root privileges, but I want to use cpan. Can it be installed in the user area?

A. It's a good idea to use a tool called cpanm instead of cpan.

Q. Is there a way to ensure that the CPAN module is deployed in another environment? Certainty is required in practice.

A. It is a good idea to write the required modules in a file called cpanfile and install using cpanm.

Related Informatrion