
cpan or cpanm (this article) can be used to install a Perl module.
- Install a module using cpanm (this article)
- Install a module using cpan
Before installing a module, you may want to use the perldoc command to determine if the module is installed.
perldoc -l Net::SSH:Perl
Or using inline Perl.
perl -e "use Net::SSH::Perl"
Or using instmodsh.
~]# instmodsh
Available commands are:
l - List all installed modules
m <module> - Select a module
q - Quit the program
cmd? l
Installed modules are:
Alien::Build
Alien::GMP
Alien::m4
Capture::Tiny
Crypt::Curve25519
Crypt::IDEA
CryptX
Digest::BubbleBabble
ExtUtils::MakeMaker
FFI::CheckLib
File::Which
File::chdir
Math::GMP
Math::Int64
Mojo::DOM58
Net::SFTP
Net::SSH::Perl
Path::Tiny
Perl
Sort::Versions
String::CRC32
Test::Simple
install
local::lib
cmd? q
If you installed Perl using apt-get (Debian, Ubuntu), dnf or yum (CentOS, Fedora, Red Hat) then apt-get, dnf or yum can be used to install cpanm.
dnf install cpanminus
If you installed Perl from source code using make, then the perl -MCPAN command can be used to install cpanm.
perl -MCPAN -e "install App::cpanminus"
Or using cpan.
cpan install App::cpanminus
Here is how you would install a module using cpanm.
cpanm the::module
For example.
cpanm JSON::Create
If the install fails and you are comfortable with ignoring the failed tests, you can try to install the module using the --force flag.
cpanm JSON::Create --force
A successful install of a module that is not already installed will return the following.
Successfully installed module::name-version
A successful update of an already installed module will return the following.
module::name is up to date. (version)
After the module is installed it's probably a good idea to create a boilterplate Perl script that contains the module.
#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH::Perl;
And then use the perl command with the -c option.
~]# perl -c /path/to/example.pl
example.pl syntax OK
On the other hand, if there is some issue, something like this may be returned.
~]$ perl -c /path/to/example.pl
Can't locate Net/SSH/Perl.pm in @INC (you may need to install the Net::SSH::Perl module) (@INC entries checked: /usr/local/bin/perl5.38.2/lib/site_perl/5.38.2/x86_64-linux /usr/local/bin/perl5.38.2/lib/site_perl/5.38.2 /usr/local/bin/perl5.38.2/lib/5.38.2/x86_64-linux /usr/local/bin/perl5.38.2/lib/5.38.2) at example.pl line 4.
BEGIN failed--compilation aborted at example.pl line 4.
Did you find this article helpful?
If so, consider buying me a coffee over at