- Unix Commands Reference
- Unix Commands - Home
cpan Command in Linux
cpan is a Linux command that allows you to interact with the comprehensive Perl Archive Network (CPAN) from the terminal. With the cpan command, you can install Perl modules and extensions, either by specifying modules names or using switches for extra behavior. You can also create an autobundle, view module details and recompile modules from the cpan command.
If you are a Perl programmer, you will hardly find any better go-to-tool than cpan for managing CPAN modules and dependencies.
Syntax of cpan Command
The cpan command syntax varies based on different scenarios −
1. Installing Specific Modules
cpan <module_name> [ module_name ... ]
2. Installing Modules Using Switches with Extra Behavior
cpan [-cfgimtTw] <module_name> [ module_name ... ]
3. Installing Modules from the Distribution in the current directory
cpan .
4. Starting CPAN.pm shell Without Arguments
cpan
5. Dumping the Configuration
cpan -J
6. Loading a Different Configuration to Install Module::Foo
cpan -j some/other/file Module::Foo
7. Using Switches Without Arguments
cpan [-ahrvACDlLO]
Common Options with cpan Command
You can use different options or flags with the cpan command in you Linux system, these are discussed in the table given below −
Option | Description |
---|---|
-a | Generates a CPAN.pm autobundle using CPAN::Shell->autobundle. |
-A module [ module … ] | Displays the primary maintainers of specific modules. |
-c module | Cleans specified module directories with make clean. |
-C module [ module … ] | Shows Changes released to files for specified modules. |
-D module [ module … ] | Gives detailed information about specific modules. |
-f | Forces actions (even if tests fail during installation). |
-F | Disables CPAN.pm’s locking attempts (use with caution). |
-g module [ module … ] | Downloads latest module distribution to current directory. |
-G module [ module … ] | UNIMPLEMENTED (for creating Git repositories from distributions). |
-h | Prints help messages and exits. |
-i | Installs specified modules. |
-I | Loads “local::lib” (similar to “-I” for lib paths). |
-j Config.pm | Loads CPAN configuration data from a file. |
-J | Dumps configuration in CPAN.pm format. |
-l | Lists installed modules with versions. |
-L author [ author … ] | Lists modules by specific authors. |
-m | Make specified modules. |
-O | Shows out-of-date modules. |
-p | Pings configured mirrors. |
-P | Finds the best mirrors (without configuring them). |
-r | Rebuilds dynamically loaded modules. |
-t | Runs “make test” process on specified modules. |
-T | Installs modules without testing. |
-u | Upgrades all installed modules (use with caution). |
-v | Prints script version and CPAN.pm version. |
-V | Provides detailed information about cpan clients. |
-w | UNIMPLEMENTED. |
Examples of cpan Command in Linux
Let’s explore some of the widely used examples of cpan command in Linux system −
- Install Modules
- Create an Autobundle
- Recompile Modules
- Upgrade All Installed Modules
- Force Install Modules
Install Modules
You can use the cpan command on Linux to install modules on your system. For that purpose, simply use the -i option followed by the module name you want to install with the cpan command. For example, to install the Netscape::Bookmarks and Business::ISBN modules, you can run the below-given command −
cpan -i Netscape:Bookmarks Business::ISBN
Create an Autobundle
You can also generate a bundle of installed module by using the cpan command followed by the -a option on your Linux system, as given below −
cpan -a
Recompile Modules
With cpan command, you can use -r option to recompile existing modules on your Linux system, the command is given below −
cpan -r
Upgrade All Installed Modules
To upgrade all installed modules on your system, you can simply use -u option with the cpan command as given below −
cpan -u
Force Install Modules
If by chance your test fails, you can perform the force installation of a module by using the cpan command with the -fi option. For example, to perform the force installation of a module named CGI::Minimal URI, you can use the following command −
cpan -fi CGI::Minimal URI
That’s how cpan command actually works on Linux systems.
Conclusion
The cpan is a powerful Linux command that can be used to install and manage Perl modules and extensions on your Linux system. This tutorial presented the syntax of cpan command along with different options that can be used to customize the command’s behavior. Moreover, examples are also provided that are tested one by one on the Linux system to ensure the effectiveness of the command. You can get help from the examples and explore more options to customize the command according to your needs.