-2

I'm trying to install a perl module: Net::SSH2 with cpan but doesn't actually works.

cpan -f install Net::SSH2

Output:

CPAN: Storable loaded ok (v2.20) Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz' ............................................................................DONE Going to read '/root/.cpan/sources/modules/02packages.details.txt.gz' Database was generated on Mon, 22 May 2017 22:29:03 GMT HTTP::Date not available ............. New CPAN.pm version (v2.16) available.
[Currently running version is v1.9402] You might want to try install CPAN reload cpan to both upgrade CPAN.pm and run the new version without leaving the current session.

...............................................................DONE Going to read '/root/.cpan/sources/modules/03modlist.data.gz' Can't locate object method "data" via package "CPAN::Modulelist" (perhaps you forgot to load "CPAN::Modulelist"?) at (eval 16) line 1. at /usr/share/perl5/CPAN/Index.pm line 518 CPAN::Index::rd_modlist('CPAN::Index', '/root/.cpan/sources/modules/03modlist.data.gz') called at /usr/share/perl5/CPAN/Index.pm line 85 CPAN::Index::reload('CPAN::Index') called at /usr/share/perl5/CPAN.pm line 955 CPAN::exists('CPAN=HASH(0x21fd2f0)', 'CPAN::Module', 'install') called at /usr/share/perl5/CPAN/Shell.pm line 1243 CPAN::Shell::expandany('CPAN::Shell', 'install') called at /usr/share/perl5/CPAN/Shell.pm line 1639 CPAN::Shell::rematein('CPAN::Shell', 'force', 'install', 'install') called at /usr/share/perl5/CPAN/Shell.pm line 1935 CPAN::Shell::ANON('CPAN::Shell', 'install', 'install') called at /usr/bin/cpan line 318 main::_default('ARRAY(0x1938f18)') called at /usr/bin/cpan line 278

Jobine23
  • 129
  • 9

3 Answers3

1

It seems that your installation of CPAN is incomplete or otherwise corrupted. OS and Perl version could be helpful. On many current Linux distributions, Perl modules and their dependencies can be installed using the normal system software utilities like yum (RHEL/CentOS), apt (Debian/Ubuntu) and yast (SuSE). Drawback is that versions may not be the most current.

Deathgrip
  • 398
  • 4
  • 10
0

This PerlMonks thread has someone else with a similar problem. It looks like this answer worked in that case:

It looks to me like you have some corrupt data in your .cpan directory. I'd blow it away and try again:

$ rm -rf /home/user/.cpan

Try it at your own risk. In your case, you would need to delete /root/.cpan.

In addition, the correct use of cpan is to list the module names after the command. So, instead of cpan install Net::SSH2, you should use cpan Net::SSH2. If you use the -f option, you must specify -i: cpan -f -i Net::SSH2, but try without forcing things first. You do not want to willy-nilly install broken modules in the system's perl.

In fact, in general, you do not want to mess with the system's perl at all. Build your own perl and mess with it as much as you want.

PS: install is a dummy module created precisely because many people make this mistake.

Community
  • 1
  • 1
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
0

The safest and most convenient way to install Perl modules can depend on distribution. For example, the recommended method on Fedora is:

$ sudo dnf install 'perl(Net::SSH2)'

As shown in that example, installing Perl modules on your system usually requires sudo or the root user. So you might want to try your command with sudo if you're a sudoer.

If you don't have that kind of power, you may need to install it locally. That usually means downloading it to a Perl library directory you create in your home directory, and including the path in @INC somehow, such as updating your $PERL5LIB to include the /home/user/perl/modules/Net-SSH2/lib/ or whatever your path to the module lib directory is.

jrefior
  • 4,092
  • 1
  • 19
  • 29