Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out where a Perl module is installed?

People also ask

Where are Perl modules installed Ubuntu?

You'll find them in /usr/lib/perl/{VERSION}/ as well as /usr/lib64/perl/{VERSION}/ . {VERSION} corresponding to the version of Perl. You can get it with perl --version .

How do I know if perl DBI module is installed on Linux?

If the module is not installed, then: $ perl -e 'use dbi' Can't locate dbi.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14. 2 /usr/local/share/perl/5.14. 2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .)

How do I find the perl path in Unix?

if the path is correct, you should see in output the list of perl modules currently installed. Once you have identified the correct path, you can add it to your user's PATH (i.e. if you're using bash shell, edit your . bash_profile and add the path /usr/bin to PATH, like: PATH=$PATH:/usr/bin). locate: not found.


perl -MTime::HiRes -e 'print $INC{"Time/HiRes.pm"}' or perldoc -l Time::HiRes


Mostly I use perldoc to get a location:

$ perldoc -l Module

You can also get module details with the cpan tool that comes with Perl:

$ cpan -D Time::HiRes
Time::HiRes
-------------------------------------------------------------------------
    High resolution time, sleep, and alarm
    J/JH/JHI/Time-HiRes-1.9719.tar.gz
    /usr/local/perls/perl-5.10.0/lib/5.10.0/darwin-2level/Time/HiRes.pm
    Installed: 1.9711
    CPAN:      1.9719  Not up to date
    Andrew Main (Zefram) (ZEFRAM)
    [email protected]

It even works on modules that you haven't installed:

$ cpan -D Win32::Process
Win32::Process
-------------------------------------------------------------------------
    Interface to Win32 Process functions
    J/JD/JDB/Win32-Process-0.14.tar.gz
    Installed: 
    CPAN:      0.14  Not up to date
    Jan Dubois (JDB)
    [email protected]

I think maybe I need an XML option like svn.


Note: This solution proposes use of a (self-authored) utility that you must download. While it offers what I believe to be helpful features, installing a third-party solution first is not an option for everyone.


I've created whichpm, a cross-platform CLI (Linux, macOS, Window) that locates installed Perl modules by module (package) name, and optionally reports information about them, including detection of accidental duplicates.

Examples

# Locate the Data::Dumper module.
$ whichpm Data::Dumper
/usr/lib/perl/5.18/Data/Dumper.pm

# Locate the Data::Dumper module, and also print
# version information and core-module status.
$ whichpm -v Data::Dumper
Data::Dumper    2.145   core>=5.005 /usr/lib/perl/5.18/Data/Dumper.pm

# Locate the Data::Dumper module and open it in your system's default text
# editor.
$ whichpm -e Data::Dumper

# Look for accidental duplicates of the Foo::Bar module.
# Normally, only 1 path should be returned.
$ whichpm -a Foo::Bar
/usr/lib/perl/5.18/Foo/Bar.pm
./Foo/Bar.pm

# Print the paths of all installed modules.
$ whichpm -a

Installation

Prerequisites: Linux, macOS, or Windows, with Perl v5.4.50 or higher installed.

Installation from the npm registry

With Node.js or io.js installed, install the package as follows:

[sudo] npm install whichpm -g

Manual installation (macOS and Linux)

  • Download the CLI as whichpm.
  • Make it executable with chmod +x whichpm.
  • Move it or symlink it to a folder in your $PATH, such as /usr/local/bin (OSX) or /usr/bin (Linux).

If need to find which modules are actually used by your script you can use perl debuggers M command:

[ivan@server ~]$ perl -d your_script.pl
...

Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.

DB M
'AutoLoader.pm' => '5.60 from /usr/lib/perl5/5.8.8/AutoLoader.pm'
'Carp.pm' => '1.04 from /usr/lib/perl5/5.8.8/Carp.pm'
...

This will help in case when you have modules with same names but in different folder.


I just find another one: http://www.perlmonks.org/?node_id=568730

#!/bin/sh

echo 'print map { sprintf( "%20s : %s\n", $_, $INC{$_} ) } sort keys %INC; print "\n'$1' version : $'$1'::VERSION\n\n"' | perl "-M$1" 

the script just print out everything in %INC when you run perl -MSTH::STH

eg:

$ whichpm CGI       
              CGI.pm : /System/Library/Perl/5.8.6/CGI.pm
         CGI/Util.pm : /System/Library/Perl/5.8.6/CGI/Util.pm
             Carp.pm : /System/Library/Perl/5.8.6/Carp.pm
         Exporter.pm : /System/Library/Perl/5.8.6/Exporter.pm
         constant.pm : /System/Library/Perl/5.8.6/constant.pm
         overload.pm : /System/Library/Perl/5.8.6/overload.pm
           strict.pm : /System/Library/Perl/5.8.6/strict.pm
             vars.pm : /System/Library/Perl/5.8.6/vars.pm
         warnings.pm : /System/Library/Perl/5.8.6/warnings.pm warnings/register.pm : /System/Library/Perl/5.8.6/warnings/register.pm

CGI version : 3.05

I like to use the V module.

Just install it from CPAN or by installing the package libv-perl on Debian or Ubuntu.

Then use it like this:

$ perl -MV=DBI
DBI
    /Users/michiel/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/darwin-2level/DBI.pm: 1.636

Other output example:

$ perl -MV=Time::HiRes
Time::HiRes
    /usr/lib/perl/5.18/Time/HiRes.pm: 1.9725