19

I have downloaded the module Digest::SHA1 and extracted it to a directory (../Digest-SHA1-2.13/) , then copied all the SHA1.* files into (../Digest-SHA1-2.13/Digest)

and in the perl script, I did : use Digest::SHA1; launching the script like this:

perl -I ../Digest-SHA1-2.13/Digest perlscriptname.pl

I get this error:

Can't locate loadable object for module Digest::SHA1 in @INC

I assume it has something to do with a shared library (*.so)?, I have no idea how to continue from here.

I can install it directly using CPAN (-MCPAN) module, as I dont have permissions on that server to do that, and can install only locally (where the application is running). My final goal is to use Algorithm::CouponCode which is dependent on Digest::SHA1

The weird part is, that I have Digest::SHA1 installed (perl -MDigest::SHA1 -e 'print $Digest::SHA1::VERSION' shows version 2.11), still Algorithm::CouponCode (which is installed the same way I did with Digest::SHA1) complains it can find it in @INC

thanks!

snoofkin
  • 8,725
  • 14
  • 49
  • 86
  • From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [How can I install a CPAN module into a local directory?](http://stackoverflow.com/questions/540640/how-can-i-install-a-cpan-module-into-a-local-directory) – daxim Sep 26 '11 at 11:00

3 Answers3

37

Use this recipe for manually installing perl modules:

tar zxf Digest-SHA1-2.13.tar.gz
cd Digest-SHA1-2.13
perl Makefile.PL
make
make test
make install

Note that some distributions will have a Build.PL file instead of Makefile.PL. In that case use this recipe:

tar zxf ...
cd ...
perl Build.PL
./Build
./Build test
./Build install

(You may be able to get by with just running make install and ./Build install.)

If you need to alter the installation dir then use:

perl Makefile.PL INSTALL_BASE=...

or

perl Build.PL --install_base ...

depending on the kind of module.

For more info see the perldoc for ExtUtils::MakeMaker::FAQ and Module::Build

ErikR
  • 51,541
  • 9
  • 73
  • 124
5

There are two kinds of Perl module: pure-Perl and XS. Pure-Perl modules are written entirely in Perl, and can usually be installed just by copying the .pm files to an appropriate directory. XS modules are written in both Perl and C (XS is processed into C code by the ExtUtils::ParseXS module) and require a C compiler to install them.

As dsolimano said, the easiest way to install Perl modules for the system Perl when you don't have root access is to use local::lib. (You could do the same things that local::lib does yourself, but why bother?)

The reason why Digest::SHA1 works by itself but not when you're using Algorithm::CouponCode is that the system Perl already has version 2.11 of Digest::SHA1 installed. When you use -I ../Digest-SHA1-2.13/Digest, then use Digest::SHA1 picks up the Perl code from ../Digest-SHA1-2.13/Digest, but the shared library that would be built from the XS code is not in the corresponding location.

cjm
  • 61,471
  • 9
  • 126
  • 175
  • local::lib seems to be broken... it tries to fetch modules from non working URLs.. hence I cant install anything – snoofkin Sep 24 '11 at 23:20
  • 1
    @soulSurfer2010, you should ask another question about that (with more details). It sounds too complicated to discuss in comments. – cjm Sep 25 '11 at 12:13
  • Ok I will gather all the issues and post a new question. for the meantime, the answer I accepted solved the issue, but now I rather try to dig into why local::lib didnt work, it seems like a really handy module – snoofkin Sep 25 '11 at 13:32
4

Any reason why you can't use local::lib?

create and use a local lib/ for perl modules with PERL5LIB

It is basically a tool to help you use a private (non-systemwide) directory as your Perl library directory.

After setting it up, you could run a command like

perl -MCPAN -Mlocal::lib -e 'CPAN::install(Algorithm::CouponCode)'

and then your script would use your locally installed copy of Algorithm::CouponCode).

cjm
  • 61,471
  • 9
  • 126
  • 175
dsolimano
  • 8,870
  • 3
  • 48
  • 63