当前位置: 首页 > 工具软件 > CPAN > 使用案例 >

perl 安装本地CPAN

司信厚
2023-12-01

Install your own Perl with your own CPAN


Yes I know, it exists a featured tool called perlbrew but can happen that

·                    your home dir has not enough space

·                    you don't have an internet connection

·                    you want to tweak your perl distro

·                    you just want to DIY


In this article I talk about how to build your own Perl, and use your ownCPAN mirror. 


Suppose your login is "user" on host "darkstar" that is a Linux box with Internet connection.
You can start there to build your Perl and mirror your own CPAN.
After that you can hop to hosts in your Intranet, I mean with no connection outside your Firewall.

You can draw your topology  (机器拓扑图,假设有3台机器,其中只有 DEV 可以上网。)

                     DEV --> TEST --> PROD 


which are three hosts with custom Perl installation (latest). This is just an example topology that matches my job place policy. Adapt it to your needs,mutatis mutandis.

·                    DEV is the first host, connected toInternet, with a freezed CPAN mirror serving to the TEST host.

·                    The TEST host, mirrors CPAN from DEV whichis test safe, specially for make installdeps.

·                    The PROD host, runs Perl software testedin the TEST host.


(TEST 和 PROD 将通过DEV安装perl module )

Let's start now!

## 开始在DEV 上安装perl, 以下安装环境为linux。


You can copy and paste to get your latest Perl installed, except for bold command lines where you have to choose you Perl root dir and your Perlversion.

Create your Perl root folder, for instance /opt/Perl and set permissionsproperly,
probably you will need to use sudo.

[user@darkstar]$ export PERL_ROOT=/opt/Perl
[user@darkstar]$ sudo mkdir $PERL_ROOT
[user@darkstar]$ sudo chown user:group $PERL_ROOT


Create folder structure.

[user@darkstar]$ mkdir $PERL_ROOT/src
[user@darkstar]$ mkdir $PERL_ROOT/CPAN


Download latest Perlsources, for instance version 5.14.2,
and put them under $PERL_ROOT/src folder.

[user@darkstar]$ export PERL_VERSION=5.14.2
[user@darkstar]$ cd $PERL_ROOT/src
[user@darkstar]$ tar xzvf perl-$PERL_VERSION.tar.gz
[user@darkstar]$ cd perl-$PERL_VERSION


Now build your Perl !

Just use defaults and point to your folders.

[user@darkstar]$ sh Configure -des -Dprefix=$PERL_ROOT/$PERL_VERSION-Dscriptdir=$PERL_ROOT/$PERL_VERSION/bin


And pray the mantra, make ... make test ( DON'T MISS IT ! ) ... make install.

[user@darkstar]$ make 
[user@darkstar]$ make test
[user@darkstar]$ make install


##安装完成,清除安装文件。

Clean up.

[user@darkstar]$ cd ..
[user@darkstar]$ rm -rf perl-$PERL_VERSION


## 配置


Now add this symbolic link, it will be useful in the future to switch to latestPerl version.

[user@darkstar]$ ln -s $PERL_ROOT/$PERL_VERSION $PERL_ROOT/current


Set up your env, for instance add these lines to your bash profile ...

export PERL_ROOT=/opt/Perl
export CPAN_ROOT=$PERL_ROOT/CPAN
export CPAN_MINI_CONFIG=$PERL_ROOT/.minicpanrc 
export PATH=$PERL_ROOT/current/bin:$PATH


and reload it.

[user@darkstar]$ source $HOME/.bash_profile


You can check if you are pointing to the right Perl.

[user@darkstar]$ perl -v


## DEV开始上网安装本地CPAN


You can upgrade Perl simply repeating installation and using the sympolic linkto point to latest version. 

Habemus Perl, now it's time to update CPAN !

Since this is the first time you use the cpan shell, it will prompt you forconfiguration: just use defaults, i.e. type <ENTER> as in an '80s shootem all :)

[user@darkstar]$ cpan CPAN


Install CPAN::Mini

[user@darkstar]$ cpan CPAN::Mini


Now you can set up your local mirror using your favourite editor (of course vim :).

[user@darkstar]$ vim $CPAN_MINI_CONFIG

 

local: $ENV{CPAN_ROOT}
remote: REMOTE_CPAN_MIRROR
exact_mirror: 1


Put exactly $ENV{CPAN_ROOT}, it works !

REMOTE_CPAN_MIRROR  is a working CPAN mirror,
type the following to know your current list ...


## 查看下载地址


[user@darkstar]$ cpan
cpan> o conf urllist


the last entry should work (type q to exit the cpan shell).

It's time to update your mirror, just type ...

[user@darkstar]$ minicpan


since it takes a lot of time to mirror all the stuff :), so go out and have abeer.

Ok, ok ... maybe you should type instead

[user@darkstar]$ nohup minicpan > /dev/null &


so you can go holiday :)

After a while evaluate this pseudo code

if( pickedUpGirl || pickedUpBoy ) { 
    raise Exception;
} else { 
    return toHaveFun; 
}


I assume pickedUpGirl is false :-).

Now you can configure cpan shell to point to your local CPAN mirror

[user@darkstar]$ cpan
cpan> o conf urllist
cpan> o conf urllist file:///path/to/local/cpan
cpan> o conf commit


where path/to/local/cpan is the absolute path to your localCPAN mirror, i.e. what you set for CPAN_ROOT in your .bash_profile.

Your DEV host is ready, now repeat Perl installation on TEST and PRODhosts.

Develop your software on DEV host.

Pack your software as a compliant CPAN distribution.
This helps organize your code, add documentation, write tests, include scripts.

Then use CPAN::Mini::Inject toadd your distro, to CPAN mirror on DEV and make it installable via cpan client.

[user@darkstar]$ cpan CPAN::Mini::Inject
[user@darkstar]$ mcpani -H


And read the mcpani man ... I'm sorry but right now I don't remember theoptions :-P

## 在DEV上启动 http server ,提供 CPAN 下载.

## 上不了internet的机器,可以使用 o conf urllist 命令指定本地CPAN下载地址。( http://DEV的本地IP:8080 )


On DEV and TEST host install CPAN::Mirror::Server::HTTP, itworks great!

[user@darkstar]$ cpan CPAN::Mirror::Server::HTTP
[user@ darkstar]$ cpanmirrorhttpd --root $CPAN_ROOT


Yep, there is a running CPAN listening to 8080 port.
Install and configure minicpan on TEST.

Mirror CPAN on TEST host from DEV host if your distro tests on DEV are ok.
Launch cpanmirrorhttpd on TEST host
Configure cpan client on PROD host to point to TEST host on 8080 port.


Summary

On DEV, TEST and PROD you have latest Perl release.

On DEV:

·                    you develop your software packaged as aCPAN distro

·                    there is a CPAN mirror, where you injectyour distro

·                    cpan client points to local CPAN

·                    there is CPAN server on port 8080

On TEST:

·                    there is a CPAN mirror, that points to DEV

·                    cpan client points to local CPAN

·                    install your distro using cpan client andrun your software

On PROD:

·                    cpan client points to CPAN mirror on TEST

·                    run your software installed via cpanclient


Come on guys, Perl is awesome !!!

 

引用网址 :  http://perl-node-interface.blogspot.com/2012/02/install-your-own-perl-with-your-own.html

 类似资料: