How can I check if a Perl module is installed on my system from the command line?
Solution 1:
You can check for a module's installation path by:
perldoc -l XML::Simple
The problem with your one-liner is that, it is not recursively traversing directories/sub-directories. Hence, you get only pragmatic module names as output.
Solution 2:
Quick and dirty:
$ perl -MXML::Simple -e 1
Solution 3:
$ perl -MXML::Simple -le 'print $INC{"XML/Simple.pm"}'
From the perlvar entry on %INC
:
- %INC
The hash
%INC
contains entries for each filename included via thedo
,require
, oruse
operators. The key is the filename you specified (with module names converted to pathnames), and the value is the location of the file found. Therequire
operator uses this hash to determine whether a particular file has already been included.If the file was loaded via a hook (e.g. a subroutine reference, see require for a description of these hooks), this hook is by default inserted into
%INC
in place of a filename. Note, however, that the hook may have set the %INC entry by itself to provide some more specific info.
Solution 4:
For example, to check if the DBI module is installed or not, use
perl -e 'use DBI;'
You will see error if not installed. (from http://www.linuxask.com)