Automatically Install Package-Based Perl Modules in Ubuntu - perl

I would like to install the Perl modules required by a specific Perl script, such as those listed by the perl-depends tool. However, I would like to do that in Ubuntu using the apt-get, meaning installing the modules through the package repository and not through CPAN.
Most similar questions (such as this one) address ways of doing that through CPAN.

Debian-Apt-PM

This will list all packages having perl in them:
sudo apt-cache search perl *
then:
sudo apt-get install pkg_name_in_output

Related

perlbrew: installing a perl module locally

I've got perlbrew installed on OS X fine, and can install Perl modules from CPAN, using 'cpanm' no problem.
But, now I'm attempting to install a Perl module provided from a software vendor, and that PM is not on CPAN - you download it from their application and install it "locally".
I'm not sure how to accomplish this with perlbrew ?
The documentation states to do a direct install, download the tar.gz file, extract it, then:
cd Infoblox-xxxxxxx/
perl Makefile.PL
make
make install
But if I do this, I guess it will install it for the OS Perl version, not my perlbrew install.
The other option mentioned is to create a local CPAN site and add the appliance URL (to grab the Perl module) to the list of sites. Is this possible with perlbrew ?
Thanks !
cd Infoblox-xxxxxxx/
perl Makefile.PL
make
make install
But if I do this, I guess it will install it for the OS Perl version, not my perlbrew install.
If you are using perlbrew to select your perl, it should install in the appropriate location for the perl you selected.
which perl will tell you which perl you are using.
If you want to use a specific perl without leaving things to perlbrew, you can always invoke the specific perl you want using its full path:
cd Infoblox-xxxxxxx/
~/perl5/.../bin/perl Makefile.PL
make
make install

apt-get Perl 5.18.2 in debian:wheezy with threading support

I'm trying to install perl 5.18.2 with threading support in ubuntu using apt-get (binary installation, not from source)
Basically, the equivalent of the following perlbrew-based installation
perlbrew install -v perl-5.18.2 -Dusethreads -n --as perl-5.18.2_WITH_THREADS
in apt-get method:
sudo apt-get install perl perl-base
But the above apt-get command installs an older version and has no way to get perl compiled with threading support. Is there a PPA hosting perl 5.18.2 compiled with threads binary? If so, what is the apt-get command to install from it?
No, this isn't possible.
Debian uses Perl internally for a number of system management tasks — it's a critical system component. As the Perl ABI changes between major versions, and all of the Perl modules in Debian are compiled against the version of Perl that was supplied with that release, you can't safely replace the system Perl with another version. Trying to do so will result in a completely broken system.
If you want a different Perl version than the one that came with the Debian release you're using, you'll need to install it to an alternate location (e.g, using perlbrew), or use another Debian release and/or distribution.

purpose of installing a perl module with apt-get instead of cpan

