Installing CPAN modules via local :: lib

August 30, 2009 · Posted in Perl

DEPRECATED: This text has been obsoleted by the text Perl increasingly easy .

Installing CPAN modules on machines where you do not have root permissions is very simple. Using the module's own local :: lib CPAN, you can create a local installation in which the modules are installed in your own home.

Setting up cpan

Simply call a terminal and type the command cpan. It will show a short introduction message and ask if you would like to let you configure everything automatically. For most cases the automatic configuration is sufficient, but I'll set some options for myself, so I'll answer 'no'.

  Would you like me to configure automatically much as Possible?  [Yes] in 

The first option that I will answer different from the default is the policy that defines the prerequisites (<prerequisites_policy>). It defines what the cpan should do when faced with a module that has an addiction. The default is 'ask' (ask).

  Policy on building prerequisites (follow, ask or ignore)?  [Ask] follow 

I'll change it to 'follow' (below). So when the cpan find a module that has some dependence, rather than ask me, he will try to install it automatically. This is extremely useful during long facility with a dependency tree as large as the Catalyst.

  Policy on installing 'build_requires' modules (yes, no, ask / yes,
 ask / no)?  [Ask / yes] yes 

Following is a question about the installation of build dependencies of the modules. I will change to 'ask / yes' to 'yes' to the build dependencies are also installed. The default was to ask and suggest yes for an answer.

Next comes a series of questions about the tools normally use cpan. I take this moment to check if any is missing, then install it.

  Where is your bzip2 program?  [/ Bin/bzip2]

 Where is your gzip program?  [/ Bin / gzip] 

Several options then the next is that I change the default charset ISO-8859-1 to UTF-8.

  The next option deals with the charset (aka character set) your
 terminal supports.  In general, CPAN is English speaking territory, so
 the charset does not matter much but some CPAN have names That Are
 outside the ASCII range.  If your terminal supports UTF-8, You Should
 say no to the next question.  If it expects ISO-8859-1 (also known to
 LATIN1) then you Should say yes.  If it supports Neither, your answer
 does not matter because you will not be Able to read the names of some
 authors anyway.  If you answer no, names will be output in UTF-8.

 Your terminal expects ISO-8859-1 (yes / no)?  [Yes] in 

The cpan will ask you if it can connect to the Internet to download the list of repositories. He is well educated about the things he needs to do, so we're setting options that let more independent. Answer yes and wait for it to download the server list.

After communicating with the servers default, it asks you about what you want to configure repositories in three steps. First ask the continent, then country and finally the repository itself. You can choose more than one option simultaneously. I chose to continents of South America and North America to countries Brazil, Chile and the United States and finally some repositories in each country. Feel free to choose how and what you want.

Ready. Now you are in the cpan shell.

Installing the module local :: lib

The next step is to install and configure the module local :: lib. For this type in the cpan shell command:

  cpan [1]> look local :: lib 

This will cause the cpan download the module but not install it automatically. Instead it will open a new shell in the directory where it unpacked the module local :: lib.

In this shell, do the bootstrap with the following commands:

  catalyst spectro @: ~ / perl Makefile.PL $ .cpan/build/local-lib-1.004003-UyX2wf \
 - Bootstrap && make test && make install 

Last but not least you need to export some environment variables. To exit the current shell it (Ctrl + D), quit the cpan shell (bye or quit) and run the following command in bash:

  & gt; & gt;~ / .bashrc echo 'eval $ (perl-I $ HOME/perl5/lib/perl5-Mlocal :: lib) "& gt; & gt; ~. / bashrc 

This will add the commands to export the environment variables at the end of your file. Bashrc, and then every login they will be automatically exported.

Force a re-implementation of its bashrc or logout and login again

  catalyst spectro @: ~ $.  ~. / Bashrc 

Make sure that the environment variables are set or strange things may happen. Understand why "strange things" anything other than proper operation. Some can be really bizarre. :)

  | grep perl catalyst spectro @: ~ $ env | grep perl
 home / catalyst / perl5 / lib / perl5: / home / catalyst / perl5 / lib / perl5... PERL5LIB = / home / catalyst / perl5 / lib / perl5: / home / catalyst / perl5 / lib / perl5 ...
 home / catalyst / perl5 / .modulebuildrc MODULEBUILDRC = / home / catalyst / perl5 /. Modulebuildrc
 home / catalyst / perl5 / bin: / usr / local / bin: / usr / bin: / bin: / usr / games PATH = / home / catalyst / perl5 / bin: / usr / local / bin: / usr / bin, / bin, / usr / games
 = / home / catalyst / perl5 PERL_MM_OPT = INSTALL_BASE = / home / catalyst / perl5
 catalyst spectro @: ~ $ 

