简体   繁体   中英

How to change the perl cpan repository location

When I am using cpan to install module, there is a download source which is very unstable and slow, and I might want to install that module on many machines?

Is that possible to change the perl module repository to other address, or copy the repos to local disk.

Or, can we save the local module files to local when we use cpan. It seems cpan would delete it after installation.

Is that possible to change the perl module repository to other address

You can reconfigure cpan (and change your mirror) by running a CPAN shell:

perl -MCPAN -eshell

and then typing:

o conf init

or copy the repos to local disk.

CPAN Mini is the usual tool for this.

cpanm (called "cpanminus") is a very popular alternative installer for Perl modules. With cpanm, you can use the --mirror option to point it at a different repository URL. I believe cpanm can also create a local cache of all the modules you install, for quicker access later.

Pinto is another option for creating a CPAN-like repository on local disk. However, it aspires to be a more "complete" solution for managing Perl modules. So it might be more than you are looking for.

You could set up a CPAN::Mini repository. You need to install CPAN::Mini , and provide a config file .minicpanrc . Mine is quite short:

# contents of .minicpanrc in home directory
local: /home/ebaudrez/mirrors/minicpan
remote: http://cpan.cu.be/

Obviously, you'll need to tune that to your installation. You can find a list of CPAN mirrors here . Then you have to create the local mirror by calling

minicpan

Beware: the first time, this will take quite some time. Expect a couple of gigabytes of storage to be consumed. Subsequent calls will be much faster. It found it made no sense to call it more than once daily. Also note that only the last release of a distribution is kept, and old or removed distributions will be removed from your local repository.

And then finally, you can tell cpanm to use your mirror preferentially, and to fail back to real CPAN only when the particular distribution or version you're after is not available in your local mirror:

PERL_CPANM_OPT="--mirror $HOME/mirrors/minicpan --mirror http://search.cpan.org/CPAN"

It's possible to configure CPAN or CPANPLUS to use your mirror, too, but I found it slightly less convenient to do so, and prefer cpanminus anyway.

Now you can install any distribution/version you want using cpanm , eg,

cpanm Dist::Zilla; # enjoy as the dependencies fly by ;-)

or, say, PDL version 2.006 (note: latest release at the time of writing is 2.007 ;-))

cpanm PDL@2.006 # note: that is new syntax since cpanminus 1.6

Stuff that is in your local mirror will be used if available. Global CPAN will be used for fallback.

I'm surprised nobody has added how to just edit the default CPAN configuration. Using the CPAN shell to do this is just crazy, in comparison to editing a small text file.

Here's how to do it:

  1. Choose some CPAN mirrors from the Official CPAN mirror list .
  2. Locate your CPAN configuration, usually in:
    $HOME/.cpan/CPAN/MyConfig.pm
    (If not there, then search for the file: MyConfig.pm .)
  3. Edit the list-item called urllist , and add your URLs to it.
'urllist' => [
    q[http://httpupdate3.cpanel.net/CPAN/], 
    q[http://mirrors.servercentral.net/CPAN/], 
    q[ftp://cpan.cse.msu.edu/]
],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM