how to change configuration of CPAN from local::lib to sudo preference - perl

Hi am new to using perl and installed CPAN using the code:
$ perl -MCPAN -e shell
and i got the following prompt:
To install modules, you need to configure a local Perl library directory or escalate your privileges. CPAN can help you by bootstrapping the local::lib module or by configuring itself to use 'sudo' (if available). You may also resolve this problem manually if you need to customize your setup.
What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
I selected local::lib, but i realized that may not be the best for what I want to do and now would like to switch to sudo to build modules not in a local library. I have tried to build libraries but they always get put in a local library.
How would I do this?
Thanks

CPAN may store its configuration and the choice you made in several places, however, you should take a look first at /etc/perl/CPAN/Config.pm and/or $HOME/.cpan/CPAN/MyConfig.pm.
Deleting these file (you may move them as a backup if you're not sure) will reset CPAN to default behavior.
You may also have a look inside these files, find the exact parameter, and remove the corresponding line.
try grep local::lib ~/.cpan/CPAN/MyConfig.pm for example...

To disable local::lib and get the configuration prompt again you must remove:
PATH="/home/.../perl5/bin${PATH:+:${PATH}}";
export PATH;
PERL5LIB="/home/.../perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}";
export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/.../perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}";
export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/.../perl5\"";
export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/.../perl5";
export PERL_MM_OPT;
From ~/.bashrc

Related

Perl Module install to mentioned directory

I want to install a Perl module to a particular directory which I am mentioning while executing a command.
I want this module to be installed in a mentioned path.
Command I tried is
$ env PERL_MM_OPT='INSTALL_BASE=/home/vinod/my_test_folder/perl_practice/scripts' cpanm Log::Log4perl
But this by default installed in /home/vinod/my_test_folder/perl_practice/scripts/lib/perl5.
What could be the reason? How to install the module in particular directory which I am mentioning?
See the documentation of INSTALL_BASE. You seem to be interested in changing just the INSTALLPRIVLIB path. Maybe you want to set the LIB attribute only, described in the next section?

CPAN first launching configuration

I'm taking a look into Perl as a total beginner. I want to try some CPAN modules.
When I run an install command on my Osx console, CPAN asks for a configuration with the following statement :
To install modules, you need to configure a local Perl library
directory or escalate your privileges. CPAN can help you by
bootstrapping the local::lib module or by configuring itself to use
'sudo' (if available). You may also resolve this problem manually if
you need to customize your setup.
What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
What is the difference between local::lib and sudo options ?
If I understand it well, it installs some modules locally on my computer. But I don't see any difference between the two config above.
If you use sudo, CPAN will use root to install the libraries in a central location where all users on the machine can access the files without any special configuration. If you use 'local::lib', it will create a library in your home directory and install the modules such that only perl programs that have been configured to look for modules in your home directory will find the modules.
Perl uses the special variable #INC to search for module paths. So you can install modules anywhere as long as you set #INC properly before you use them. This article explains the basics.
http://www.symkat.com/find-a-perl-modules-path
You can do all kinds of fun stuff with #INC; one of my favorite hacks it to put a function pointer in there and use custom perl code to lookup modules.
Good question. When you use local::lib, you can install Modules via CPAN User specific in an given directory. Assume you choose sudo as approach, you install Modules global.
Its like installing Node.js via npm. When you install a module with npm install -g <Modul>, its global installed and you can use it everywhere. But withouth that -g flag, its just available inside your current directory.
Its about the same here, except that you choose the default way of installing CPAN Modules.

How do I install a CPAN module site-wide while local::lib is present?

I've recently set up a new system and wanted to install Padre to check it out. The Padre install instructions specifically said to install local::lib, so I did so (although I've never had need of it before). I then went on my way installing several other modules, running CPAN from my normal user account with sudo to handle the root-required portions of the installation.
Then time came to test out one of the web apps these modules were needed to support and, lo and behold, apache couldn't find them. They loaded fine from the command line and a quick look in ~/perl5 confirmed my suspicion that local::lib had hijacked my CPAN sessions and installed these modules there instead of in a site-wide location, despite my CPAN config including
makepl_arg [INSTALLDIRS=site]
mbuildpl_arg [--installdirs site]
What do I need to do to my CPAN config so that modules will be installed site-wide even though local::lib is installed? Or will Padre work without it and I can just remove local::lib entirely?
(I do not want any modules installed under ~/perl5 unless Padre insists on them being there. My code under development has its own project-specific directory locations and everything else should be site-wide. I have no need for a private catch-all location.)
Got it. Per the instructions on local::lib's CPAN page, I had set export PERL_MM_OPT='INSTALL_BASE=~me/perl', which was overriding the setting in my CPAN config. A quick export PERL_MM_OPT= got me back to a proper install location.
On the one hand, that's what I get for following the instructions blindly. On the other, I would have expected o conf to show the actual config settings that are being used rather than those which are in the saved CPAN config (even if an environment variable is overriding them).
A quick export PERL_MM_OPT= got me back to a proper install location.
This didn't help me when I tried to install Starman globally. I had to edit /root/.bashrc to comment (or to delete) next lines:
export PERL_LOCAL_LIB_ROOT="$PERL_LOCAL_LIB_ROOT:/root/perl5";
export PERL_MB_OPT="--install_base /root/perl5";
export PERL_MM_OPT="INSTALL_BASE=/root/perl5";
export PERL5LIB="/root/perl5/lib/perl5:$PERL5LIB";
export PATH="/root/perl5/bin:$PATH";
Based on this comment, it seems that local::lib installs its own version of CPAN.pm. If this is the case, you may need to find the original CPAN.pm and make sure that that one is loaded when you run your CPAN shell. Something like:
perl -I /usr/lib/perl5 -MCPAN -e shell
might do it. You might also find perl -V useful to see what include path the Perl compiler is using for its modules.

How can I install Perl modules without root privileges?

I am on a Linux machine where I have no root privileges. I want to install some packages through CPAN into my home directory so that when I run Perl, it will be able to see it.
I ran cpan, which asked for some coniguration options. It asked for some directory, which it suggested ~/perl "for non-root users". Still, when I try to install a package, it fails at the make install step, because I don't have write access to /usr/lib/perl5/whatever.
How can I configure CPAN so that I can install packages into my home directory?
See local::lib.
Once you have it installed, you can do:
perl -MCPAN -Mlocal::lib -e 'CPAN::install(LWP)'
There's the way documented in perlfaq8, which is what local::lib is doing for you.
It's also a frequently asked StackOverflow question:
Why does installing certain CPAN modules require root privilege?
How can I install CPAN modules locally without root access (DynaLoader.pm line 229 error)?
How do I tell CPAN.pm to install all modules in a specific directory?
How can I install a CPAN module into a local directory?
How can I use a new Perl module without install permissions?
How can I use CPAN as a non-root user?
How can I install local modules with the cpan tool?
Curiously, none of these are suggested when I use your original question title (which is one of the reasons a good title is very important in finding your answer).
How do I keep my own module/library directory?
When you build modules, tell Perl where to install the modules.
If you want to install modules for your own use, the easiest way might be local::lib, which you can download from CPAN. It sets various installation settings for you, and uses those same settings within your programs.
If you want more flexibility, you need to configure your CPAN client for your particular situation.
For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:
perl Makefile.PL INSTALL_BASE=/mydir/perl
You can set this in your CPAN.pm configuration so modules automatically install in your private library directory when you use the CPAN.pm shell:
% cpan
cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl
cpan> o conf commit
For Build.PL-based distributions, use the --install_base option:
perl Build.PL --install_base /mydir/perl
You can configure CPAN.pm to automatically use this option too:
% cpan
cpan> o conf mbuild_arg "--install_base /mydir/perl"
cpan> o conf commit
INSTALL_BASE tells these tools to put your modules into /mydir/perl/lib/perl5. See How do I add a directory to my include path (#INC) at runtime? for details on how to run your newly installed modules.
There is one caveat with INSTALL_BASE, though, since it acts differently than the PREFIX and LIB settings that older versions of ExtUtils::MakeMaker advocated. INSTALL_BASE does not support installing modules for multiple versions of Perl or different architectures under the same directory. You should consider if you really want that, and if you do, use the older PREFIX and LIB settings. See the ExtUtils::Makemaker documentation for more details.
CPAN way
run cpan command. If you don't have CPAN configurated, do it first! Otherwise, you will see the cpan prompt. In this case, type look local::lib and you will have a new shell prompt. In this new shell, run the bootstrap command configuring and compiling the module at same time as at bellow.
user#host:~/.cpan/build/local-lib-1.004003-UyX2wf$ perl Makefile.PL --bootstrap && make test && make install
Now, export some variables:
Path where local::lib will install things
echo 'eval $(perl -I$index.t/perl5/lib/perl5 -Mlocal::lib)' >> ~/.bashrc
And Perl variable to avoid user input
echo 'export PERL_MM_USE_DEFAULT=1' >> ~/.bashrc
Now load your bashrc running
source ~/.bashrc
Try to install running cpan <SOME_VALID_MODULE_NAMESPACE>
That's it! Now you can install modules using cpan without root privileges. But, remember that this will work just for the CURRENT USER including the root user !
cpanminus way
If you have this installed your sys admin deserves a beer!
Just run
$ cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
Open another terminal and run
$ env |grep PERL
You should see something like this:
PERL5LIB=$HOME/perl5/lib/perl5 PERL_MB_OPT=--install_base "$HOME/perl5"
PERL_LOCAL_LIB_ROOT=$HOME/perl5
PERL_MM_OPT=INSTALL_BASE=$HOME/perl5
But if you're not, export variables like this:
$ echo "export PERL5LIB=\"$HOME/perl5/lib/perl5\"">>~/.bashrc && \
echo "export PERL_MB_OPT=\"--install_base '$HOME/perl5'\">>~/.bashrc && \
echo "export PERL_LOCAL_LIB_ROOT=$HOME/perl5">>~/.bashrc
Finally, load your bashrc file and try to install with commands
source ~/.bashrc
and
cpanm <SOME_VALID_MODULE_NAMESPACE>
Fim!

How can I install Perl module without using CPAN.pm?

Is it possible?
If you download the source code, and read the README file. This will probably tell you you should do
perl Makefile.PL
make
make test
make install
or
perl Build.PL
./Build
./Build test
./Build install
If you download the source code, it will generally have a Makefile.PL. You run "perl Makefile.PL; make; make test; make install" and it will build and install for you.
Obviously if you're not using CPAN.pm, you're going to have to deal with dependencies yourself.
Also, if the reason you can't use CPAN.pm is that you don't have permission to install into /usr/lib/perl, you can force CPAN.pm to install locally, but I forget how.
If you are on a Linux box, a very large portion of the packages can usually be obtained using the built in package manager. For instance, on an Ubuntu system, if you want to install the PostgreSQL Perl module you'd simple do:
sudo apt-get install libpg-perl
You can see a list of the modules for Ubuntu here: http://packages.ubuntu.com/hardy/perl/
I find I can often guess at the names myself. Not sure if this helps at all, but for myself I often find this easier to use than CPAN as it does a lot better at resolving dependencies.
See here: How to install perl modules using CPAN without root
I have just set this up on a server without root access and CPAN does everything automatically.
But if you really wanna install a module without CPAN and you don't have root (assuming this since you don't wanna use CPAN), you can do it as follows
perl Makefile.PL PREFIX=$HOME
make
make install
You're gonna have to hunt down dependencies yourself so it's better to use CPAN.
If the problem is no root access, I would recommend looking at local::lib and also this webpage for CPAN.pm and non-root installation.
But to answer the question as asked, CPAN or CPANPLUS are helpful, but they aren't required. You can always do it the old-fashioned way as Leon says - though usually, it's easier not to.
If you are using Red Hat (Fedora, CentOS), you should use RPM for Perl dependencies wherever possible. Perl packages are almost always named perl-Module-Name, e.g. perl-DBI, perl-Spreadsheet-WriteExcel, etc.
On Ubuntu the naming scheme is libmodule-name-perl.
If the .pm file is pure Perl and doesn't need to be compiled you can just put it in your application's lib folder and use it as normal.
We can install all perl modules both from and even with your terminal in ubuntu. If you are using a ubuntu server then execute the following command ,
'sudo apt-get install "perl_module"'
The modules which you want just give the name in "perl_module" means If you want to install Apache2::Cookie it will be in "libapreq2" so you have to give like,
"sudo apt-get install libapreq2"
I, as others have would highly suggest using CPAN.pm. It is a breeze to use and can resolve any dependencies associated with the module you need automatically.
On the other hand, I would suggest that you read the perlmodinstall document over at perldoc as it gives details on other os' as well.
Regards,
Jeff
If you're asking this because you're having problems with CPAN... you're probably running out of RAM that's why you can't use CPAN.
Maybe you don't have a swap file. Try this:
$ sudo su
# dd if=/dev/zero of=/swap bs=1M count=1k # create a 1GB file
# mkswap /swap
# swapon /swap
Otherwise... stop some services.
$ sudo service mysql stop
$ sudo service nginx stop
...And try again
$ cpan install CPAN
$ cpan install MIME::Lite::TT::HTML