While loading necessities into my crouton, apt-get recommended that I install libtemplate-perl. This seemed a jolly idea, and I obeyed.
Reading this answer, I see a fellow traveler install Plack and Starman via CPAN, but then use apt-get to install Dancer.
Minutes before reading said answer, I had installed Dancer via CPAN. And it had worked. It had worked real good!
What happens differently when I install a CPAN package via a non-CPAN package manager? Are there pitfalls I need to be wary of because my libtemplate-perl came from apt-get, or my Dancer came from CPAN?
On Debian or Debian based distros like Ubuntu, CPAN (/usr/bin/cpan utility) installs modules into /usr/local/lib/ by default. And Debian packages keep their files in /usr/share/perl5/ and /usr/lib/perl5/.
It's a better way to choose dh-make-perl tool to package any CPAN distribution not available in your apt repositories, to avoid making mess (serious risk of conflict between apt and CPAN):
dh-make-perl --build --cpan Some::Module
dpkg -i some-module*.deb
Also check out about local::lib and perlbrew.
A lot of tutorials, Stack Overflow answers, walk throughs, etc. will not want to assume that you know how to use /usr/bin/cpan and will instead suggest that you use your system's package manager, which you are more likely to be familiar with.
This is especially true if you are using a tool written in a particular language, but you don't know that language. For example many people wouldn't care whether crouton is written in Perl, Python or Lisp, they just want a tool they can use. Your average Debian or Ubuntu user is more likely to be familiar with apt-get than with cpan.
If you are looking to program in Perl I recommend installing things by cpan, using perlbrew and/or local::lib. If you are just looking to install a tool you can use, I would recommend using apt-get.
Additionally apt-get has the advantage that non-Perl dependencies will be installed automatically. For example the CPAN module XML::LibXML requires that the libxml2 headers are available on the system; the CPAN distribution has no way of stating that as a dependency, and will simply fail on install if it can find the headers to link against. The Debian package can actually specify that libxml2 is a dependency, and will install the dependency automatically for you.
Despite that if you are looking to use XML::LibXML as a Perl programmer, I would recommend installing it with cpan and installing the libxml2 package via apt-get. Having all your Perl modules installed in the same place - again, via perlbrew or local::lib - will help you keep your sanity in the future. CPAN is preferable to apt-get in this case because not all distributions have been packaged for Debian, and so you get a lot more options if you use CPAN directly.
In summary: TIMTOWTDI ;-)
Another difference to mention that I don't see in other answers, is that if you use CPAN to install a module then the module version you get will be set, until you decide to upgrade that module. Whereas, if you use apt and a later version appears in Debian at some point in the future, then apt-get upgrade will update it.
Maybe you want that, maybe you don't. It's neither necessarily an advantage, nor a disadvantage. Simply a difference to be noted.
The good things about apt-get are
that you can uninstall the packages afterwards should you need to
if you are maintaining any number of servers it is quicker to use apt-get as there is no building required
there are definite versions of packages which are tested for compatibility
The downsides are
not necessarily the latest version of packages
not all packages are available
apt-get installs are generally easier and better than cpan because of dependencies alone.
If you are so lucky as to need SOAP::Lite, for example, it is many dozens of dependencies, and a one-line "apt-get install libsoap-lite-perl".
It is sometimes not clear how Perl CPAN names map to their repository package names, but "apt-cache search " is your friend.
Another approach, that can be used for any distro in HOME install as simple user:
Pros
avoid conflicts
up to date version of perl and modules
when you reinstall, you keep your home/perl as-si
you can upgrade all installed modules with $ cpan -r
Cons
you need to upgrade Perl manually
How to
Edit ~/.bashrc or such, and add:
export PERL5LIB=~/localperl/lib/
export PATH=~/localperl/bin:$PATH
Then
source ~/.bashrc
Install latest Perl5 from sources: https://www.cpan.org/src/README.html
Now, you have an isolate Perl installation in your home.
Enjoy the power to install any libs via:
$ cpan -i Whatever::Module

How do I install CPAN modules while using perlbrew?

I have started using perlbrew and installed perl-5.12.2.
I understand I need to re-install my CPAN modules, so I switched to my new Perl version (perlbrew switch perl-5.12.2 and hash -r), verified the switch was successful (perl -v) then tried installing some module (File::Copy::Recursive using cpan. However, cpan says `File::Copy::Recursive is up to date (0.38).
When I start a Perl script using this module, it shouts Can't locate File/Copy/Recursive.pm in #INC ... (showing many perl-5.12.2 locations). When I switch back to my 'normal' Perl (perlbrew off) the script runs fine.
Any suggestions? Perhaps CPAN does not work well with perlbrew?
After installing perlbrew you could install cpanm through this command:
perlbrew install-cpanm
Otherwise you will need to install cpanm manually each time you switch your Perl version on perlbrew. With this command just once.
Once installed you can then use cpanm to install the missing module:
cpanm File::Copy::Recursive
Everything should be working fine with "cpan" as well as "cpanm", that is: when switching perl with perlbrew, cpan sees the installed modules of the version you use.
While it's true that cpanm is the recommended tool to use with perlbrew, cpan allows for test reporting so that is what I always use.
How do I install CPAN modules while using perlbrew?
That's how:
perlbrew use <version>
cpan -i <module>

How do I update all my CPAN modules to their latest versions?

How do I update all my CPAN modules to their latest versions?
An alternative method to using upgrade from the default CPAN shell is to use cpanminus and cpan-outdated.
These are so easy and nimble to use that I hardly ever go back to CPAN shell. To upgrade all of your modules in one go, the command is:
cpan-outdated -p | cpanm
I recommend you install cpanminus like the docs describe:
curl -L https://cpanmin.us | perl - App::cpanminus
And then install cpan-outdated along with all other CPAN modules using cpanm:
cpanm App::cpanoutdated
BTW: If you are using perlbrew then you will need to repeat this for every Perl you have installed under it.
You can find out more about cpanminus and cpan-outdated at the Github repos here:
https://github.com/miyagawa/cpanminus
https://github.com/tokuhirom/cpan-outdated
An easy way to upgrade all Perl packages (CPAN modules) is the following way:
cpan upgrade /(.*)/
cpan will recognize the regular expression like this and will update/upgrade all packages installed.
For Strawberry Perl, try:
cpan -u
Try perl -MCPAN -e "upgrade /(.\*)/". It works fine for me.
upgrade
BTW there is a help command.