问题
I wanted to use CPAN to install some Perl packages, but I get the following error when I try to start the CPAN shell:
paulzierep@naproxen:~$ cpan
Can't locate B.pm in @INC (you may need to install the B module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base /home/paulzierep) at /usr/share/perl/5.22/Safe.pm line 34.
BEGIN failed--compilation aborted at /usr/share/perl/5.22/Safe.pm line 34.
Compilation failed in require at /usr/share/perl/5.22/CPAN.pm line 56.
BEGIN failed--compilation aborted at /usr/share/perl/5.22/CPAN.pm line 56.
Compilation failed in require at /usr/share/perl/5.22/App/Cpan.pm line 273.
BEGIN failed--compilation aborted at /usr/share/perl/5.22/App/Cpan.pm line 273.
Compilation failed in require at /usr/bin/cpan line 9.
BEGIN failed--compilation aborted at /usr/bin/cpan line 9.
I can't figure out how to install the missing B module without cpan. I guess this should be installed by default.
I'm using Perl 5.22.1 on Ubuntu 16.04.
Update
So I set the PERL5LIB
or PERL5OPT
to make it find /usr/lib/x86_64-linux-gnu/perl/5.22.1/B.pm
, and CPAN runs, but I can not install anything due to the following error
cpan[1]> install Log::Log4perl
Reading '/home/paulzierep/.cpan/Metadata'
Database was generated on Fri, 30 Sep 2016 06:29:02 GMT
Running install for module 'Log::Log4perl'
Checksum for /home/paulzierep/.cpan/sources/authors/id/M/MS/MSCHILLI/Log-Log4perl-1.47.tar.gz ok
Scanning cache /home/paulzierep/.cpan/build for sizes
............................................................................DONE
'YAML' not installed, will not store persistent state
Configuring M/MS/MSCHILLI/Log-Log4perl-1.47.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
Have /usr/lib/x86_64-linux-gnu/perl/5.22.1
Want /usr/lib/x86_64-linux-gnu/perl/5.22
Your perl and your Config.pm seem to have different ideas about the
architecture they are running on.
Perl thinks: [5.22.1]
Config says: [x86_64-linux-gnu-thread-multi]
This may or may not cause problems. Please check your installation of perl
if you have problems building this extension.
Generating a Unix-style Makefile
Writing Makefile for Log::Log4perl
Writing MYMETA.yml and MYMETA.json
MSCHILLI/Log-Log4perl-1.47.tar.gz
/usr/bin/perl Makefile.PL INSTALLDIRS=site -- OK
Running make for M/MS/MSCHILLI/Log-Log4perl-1.47.tar.gz
make: *** No rule to make target '/usr/lib/x86_64-linux-gnu/perl/5.22/Config.pm', needed by 'Makefile'. Stop.
MSCHILLI/Log-Log4perl-1.47.tar.gz
/usr/bin/make -- NOT OK
Failed during this command:
MSCHILLI/Log-Log4perl-1.47.tar.gz : make NO
So it kind of fixed it and left me with another problem. Any help on this one?
That what I get for:
paulzierep@naproxen:~$ perl -E 'say for @INC'
/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22
/usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base
.
paulzierep@naproxen:/home$ perl -MFile::Spec -E 'say for
File::Spec->path'
/home/paulzierep/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
回答1:
So after having a look on a different systems with pretty similar set-up I found whats the problem with my perl install. It always bugged me, that the 5.22 folder is empty, but still seems to be the folder perl is looking for.
paulzierep@naproxen:/usr/lib/x86_64-linux-gnu/perl$ ls
5.22 5.22.1 cross-config-5.22.1 debian-config-data-5.22.1
In a system with similar set-up I found that the 5.22 was linking to 5.22.1, setting this link solved the problem and perl runs again like a charm.
I additional wanted to point out, that in my reseach I found that the working directory "." seems to be in @INC by default, (http://www.perlmonks.org/bare/?node_id=375341) therefore I am wondering why it seems so strange to some (@Borodin), that my home directory is there (Any directory is there as long as you start cpan from there).
Also I don't see how perlbrew would help here, besides the fact, that you cannot install it without working perl, I don't see how it would help, when your system perl does not work properly.
回答2:
I had the same problem. For some unknown reason, the directory /usr/lib/x86_64-linux-gnu/perl
was empty. My solution was to reinstall the libperl5.22
package.
sudo apt-get install --reinstall libperl5.22
回答3:
$ cpan
Can't locate File/Spec.pm: /usr/local/lib/x86_64-linux-gnu/perl/5.22.1/File/Spec.pm: Permission denied at /usr/share/perl/5.22/CPAN.pm line 10.
BEGIN failed--compilation aborted at /usr/share/perl/5.22/CPAN.pm line 10.
Compilation failed in require at /usr/share/perl/5.22/App/Cpan.pm line 273.
BEGIN failed--compilation aborted at /usr/share/perl/5.22/App/Cpan.pm line 273.
Compilation failed in require at /usr/bin/cpan line 9.
BEGIN failed--compilation aborted at /usr/bin/cpan line 9.
Perl don't looking modules in @INC.
来源:https://stackoverflow.com/questions/39773525/cpan-command-gives-the-error-cant-locate-b-pm-in-inc