Install Perl on Ubuntu

Contents
Is Perl already there
Install from apt
cpanm and apt modules
perlbrew for newer versions

Is Perl already there

Ubuntu ships Perl because parts of the system use it. Before installing anything, ask what you already have:

perl -v

This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-linux-gnu-thread-multi

If you see a version, you can start the course right now. The minimum for every example is 5.26, and anything newer runs the modern syntax from lesson 49.

Also check where the binary lives. A version installed by hand in /usr/local/bin can shadow the system one, and then two terminals disagree about which Perl they run:

which perl

/usr/bin/perl

Install from apt

The perl package is enough to run scripts, but the documentation and the standard tooling live in separate packages. Refresh the list and install them together:

sudo apt update

sudo apt install perl perl-doc

perl-doc is what makes perldoc perlintro and perldoc -f open work offline. It is a large download, and it pays for itself the first time you need to look up a function signature without a browser.

cpanm and apt modules

Ubuntu packages many CPAN modules with a lib...-perl name. Installing them with apt keeps them updated by the system, which is convenient on a server:

sudo apt install libjson-pp-perl libtext-csv-perl

For anything not packaged, use cpanm. Install it once from apt, then it manages modules in the usual CPAN way:

sudo apt install cpanminus

cpanm HTTP::Tiny

Running cpanm with sudo installs into the system Perl, which mixes your modules with the distribution's. Prefer a local library for project work, as lesson 32 shows, and keep the system Perl for system scripts.

perlbrew for newer versions

The Perl in the Ubuntu release is frozen when the release ships. When you need a newer one, perlbrew builds it in your home folder and leaves the system copy untouched:

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

The installer prints one line to add to your shell profile. After a new shell, build and switch:

perlbrew install perl-5.40.0

perlbrew switch perl-5.40.0

Building takes a few minutes and needs a compiler and the development headers. If the build fails at the first step, install build-essential and try again.

One caution: scripts that start with #!/usr/bin/perl keep using the system Perl even when your shell prefers the perlbrew one. For a shebang that follows your choice, use #!/usr/bin/env perl.

Next: Install Perl on Rocky Linux

Article author: Arthur Isaev

Related articles
Perl
Perl course: zero to hero in 50 lessons
What is Perl and where it runs
Install Perl and check the version
Your first Perl script
The debugger as a REPL
Scalars and sigils
Numbers
Strings
Interpolation and quoting
Arrays
push, pop, shift and splice
Hashes
keys, values, exists and delete
Scalar and list context
Conditions and comparison
while, for, next and last
foreach and the default variable
Subroutines
Arguments in @_
References
Nested data structures
Regular expressions: match and anchors
Captures and named groups
Substitution with s///
split and join
grep and map
Sort and the Schwartzian transform
Read and write files
File tests and metadata
Directories and paths
die, warn and eval
Modules and Exporter
CPAN and cpanm
Objects with bless
Modern objects with Moo
Testing with Test::More
strict, warnings and diagnostics
Options with Getopt::Long
Environment and %ENV
system, backticks and pipes
One-liners with -n and -p
CSV and TSV processing
JSON with JSON::PP
HTTP clients with HTTP::Tiny
Sockets and IO::Socket
Databases with DBI
Capstone: todo CLI
Capstone: log report
Performance and profiling
Modern Perl tour
Hero roadmap: the whole course on one page
Install Perl on Windows 11
Install Perl on Ubuntu
Install Perl on Rocky Linux
Install Perl on macOS
Install Perl on FreeBSD
Perl in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: