Reputation: 425
I have a server where I've installed some perl modules. I installed the first few via CPAN, i.e. perl -MCPAN -e 'install Module::Name' as a non-root user.
Then I ran into some issues, and just started installing them via sudo or root.
I found out last night via some output from a cron job, that some of the scripts are failing because they can't locate the modules in the @INC array.
I discovered that on the server in question, perl -V shows the following:
as root:
%ENV:
PERL5LIB="/root/perl5/lib/perl5:"
PERL_LOCAL_LIB_ROOT=":/root/perl5"
PERL_MB_OPT="--install_base /root/perl5"
PERL_MM_OPT="INSTALL_BASE=/root/perl5"
@INC:
/root/perl5/lib/perl5/x86_64-linux-thread-multi
/root/perl5/lib/perl5
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
and as a non-root user:
%ENV:
PERL5LIB="/home/user/perl5/lib/perl5:"
PERL_LOCAL_LIB_ROOT=":/home/user/perl5"
PERL_MB_OPT="--install_base /home/user/perl5"
PERL_MM_OPT="INSTALL_BASE=/home/user/perl5"
@INC:
/home/user/perl5/lib/perl5/x86_64-linux-thread-multi
/home/user/perl5/lib/perl5
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
I checked another server, where installation of perl modules has never had a problem, and it shows the same output whether run as a non-root user or root, and only has @INC, no $ENV defined.
@INC:
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
So my question is, How can I configure CPAN on the server I'm having problems to not have different Environments and @INC values for different users. I'd rather it just have one default system location for perl modules that are accessible by all. I assume I need to run o conf init from the CPAN shell, or edit /root/.cpan/CPAN/MyConfig.pm and /home/user/.cpan/CPAN/MyConfig directly, but not too sure what exact edits I need to make.
Thank you,
Upvotes: 1
Views: 1444
Reputation: 6378
Since cron tasks could be defined as "system" related I'd do as @ikegami suggests and stick with the system perl and use the package manager to keep the environment consistent across users. It's best to keep root and /root
out of the picture: if root is installing to their $HOME you might as well just use system packages.
If you are creating custom scripts for cron
and running them as a user then you can create a consistent perl environment (or several) for that user with perlbrew
, local::lib
(which you seem to already have installed) and cpanminus
(which can be installed alongside and work seamlessly with perlbrew
).
As a quick fix you can extend your @INC
with -I
(but a non-root user is not going to be able to access /root
obviously) and your %ENV
with other switches and environment variables. See perlrun
for some of those - e.g.:
-Idirectory
Directories specified by -I are prepended to the search path for modules (@INC
).
Upvotes: 0