Skip to content

Perl Environment Installation

Check if Perl is Already Installed

Most Linux and Unix systems (including macOS) come with Perl pre-installed. You can check with the following command:

bash
perl -v

If you see output similar to the following, Perl is already installed:

This is perl 5, version 38, subversion 0 (v5.38.0) built for x86_64-linux
...

If not installed or you need to upgrade, follow the steps below.

Installing on Linux

Ubuntu/Debian

bash
# Update package list
sudo apt-get update

# Install Perl
sudo apt-get install perl

# Install additional development tools (recommended)
sudo apt-get install build-essential cpanminus

CentOS/RHEL/Fedora

bash
# CentOS/RHEL
sudo yum install perl
sudo yum install perl-App-cpanminus

# Fedora
sudo dnf install perl
sudo dnf install perl-App-cpanminus

Arch Linux

bash
sudo pacman -S perl perl-cpanminus

Compile from Source (Latest Version)

If you need to install the latest version of Perl:

bash
# 1. Download source code
wget https://www.cpan.org/src/5.0/perl-5.38.0.tar.gz

# 2. Extract
tar -xzf perl-5.38.0.tar.gz
cd perl-5.38.0

# 3. Configure
./Configure -des -Dprefix=$HOME/localperl

# 4. Compile and install
make
make test
make install

# 5. Update PATH (add to ~/.bashrc or ~/.zshrc)
export PATH="$HOME/localperl/bin:$PATH"

Installing on macOS

Using Homebrew

bash
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Perl
brew install perl

# Install cpanminus
brew install cpanminus

Using System Perl

macOS comes with Perl, but the version may be outdated. You can install an updated version through a package manager.

Installing on Windows

Strawberry Perl is the most popular Perl distribution on Windows, including a compiler and complete CPAN support.

  1. Visit the Strawberry Perl website
  2. Download the latest installer (e.g., strawberry-perl-5.38.0.1-64bit.msi)
  3. Run the installer and follow the prompts
  4. After installation, open Command Prompt and enter perl -v to verify

Using ActivePerl

ActivePerl is another Perl distribution for Windows, offering commercial support.

  1. Visit the ActivePerl website
  2. Download the free community edition
  3. Run the installer
  4. Verify installation: perl -v

Using Chocolatey

If you use Chocolatey package manager:

powershell
# Run PowerShell as administrator
choco install strawberryperl

Configuring Perl Environment

Setting Environment Variables

Linux/macOS

Edit ~/.bashrc or ~/.zshrc, add:

bash
# Perl related paths
export PERL5LIB="$HOME/perl5/lib/perl5:${PERL5LIB}"
export PERL_LOCAL_LIB_ROOT="$HOME/perl5:${PERL_LOCAL_LIB_ROOT}"
export PERL_MB_OPT="--install_base \"$HOME/perl5\""
export PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"
export PATH="$HOME/perl5/bin:${PATH}"

Then reload the configuration:

bash
source ~/.bashrc
# or
source ~/.zshrc

Windows

Strawberry Perl automatically configures environment variables after installation. For manual configuration:

  1. Right-click "This PC" → "Properties" → "Advanced System Settings" → "Environment Variables"
  2. Find "Path" in "System Variables" and add:
    • C:\Strawberry\perl\bin
    • C:\Strawberry\perl\site\bin
    • C:\Strawberry\c\bin

Configuring CPAN

CPAN is Perl's module repository and needs configuration to work properly.

bash
# First run will enter interactive configuration
perl -MCPAN -e shell

# Or use cpanminus (recommended, simpler)
cpanm

During configuration, usually choosing default options is sufficient.

Installing Common Modules

bash
# Install using cpanminus
cpanm Modern::Perl
cpanm Data::Dumper
cpanm JSON::XS
cpanm DBI
cpanm DBD::mysql
cpanm LWP::UserAgent

Verifying Installation

Create a test script test.pl:

perl
#!/usr/bin/perl
use strict;
use warnings;
use v5.38;

print "Perl version: $^V\n";
print "Perl installation path: $^X\n";
print "Operating system: $^O\n";
print "Hello, World!\n";

Run the test:

bash
# Linux/macOS
chmod +x test.pl
./test.pl

# or
perl test.pl

# Windows
perl test.pl

Text Editors

  • Vim: Powerful editor with Perl syntax highlighting plugins
  • Emacs: Feature-rich editor supporting Perl
  • VS Code: Modern editor with excellent Perl plugins
  • Sublime Text: Lightweight editor supporting Perl

IDEs

  • Padre: IDE designed specifically for Perl
  • Eclipse: Supports Perl through EPIC plugin
  • Komodo IDE: Commercial IDE supporting Perl

VS Code Perl Plugins

Recommended VS Code plugins:

  1. Perl - Provides syntax highlighting, code snippets
  2. Perl Navigator - Provides IntelliSense, code navigation
  3. Perl Critic - Code quality checking

Installation method:

  1. Open VS Code
  2. Press Ctrl+Shift+X to open the Extensions panel
  3. Search and install the plugins above

Common Issues

Q: perl command not found

A: Check if the PATH environment variable includes Perl's bin directory.

Q: Module installation failed

A:

  1. Ensure network connection is working
  2. Use cpanm --notest <Module> to skip tests
  3. Check if dependencies are complete

Q: Permission issues

A:

  • Linux/macOS: Use sudo or install to user directory
  • Windows: Run Command Prompt as administrator

Q: Multiple Perl versions coexisting

A: Use perlbrew to manage multiple Perl versions:

bash
# Install perlbrew
curl -L https://install.perlbrew.pl | bash

# Install specific version
perlbrew install perl-5.38.0
perlbrew switch perl-5.38.0

Summary

After completing this chapter, you should have:

  1. ✅ Successfully installed Perl on your system
  2. ✅ Configured the development environment
  3. ✅ Installed necessary tools and modules
  4. ✅ Able to run Perl scripts

Next, we will learn Perl Basic Syntax.

Content is for learning and research only.