Skip to content

Instantly share code, notes, and snippets.

@rwp0
Last active December 21, 2023 22:46
Show Gist options
  • Save rwp0/45d9139cd42597ea80d085638940dfbc to your computer and use it in GitHub Desktop.
Save rwp0/45d9139cd42597ea80d085638940dfbc to your computer and use it in GitHub Desktop.
Install CPAN Distributions Locally (to a user directory)

CPAN

Run cpan interactively:

o conf makepl_arg INSTALL_BASE=/home/regular/perl
o conf mbuildpl_arg=/home/regular/perl
o conf commit

o conf commit writes to ~/.cpan/CPAN/MyConfig.pm

https://stackoverflow.com/a/543918/13762488 answered by Brian d Foy in 2009

Install

If the @INC directory not specified via the environment variable, cpan fails cannot configuring the installed module, this seem to affect the dependency resolution:

PERL5LIB=/home/regular/perl/lib/perl5 \
  cpan -T \
    Crypt::OpenSSL::Guess \
    Crypt::OpenSSL::AES \

ExtUtils-MakeMaker

Options for EUMM can be permanently set in PERL_MB_OPT environment variable.

perl Makefile.PL INSTALL_BASE=/home/regular/perl

local-lib

https://metacpan.org/pod/local::lib

# Install LWP and its missing dependencies to the '~/perl5' directory
perl -MCPAN -Mlocal::lib -e 'CPAN::install(LWP)'
 
# Just print out useful shell commands
$ perl -Mlocal::lib
PERL_MB_OPT='--install_base /home/username/perl5'; export PERL_MB_OPT;
PERL_MM_OPT='INSTALL_BASE=/home/username/perl5'; export PERL_MM_OPT;
PERL5LIB="/home/username/perl5/lib/perl5"; export PERL5LIB;
PATH="/home/username/perl5/bin:$PATH"; export PATH;
PERL_LOCAL_LIB_ROOT="/home/usename/perl5:$PERL_LOCAL_LIB_ROOT"; export PERL_LOCAL_LIB_ROOT;

Module-Build

Options for MB can be permanently set in PERL_MM_OPT environment variable.

perl Build.PL --install_base /home/regular/perl

Perl

Library directory for Perl can be permanently set in PERL5LIB environment variable.

Calling the script:

perl -I/home/regular/perl/lib/perl5 /home/regular/perl/bin/perltidy --version

Note that -I (@INC) won't understand ~ because it's concatenated to it (and therefore can't be expanded by the shell).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment