How to Install Perl on Arch Linux

Perl excels at text processing, log analysis, and system automation where regular expressions and one-liner syntax make quick work of tasks that would require verbose code in other languages. Common use cases include parsing log files, transforming data formats, automating system administration tasks, and building web applications with frameworks like Mojolicious or Dancer. By the end of this guide, you will have Perl installed on Arch Linux with proper PATH configuration for all Perl tools, access to both repository modules and CPAN, and the ability to write and execute Perl scripts.

Update Arch Linux Before Installation

Synchronize package databases and upgrade installed packages before installing new software. Arch Linux is a rolling release distribution, so regular updates ensure package compatibility:

sudo pacman -Syu

Install Perl on Arch Linux

The perl package is available in the official Arch Linux core repository. It includes the Perl interpreter, core modules, and documentation tools.

Install Perl from Official Repositories

Install Perl using pacman:

sudo pacman -S perl

The Arch Linux Perl package bundles over 100 core modules including JSON::PP, HTTP::Tiny, Test::Simple, and CPAN.pm, eliminating the need to install common modules separately.

Verify the Installation

Confirm Perl is installed and check the version:

perl -v | head -5

Expected output:

This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-linux-thread-multi

Copyright 1987-2025, Larry Wall

Verify the installation path using the POSIX-compliant command -v (the which utility is not installed by default on minimal Arch systems):

command -v perl
/usr/sbin/perl

Arch Linux installs Perl to both /usr/bin/perl and /usr/sbin/perl. Both paths point to the same binary, so either location works correctly.

Configure PATH for Perl Tools

Arch Linux places Perl scripts and tools in separate directories that are not included in the default PATH. The /usr/bin/core_perl/ directory contains tools bundled with Perl (like perldoc), while /usr/bin/vendor_perl/ contains tools from additional packages (like cpanm and perlbrew). Without adding these directories to your PATH, commands like perldoc, cpanm, and perlbrew will return “command not found” errors.

Add both directories to your shell PATH permanently:

echo 'export PATH="/usr/bin/core_perl:/usr/bin/vendor_perl:$PATH"' >> ~/.bashrc
source ~/.bashrc

If you use Zsh instead of Bash, add the export line to ~/.zshrc instead.

Verify the PATH update worked by checking that perldoc is now accessible:

command -v perldoc
/usr/bin/core_perl/perldoc

Access Perl Documentation

With the PATH configured, perldoc provides built-in documentation for Perl functions, modules, and syntax. Arch Linux includes perldoc with the main Perl package, unlike some distributions that package documentation separately:

perldoc -f print | head -10

Expected output showing documentation for the print function:

    print FILEHANDLE LIST
    print FILEHANDLE
    print LIST
    print   Prints a string or a list of strings. Returns true if
            successful. FILEHANDLE may be a scalar variable containing the
            name of or a reference to the filehandle, thus introducing one
            level of indirection.

To read documentation for a specific module:

perldoc JSON::PP

Install Perl Modules on Arch Linux

Perl modules extend the language with additional functionality for databases, web development, text processing, and more. Arch Linux supports multiple installation methods, each with different trade-offs for updates, compatibility, and convenience.

MethodChannelVersionUpdatesBest For
PacmanArch ReposDistribution defaultAutomatic via pacman -SyuMost users who prefer tested, system-integrated packages
cpanminusCPANLatest stableManual via cpanmDevelopers needing modules not in repos or specific versions
CPAN ShellCPANLatest stableManual via cpanUsers who prefer interactive configuration and module management
local::libCPANLatest stableManual via cpanmUsers without root access or wanting per-user module isolation

For most users, Pacman is recommended because it integrates with system updates and packages are tested for Arch Linux compatibility. Use cpanminus or CPAN when you need a module that is not available in the repositories or when you require a specific version.

Install Modules via Pacman

The official repositories contain hundreds of pre-built Perl modules with the perl- prefix. Search for available modules:

pacman -Ss perl- | head -20

The output lists available modules (package names and versions vary as packages are updated):

extra/perl-dbi 1.647-2
    Database independent interface for Perl
extra/perl-json 4.10-2
    JSON (JavaScript Object Notation) encoder/decoder
extra/perl-www-mechanize 2.20-1
    Automates web page form & link interaction

Install specific modules using pacman. For example, to install the DBI database interface and JSON module:

sudo pacman -S perl-dbi perl-json

Common modules available in the official repositories:

  • perl-dbi: Database-independent interface for database access
  • perl-json: Encode and decode JSON data
  • perl-xml-parser: Parse XML documents
  • perl-lwp-protocol-https: HTTPS support for LWP
  • perl-datetime: Date and time manipulation
  • perl-gtk3: GTK3 bindings for GUI applications

Install Modules via cpanminus

For modules not available in the official repositories, cpanminus provides a streamlined way to install directly from CPAN with automatic dependency resolution. First, install cpanminus:

sudo pacman -S cpanminus

The cpanm command installs to /usr/bin/vendor_perl/cpanm. Since you already added /usr/bin/vendor_perl to your PATH in the earlier configuration step, the command should be available immediately. Verify it works:

cpanm --version | head -3
cpanm (App::cpanminus) version 1.7048 (/usr/bin/vendor_perl/cpanm)
perl version 5.042000 (/usr/bin/perl)

Install modules system-wide with sudo:

sudo cpanm Module::Name

For example, to install the popular Mojolicious web framework:

sudo cpanm Mojolicious

For user-space module installation without root privileges, configure local::lib first. Run cpanm local::lib, then add eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)" to your ~/.bashrc. After sourcing the file, subsequent cpanm commands will install modules to ~/perl5 instead of system directories.

Install Modules via CPAN Shell

The traditional CPAN shell provides interactive module management. On first run, CPAN.pm prompts for configuration:

cpan

The configuration wizard asks whether to use automatic or manual configuration. For most users, automatic configuration works well:

Would you like to configure as much as possible automatically? [yes]

When asked about installation approach, choose sudo for system-wide installation or local::lib for user-space installation:

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib]

Once configured, install modules from the CPAN shell:

cpan[1]> install Data::Dumper

Exit the CPAN shell with:

cpan[2]> exit

Test Your Perl Installation

Verify that Perl can compile and execute code by creating a simple test script.

Create a Test Script

Create a file named hello.pl:

nano hello.pl

Add the following Perl code:

#!/usr/bin/env perl
use strict;
use warnings;

print "Hello, World!\n";
print "Perl version: $^V\n";

The shebang line #!/usr/bin/env perl locates Perl in the system PATH, making the script portable across different installations. The use strict and use warnings pragmas enable error checking and are considered best practice for all Perl scripts.

Save the file with Ctrl+O, press Enter, then exit with Ctrl+X.

Run the Script

Make the script executable and run it:

chmod +x hello.pl
./hello.pl

Expected output:

Hello, World!
Perl version: v5.42.0

Alternatively, run the script directly with the Perl interpreter without making it executable:

perl hello.pl

Test a Perl One-Liner

Perl one-liners are useful for quick text processing tasks. Test that Perl can process piped input:

echo "hello world" | perl -pe 's/world/Arch Linux/'
hello Arch Linux

This demonstrates Perl’s text substitution capabilities, commonly used for log parsing, data transformation, and quick edits.

Manage Multiple Perl Versions with Perlbrew

Arch Linux installs a single system-wide Perl version that updates with the rolling release cycle. For development workflows requiring multiple Perl versions, such as testing module compatibility with older releases or maintaining legacy applications, perlbrew manages separate Perl installations in your home directory without affecting the system Perl.

Install perlbrew from the official repositories:

sudo pacman -S perlbrew

The perlbrew command installs to /usr/bin/vendor_perl/perlbrew. If you configured your PATH earlier in this guide, the command should be available immediately. Initialize perlbrew for your user account:

perlbrew init
perlbrew root (~/perl5/perlbrew) is initialized.

Append the following piece of code to the end of your ~/.bash_profile and start a new shell, perlbrew should be up and fully functional from there:

    source ~/perl5/perlbrew/etc/bashrc

Simply run `perlbrew` for usage details.

Happy brewing!

Add the perlbrew environment to your shell configuration as instructed in the output:

echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc
source ~/.bashrc

List available Perl versions you can install:

perlbrew available

Install an additional Perl version. The installation compiles Perl from source, which takes several minutes depending on your hardware:

perlbrew install perl-5.38.0

Switch to the new Perl version:

perlbrew switch perl-5.38.0

Verify you are now using the perlbrew-managed version:

perl -v | head -2

Perlbrew installs Perl versions under ~/perl5/perlbrew/perls/. Each version maintains its own set of installed modules, so modules installed for one Perl version are not automatically available in another. Use perlbrew switch perl-system to return to the system Perl.

Troubleshooting

Perl Commands Not Found (perldoc, cpanm, perlbrew)

Error: Running perldoc, cpanm, or perlbrew returns “command not found” even after installation.

