Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: Best practices for local libraries

by dsheroh (Monsignor)
on Dec 08, 2019 at 09:27 UTC ( #11109835=note: print w/replies, xml ) Need Help??

in reply to Re: Best practices for local libraries
in thread Best practices for local libraries

Quick and dirty option: add a symlink to your modules into an existing perl include path
The OP mentions using apt-get install, which strongly implies he's using a Debian or Debian-derived system. A default Debian install will have /usr/local/lib/site_perl in @INC for precisely this purpose. But this does, obviously, make any modules linked there available to all users on the machine rather than user-specific, which may or may not be acceptable to the OP.

Really, though, the only real problem I see in the OP is the bit about the user's $PERL5LIB carrying over to root when using su. My solution to that is, quite simply, to use sudo instead, as it does not carry over the original user's environment:

me@host:~$ export FOO=bar me@host:~$ echo $FOO bar me@host:~$ sudo -i [sudo] password for me: root@host:~# echo $FOO root@host:~# exit logout me@host:~$ sudo bash root@host:/home/me# echo $FOO root@host:/home/me#
If you prefer su over sudo, you should be able to get the same effect by using su - or su --login to open a login shell with a fresh environment instead of preserving the previous shell's environment. From the Debian 10 version of man su:
       For backward compatibility, su defaults to not change the  current  di‐
       rectory  and to only set the environment variables HOME and SHELL (plus
       USER and LOGNAME if the target user is not root).  It is recommended to
       always use the --login option (instead of its shortcut -) to avoid side
       effects caused by mixing environments.
and, from the Debian 8/9 versions of the man page:
           Note that the default behavior for the environment is the

               The $HOME, $SHELL, $USER, $LOGNAME, $PATH, and $IFS environment
               variables are reset.

               If --login is not used, the environment is copied, except for
               the variables above.

               If --login is used, the $TERM, $COLORTERM, $DISPLAY, and
               $XAUTHORITY environment variables are copied if they were set.

               Other environments might be set by PAM modules.
So just add --login to your su command and $PERL5LIB won't be carried over to your root shell.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11109835]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-04-11 08:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found