How can I install CPAN modules locally without root access (DynaLoader.pm line 229 error)?

21,217

Solution 1

Personally I would suggest to use local::lib. :)

Solution 2

When you installed the module, did you watch the output? Where did it say it installed the module? Look in lib. Do you see the next directory you expect?

Look in ~/lib to see where eveything ended up to verify that you have the right directory name in your use lib statement:

% find ~/lib -name CSV_XS.so

Once you see where it is installed, use that directory name in your use lib (or PERL5LIB or whatever).

I expect you have a lib/lib in there somehow. The PREFIX is just the, well, prefix, and the installer appends other directory portions to that base path. That includes lib, man, bin, etc.

Solution 3

Try this instead:

'makepl_arg' => q[PREFIX=~/]

PREFIX sets the base for all the directories you will be installing into (bin, lib, and so forth.)

You may also be running into shell expansion problems with your '~'. You can try to expand it yourself:

'makepl_arg' => q[PREFIX=/home/users/foobar]

It would also be helpful if you included the commands you used to get the error you are asking about.

Solution 4

It looks from the error message ("at /www/common ...") that your script is a CGI or mod_perl script. The web server is probably not running as the user 'foo', under whose home directory you've installed the module - that could result in the web server being unable to read that directory.

It may also be running in a "chroot jail", which would mean that the directory in which you've installed the module may not be visible to the script.

In other words, just because you can see the module, does not mean that the web server, and therefore your script, can do so. You should check the relevant file permissions, and if the server is chrooted, whether your module directory is mounted within the virtual file system.

Share:
21,217
Pankaj Sharma
Author by

Pankaj Sharma

Updated on July 15, 2022

Comments

  • Pankaj Sharma
    Pankaj Sharma almost 2 years

    Doesn't work with other modules, but to give an example. I installed Text::CSV_XS with a CPAN setting:

    'makepl_arg' => q[PREFIX=~/lib],
    

    When I try running a test.pl script:

    $ perl test.pl

    #!/usr/bin/perl
    
    use lib "/homes/foobar/lib/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi";
    
    use Text::CSV_XS;
    
    print "test";
    

    I get

    Can't load '/homes/foobar/lib/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Text/CSV_XS/CSV_XS.so' for module Text::CSV_XS: /homes/foobar/lib/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Text/CSV_XS/CSV_XS.so: cannot open shared object file: No such file or directory at /www/common/perl/lib/5.8.2/i686-linux/DynaLoader.pm line 229.
    at test.pl line 6
    Compilation failed in require at test.pl line 6.
    BEGIN failed--compilation aborted at test.pl line 6.
    

    I traced the error back to DynaLoader.pm it happens at this line:

    # Many dynamic extension loading problems will appear to come from
    # this section of code: XYZ failed at line 123 of DynaLoader.pm.
    # Often these errors are actually occurring in the initialisation
    # C code of the extension XS file. Perl reports the error as being
    # in this perl code simply because this was the last perl code
    # it executed.
    
    my $libref = dl_load_file($file, $module->dl_load_flags) or
        croak("Can't load '$file' for module $module: ".dl_error());
    

    CSV_XS.so exists in the above directory

  • Pankaj Sharma
    Pankaj Sharma over 15 years
    then the script can't find CSV_XS.pm which is on dir up
  • Pankaj Sharma
    Pankaj Sharma over 15 years
    PERL5LIB='/homes/foobar/lib/perl5/site_perl/5.8.4/i686-linux‌​:{HOME}/lib/perl5/si‌​te_perl/5.8.4' nope tried with Data::UUID, same problem
  • Pankaj Sharma
    Pankaj Sharma over 15 years
    but then the script won't work for anyone else. anyway i could always ask IT support to have it installed as a root, but that's not a point
  • brian d foy
    brian d foy over 15 years
    I'm sorry, but I don't understand your comment. Did you find where the module was installed and use the right directory in use lib?
  • Pankaj Sharma
    Pankaj Sharma over 15 years
    yes the path is right from the very beginning, but it doesn't work in DynaLoader
  • singingfish
    singingfish over 15 years
    local::lib is a much better solution than this one
  • Chris Quenelle
    Chris Quenelle over 11 years
    It would be very useful to provide here a few short commands that show how to use local::lib to install a module into a local library directory.
  • Stefan Lasiewski
    Stefan Lasiewski over 10 years
    Can you please explain why you suggested local::lib? What is it, and why is it better then the other solutions presented here?
  • Olivier Dulac
    Olivier Dulac almost 7 years
    And how do we do that when: Can't locate local/lib.pm in @INC .... (and we can't install it, hence the need to install modules underneath one's homedir)