Touching up her makeup

Now before you begin installing modules, it is a good upgrade module itself CPAN.pm. Note the capitalization.

  catalyst spectro @: ~ $ cpan CPAN
 ...
 Installing / home/catalyst/perl5/bin/cpan
 Writing / home/catalyst/perl5/lib/perl5/i486-linux-gnu-thread-multi/auto ...
 Appending installation info to / home/catalyst/perl5/lib/perl5/i486-linux ...
   ANDK/CPAN-1.9402.tar.gz
   / Usr / bin / make install - OK
 Warning (usually harmless): 'YAML' not installed, will not persist store ...
 catalyst spectro @: ~ $ 

After installing the new version of CPAN.pm note that he is warning that the YAML module is not installed. To make everything go chubby intalá it too.

  catalyst spectro @: ~ $ cpan YAML
 ...
 Writing / home/catalyst/perl5/lib/perl5/i486-linux-gnu-thread-multi/auto/Y ...
 Appending installation info to / home/catalyst/perl5/lib/perl5/i486-linux ...
   INGY/YAML-0.68.tar.gz
   / Usr / bin / make install - OK
 CPAN: YAML loaded ok (v0.68)
 Going to read a yaml file from / home / catalyst / .cpan / build /
 DONE
 Restored none of the state (in 0.0265 secs)
 catalyst spectro @: ~ $ 

Now yes. Let's take a look where did the newly installed module YAML:

  catalyst spectro @: ~ $ ls ~ / perl5/lib/perl5
 CPAN CPAN.pm i486-linux-gnu-thread-multi site Test YAML YAML.pm
 catalyst spectro @: ~ $ 

He was installed in a directory tree created in the current user's home. All this without asking the root password once.

Conclusion

Installing CPAN modules locally without root password is very easy. This is extremely useful on machines where you have only permission to user, and server hosting.

Another advantage is that to take the same modules to another machine (with the same architecture) perl5 just copy the directory you just created, since all modules are installed in it, and add the command that exports the variables environment on the target machine. This is also useful when you have a hosting server that does not give you access to a shell.

Links (in) working

Comments

  • http://rio.pm.org SmokeMachine

    I owe you a beer!

  • http://rio.pm.org SmokeMachine

    I owe you a beer!

  • http://blabos.pip.verisignlabs.com/ blabos

    Then buy me a beer!

  • http://blabos.pip.verisignlabs.com/ blabos

    Then buy me a beer!

  • Russian http://russoz.wordpress.com/

    Blabos So, I am also owe you a beer. ;-) ES next?

  • Russian http://russoz.wordpress.com/

    Blabos So, I am also owe you a beer. ;-) ES next?

  • Marcio Vitor

    Blabos tb I owe you a beer, maybe in next ES. Script to follow too quiet that you wrote this.

  • Marcio Vitor

    Blabos tb I owe you a beer, maybe in next ES. Script to follow too quiet that you wrote this.

  • http://blog.blabos.org/2010/02/criando-um-mini-mirror-do-cpan-com-o-cpanmini/ Creating a mini-mirror with the cpan CPAN :: Mini: Blog of Blabos Blebe

    [...] To configure the application to install cpan modules locally with local :: lib, the first step is to configure the mirror to install and configure the module CPAN :: Mini and its [...]

  • Fernando

    Thank you! :)

    vlw same .. I still have one more doubt .. d after all these procedures if I need to format my debian .. more keeping my / home .. I need a repeat procedure or not?

  • http://blabos.org Blabos of Blebe

    Well, it depends.

    If you reinstall the system with the same version of Perl, no problem.

    Remember that some modules written in C use parts that are compiled and linked with Perl it was installed when installing the module.

    Just remember also that there is a newer text on the subject in the post Perl increasingly easy

  • Fernando

    vlwww .. Blabos! clarify this for me ..

blog comments powered by Disqus