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:
If you see output similar to the following, Perl is already installed:
If not installed or you need to upgrade, follow the steps below.
Installing on Linux
Ubuntu/Debian
CentOS/RHEL/Fedora
Arch Linux
Compile from Source (Latest Version)
If you need to install the latest version of Perl:
Installing on macOS
Using Homebrew
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
Using Strawberry Perl (Recommended)
Strawberry Perl is the most popular Perl distribution on Windows, including a compiler and complete CPAN support.
- Visit the Strawberry Perl website
- Download the latest installer (e.g.,
strawberry-perl-5.38.0.1-64bit.msi) - Run the installer and follow the prompts
- After installation, open Command Prompt and enter
perl -vto verify
Using ActivePerl
ActivePerl is another Perl distribution for Windows, offering commercial support.
- Visit the ActivePerl website
- Download the free community edition
- Run the installer
- Verify installation:
perl -v
Using Chocolatey
If you use Chocolatey package manager:
Configuring Perl Environment
Setting Environment Variables
Linux/macOS
Edit ~/.bashrc or ~/.zshrc, add:
Then reload the configuration:
Windows
Strawberry Perl automatically configures environment variables after installation. For manual configuration:
- Right-click "This PC" → "Properties" → "Advanced System Settings" → "Environment Variables"
- Find "Path" in "System Variables" and add:
C:\Strawberry\perl\binC:\Strawberry\perl\site\binC:\Strawberry\c\bin
Configuring CPAN
CPAN is Perl's module repository and needs configuration to work properly.
During configuration, usually choosing default options is sufficient.
Installing Common Modules
Verifying Installation
Create a test script test.pl:
Run the test:
Recommended Development Tools
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:
- Perl - Provides syntax highlighting, code snippets
- Perl Navigator - Provides IntelliSense, code navigation
- Perl Critic - Code quality checking
Installation method:
- Open VS Code
- Press
Ctrl+Shift+Xto open the Extensions panel - 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:
- Ensure network connection is working
- Use
cpanm --notest <Module>to skip tests - Check if dependencies are complete
Q: Permission issues
A:
- Linux/macOS: Use
sudoor install to user directory - Windows: Run Command Prompt as administrator
Q: Multiple Perl versions coexisting
A: Use perlbrew to manage multiple Perl versions:
Summary
After completing this chapter, you should have:
- ✅ Successfully installed Perl on your system
- ✅ Configured the development environment
- ✅ Installed necessary tools and modules
- ✅ Able to run Perl scripts
Next, we will learn Perl Basic Syntax.