0

I use cpan to install MongoDB on Yosemite. My Steps:

sudo -s
Password:
bash-3.2# cpan

...

cpan[1]> install MongoDB
Running install for module 'MongoDB'
Running make for M/MO/MONGODB/MongoDB-v0.708.4.0.tar.gz

...

Running make install
Manifying 24 pod documents
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/gerd/perl5/lib/perl5/darwin-thread-multi-2level/auto/MongoDB/MongoDB.bundle
Installing /Users/gerd/perl5/lib/perl5/darwin-thread-multi-2level/MongoDB.pm
Installing /Users/gerd/perl5/lib/perl5/darwin-thread-multi-2level/MongoDB/_Types.pm

...

Installing /Users/gerd/perl5/man/man3/MongoDB::Timestamp.3pm
Installing /Users/gerd/perl5/man/man3/MongoDB::Tutorial.3pm
Installing /Users/gerd/perl5/man/man3/MongoDB::WriteResult.3pm
Appending installation info to /Users/gerd/perl5/lib/perl5/darwin-thread-multi-2level/perllocal.pod
  MONGODB/MongoDB-v0.708.4.0.tar.gz
  /usr/bin/make install  -- OK

 cpan[2]> 

After exit cpan I test my Installation:

perl -e'use MongoDB; print MongoDB::VERSION();'
Can't locate MongoDB.pm in @INC (you may need to install the MongoDB module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

I think the problem is the modul location in my HOME-directory /Users/gerd/perl5/lib/perl5/darwin-thread-multi-2level/MongoDB.pm. But where is my mistake in cpan installation process on mac?

Gerd
  • 2,265
  • 1
  • 27
  • 46
  • 2
    It looks like you configured cpan to use local::lib, which will install modules in your home directory instead of in the system Perl directories. – ThisSuitIsBlackNot Sep 21 '15 at 16:06
  • Cool! perl -I ~/perl5/lib/perl5 -Mlocal::lib -e'use MongoDB; print MongoDB->VERSION();' work! Please post your answer and I can vote you up. Can I do -I ~/perl5/lib/perl5 -Mlocal::lib inside the script? – Gerd Sep 22 '15 at 06:44
  • The inline version: perl -e'use lib "$ENV{q(HOME)}/perl5/lib/perl5"; use local::lib; use MongoDB; print MongoDB->VERSION();' – Gerd Sep 22 '15 at 07:21
  • 2
    Glad you got it working. There have actually been quite a few people with this problem lately, so I wrote up a [canonical question and answer](http://stackoverflow.com/q/32726324/176646) that can hopefully address these problems in the future. I think the easiest approach is to use PERL5LIB so you don't have to add `use local::lib;` to all your code; cpan may have already changed PERL5LIB for you as I explain in the linked post. – ThisSuitIsBlackNot Sep 23 '15 at 15:17
  • 1
    Also, if that post does describe the problem you had, I hope you wouldn't mind if I vote to close this question as a duplicate. Don't worry, duplicates are not a bad thing, they act as signposts so people searching for similar questions can land on either the main question or the duplicate and still get their answer. For example, someone who had the same issue as you with MongoDB might end up on this page from a google search, while someone else might end up on my more generalized version; if the two questions are linked as duplicates, both users could get their answer easily. – ThisSuitIsBlackNot Sep 23 '15 at 15:22

0 Answers0