简体   繁体   中英

Perl not recognizing module / module path for root user

I am new to Perl so please bear with me. Thank you for your assistance.

I have an Ubuntu machine with Perl on it. I followed thelocal::lib bootstrapping guide

I used cpanm to install DBI and other modules to my system. I am concerned there may be other DBI modules available on my system which could be part of the problem. This is the result of find / -name 'DBI.pm' 2>/dev/null :

/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/blib/lib/DBI.pm
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/blib/lib/Bundle/DBI.pm
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/DBI.pm
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/lib/Bundle/DBI.pm
/home/ubuntu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/DBI.pm
/home/ubuntu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/Bundle/DBI.pm

I added 2 lines to my.bashrc file. (I added the second line because I broke things for the non-root user and this fixed it; maybe I broke something with local::lib?)

eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
PERL5LIB="/home/ubuntu/perl5/lib/perl5"

I can run my perl script as a non-root user. If I run with sudo perlScript.pl I get this error: Can't locate DBI.pm in @INC (you may need to install the DBI module)

I have been troubleshooting @INC for a while now and cannot figure out how to adjust it for the root user. I have tried various things including adding PERL5LIB to.profile and calling my script like so: sudo sh -c '. ~/.profile; perl ~/perlScripts/perlScript.pl "argForScript"' sudo sh -c '. ~/.profile; perl ~/perlScripts/perlScript.pl "argForScript"' sudo sh -c '. ~/.profile; perl ~/perlScripts/perlScript.pl "argForScript"' (I verified that PERL5LIB is being set with sudo sh -c '. ~/.profile; echo $PERL5LIB' )

However I always get the @INC error. The most obvious thing I have noticed is comparing sudo perl -V and perl -V . The sudo call does not show any ENV vars and the @INC does not include the desired PERL5LIB location. The non-sudo call does show the desired ENV and @INC vars.

I am considering wiping things and doing a fresh install with root privileges for local::lib and cpan. Not really sure what else to try at this point.

These are the commands that ended up working for me. I corrupted my first environment with local::lib / non-sudo cpan install, so I setup a fresh VM.

sudo apt install make
sudo apt install build-essential
sudo apt install libmysqlclient-dev
sudo cpan App::cpanminus
cpanm --sudo DBI
cpanm --sudo Array::Utils
cpanm --sudo DBD::mysql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM