MLS
MLS

Reputation: 21

CPAN modules claim to install but dont

Running UBUNTU 14.04 through VirtualBox.

When executing a script, i get the following error:

Can't locate XML/Simple.pm in @INC (@INC contains:... 

Now, when I check the directories in @INC, they indeed do not contain XML/Simple.pm

I then tried installing it through cpan

sudo cpan XML::Simple

and it tells me that:

XML::Simple is up to date (2.20).

which, according to perl is not true, since the output of

perl -e "use XML::Simple "

is

Can't locate XML/Simple.pm in @INC (@INC contains:

So, what am I missing?

Upvotes: 0

Views: 1655

Answers (3)

David Raab
David Raab

Reputation: 4488

As a System Administrator or Application developer there is a common problem that you usally face. When you develope an Application you probably always want the newest and latest modules, and not the modules that are shiped with the distribution. But even if you are fine with the versions in your Linux distibution sometimes you have the problem that you want a specific Perl module and it is not included in your distribution.

The usally way to solve that problem was just a call to lets say cpan XML::Simple and the latest module gets downloaded and installed.

But when you do this, you are messing with the package system of your Linux distribution. Lets say you already had XML::Simple installed from your package system. Your cpan command will now update the already installed version and replace it with a newer version. All of that is fine, until your Linux distribution for example would ship an update for libxml-simple-perl. What than could happen is that your new version gets reverted to an old version.

And because all Perl modules usally depends on other Perl Modules, an install command also can update a lot of other Perl modules.

All of that behaviour can leads to weired bugs. Either way in application you write, or also in application shiped in your distribution.

To "resolve" that problem, usally the best way is to leave the system Perl completly alone. Compile your own Perl Version completly from source. That Perl version than has its own perl libraries that you can install directly from CPAN without messing with the System Perl.

Now to do that very easy, their exists a tool named Perlbrew

With this tool you can easily install any Perl Version. For example just typing perlbrew install perl-5.16.0 and it completly installs Perl 5.16.0 in your home directory! It also setups all paths so a call to perl in your system resolve to this perlbrew installation.

Also an important part is that this Perl installation is just in your home directory under a normal user account. You don't need sudo or a root Account, because Perl gets installed in your home directory.

The same goes for Perl Modules. If you want to install a Perl Module in your Perlbrew installation you just type cpan XML::Simple (or cpanm XML::Simple checkout App::cpanminus).

Now the important part. On your system you already had a setup for Perlbrew. When you executed your installation program that Perlbrew installation was used. But in this Perlbrew installation there was no XML::Simple installed.

You then executed sudo cpan XML::Simple to install XML::Simple. The problem is that all sudo commands just gets executed as a root user. That means your system Perl /usr/bin/perl is used instead of your Perlbrew installation in /home/qiime/perl5/perlbrew/perls/perl-5.16.0/bin/perl

You successfully install XML::Simple in your System Perl. But your Perlbrew installation didn't had XML::Simple installed and thus it still returned an error that it could not found XMl::Simple.

The only thing you really needed to do was just cpan XML::Simple installing XML::Simple in your perlbrew installation in your home directory.

Upvotes: 1

Grant McLean
Grant McLean

Reputation: 6998

An alternative way to install Perl modules on Linux systems is from the distribution repository. On Debian/Ubuntu systems the general rules for converting a CPAN distribution name to an apt package name is:

  1. convert the module name to lower case
  2. convert '::' to '-'
  3. add a 'lib' prefix and a '-perl' suffix

So the package name for XML::Simple would be: libxml-simple-perl and you could install it with:

sudo apt-get install libxml-simple-perl

There are exceptions to these rules, but you can always search by Perl module name:

apt-cache search XML::Simple

You won't get the absolute latest version of the module from your distro's package repository but for stable (some might say 'moribund') modules like XML::Simple that usually doesn't matter.

If you do have multiple versions of Perl installed, then installing from your distro's package repository will usually only make the package available for the system Perl in /usr/bin

Upvotes: 3

Sinan Ünür
Sinan Ünür

Reputation: 118118

In general, you should not mess with the system perl.

Use

$ which perl

and

$ sudo which perl

to see where each perl lives.

Upvotes: 1

Related Questions