Install Perl on Rocky Linux
| What Rocky ships | |
| Install with dnf | |
| Modules and cpanm | |
| Newer Perl with perlbrew |
What Rocky ships
Rocky Linux, like every RHEL clone, includes Perl because the system tools need it. The base install is a single release line that receives security fixes but no new features.
perl -v
This is perl 5, version 32, subversion 1 (v5.32.1) built for x86_64-linux-thread-multi
5.32 is old enough to miss subroutine signatures, so lesson 49 will not compile on it. Everything else in the course runs. If you want the modern line, skip to the perlbrew section at the end.
Install with dnf
The interpreter is usually present, but the documentation and the command line tools may not be. Install the base package and the utilities together:
sudo dnf install perl perl-utils
perl-utils brings perldoc, which turns every core module into searchable documentation. Check that it works before you need it:
perldoc -f open
open FILEHANDLE,EXPR open FILEHANDLE,MODE,EXPR open FILEHANDLE,MODE,EXPR,LIST
Modules and cpanm
RPM packages for CPAN modules follow a naming rule: perl-JSON-PP for JSON::PP, perl-Text-CSV for Text::CSV. dnf also resolves the virtual name, which is easier to read:
sudo dnf install 'perl(JSON::PP)' 'perl(Text::CSV)'
cpanm is not in the base repositories. Enable EPEL and install it from there, or bootstrap it with the one-line installer if you prefer not to add a repository:
sudo dnf install epel-release
sudo dnf install perl-App-cpanminus
Once it is in place, cpanm --installdeps . reads a cpanfile and installs everything a project needs. That is the same command you would run on any other Linux.
Newer Perl with perlbrew
Building a newer Perl needs the compiler and the development libraries. Install them first, then perlbrew:
sudo dnf groupinstall 'Development Tools'
curl -L https://install.perlbrew.pl | bash
Add the line the installer prints to ~/.bashrc, open a new shell, and build the release you want:
perlbrew install perl-5.40.0
perlbrew switch perl-5.40.0
The build takes several minutes on a small VM. If it fails while linking, the usual cause is a missing libxcrypt-devel or an old gcc; the log names the missing piece.
Keep the shebang portable with #!/usr/bin/env perl so scripts follow the Perl your shell finds, not the one in /usr/bin.
Next: Install Perl on macOS
Article author: Arthur Isaev