Cause: Arch Linux installs Perl tools to directories not included in the default PATH. Core Perl tools go to /usr/bin/core_perl/ and vendor tools (from additional packages) go to /usr/bin/vendor_perl/.

Diagnostic: Confirm the tools exist but are not in PATH:

ls /usr/bin/core_perl/perldoc /usr/bin/vendor_perl/cpanm /usr/bin/vendor_perl/perlbrew 2>/dev/null

Fix: Add both directories to your PATH:

echo 'export PATH="/usr/bin/core_perl:/usr/bin/vendor_perl:$PATH"' >> ~/.bashrc
source ~/.bashrc

For Zsh users, add the export line to ~/.zshrc instead. After sourcing, verify the commands are available with command -v perldoc.

Module Not Found After Installation

Error: A script fails with “Can’t locate Module/Name.pm in @INC”.

Diagnostic: Check Perl’s module search paths:

perl -V | grep -A 20 '@INC'

Fix: Ensure the module is installed for the correct Perl installation. If using perlbrew, modules installed system-wide are not visible to perlbrew-managed Perl versions. Reinstall the module under the active Perl environment:

cpanm Module::Name

CPAN Permission Denied Errors

Error: Module installation fails with “Permission denied” when writing to system directories.

Diagnostic: The error indicates the module is trying to install system-wide without root privileges:

ERROR: Can't create '/usr/lib/perl5/site_perl/...'
Permission denied

Fix option 1: Install with sudo for system-wide installation:

sudo cpanm Module::Name

Fix option 2: Configure local::lib for user-space installation. This is the preferred approach if you do not have root access or want to keep CPAN modules separate from system packages:

cpanm local::lib
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >> ~/.bashrc
source ~/.bashrc

After configuring local::lib, cpanm installs modules to ~/perl5 without requiring root.

Remove Perl from Arch Linux

To remove Perl and its dependencies:

sudo pacman -Rns perl

The -Rns flags remove the package (-R), orphaned dependencies (-s), and configuration backup files (-n).

If you installed cpanminus or other Perl-related packages, remove them explicitly:

sudo pacman -Rns cpanminus perlbrew

Verify removal:

pacman -Qi perl

Expected output:

error: package 'perl' was not found

If you configured local::lib or perlbrew, modules installed to ~/perl5 remain after removing the system Perl package. Remove them manually with rm -rf ~/perl5 if no longer needed.

If you added PATH modifications to ~/.bashrc during this guide, remove those lines manually:

  • The export PATH="/usr/bin/core_perl:/usr/bin/vendor_perl:$PATH" line (if added)
  • The source ~/perl5/perlbrew/etc/bashrc line (if using perlbrew)
  • The eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)" line (if using local::lib)

Frequently Asked Questions

Is Perl pre-installed on Arch Linux?

No, Perl is not pre-installed on the base Arch Linux system. You must install it manually with pacman -S perl. However, some packages may pull in Perl as a dependency, so it may be present if you installed other software first.

Why do perldoc, cpanm, and perlbrew show command not found?

Arch Linux installs Perl tools to /usr/bin/core_perl/ and /usr/bin/vendor_perl/, which are not in the default PATH. Add both directories to your PATH by adding export PATH="/usr/bin/core_perl:/usr/bin/vendor_perl:$PATH" to your ~/.bashrc and running source ~/.bashrc.

Should I install Perl modules via pacman or CPAN?

Prefer pacman when a module is available in the official repositories (perl-* packages) because it integrates with system updates and is tested for Arch Linux. Use cpanm or CPAN for modules not available in the repositories or when you need a specific version.

What is the difference between cpan and cpanm?

Both install Perl modules from CPAN. cpan is the traditional interactive shell included with Perl that prompts for configuration and provides a command-line interface. cpanm (cpanminus) is a lighter-weight, zero-configuration alternative that installs modules with a single command and handles dependencies automatically.

Can I have multiple Perl versions on Arch Linux?

Yes, use perlbrew to install and manage multiple Perl versions in your home directory. This allows switching between Perl versions for testing without affecting the system installation. Install perlbrew from the official repositories with pacman -S perlbrew.

Conclusion

You now have Perl installed on Arch Linux with proper PATH configuration for all Perl tools, access to both repository and CPAN modules, and the ability to manage multiple Perl versions with perlbrew. For database-driven scripts, connect to SQLite or PostgreSQL using the DBI modules, or automate deployment workflows by combining Perl scripts with Docker containers. For advanced CPAN configuration, IDE integration, and GUI toolkit bindings, refer to the Arch Wiki Perl documentation.

Leave a Comment

Let us know you are human: