Install Perl on FreeBSD

Contents
Perl in the base system
A newer Perl from packages
Modules and cpanm
perlbrew in a home folder

Perl in the base system

FreeBSD includes Perl in the base system, because the ports tree and several system scripts are written in it. There is nothing to install to start the course:

perl -v

This is perl 5, version 36, subversion 3 (v5.36.3) built for amd64-freebsd-thread-multi

The base Perl belongs to the release, and the project keeps it stable rather than current. That makes it a dependable target — and it means the version will not move until you upgrade FreeBSD itself.

A newer Perl from packages

The ports collection carries a current Perl as perl5. It installs beside the base one, with a versioned name, so nothing that ships with the system breaks:

sudo pkg install perl5

perl5.40 -v

This is perl 5, version 40, subversion 0 (v5.40.0) built for amd64-freebsd-thread-multi

To make the new one the default for your shell, put its folder first in PATH or create a symlink in /usr/local/bin. Check with which -a perl that you know every copy the shell can see.

Modules and cpanm

FreeBSD packages CPAN modules with a p5- prefix. Install the ones this course uses from packages, and they arrive compiled and tracked by the package manager:

sudo pkg install p5-JSON-PP p5-Text-CSV

For modules that are not packaged, install cpanm. The package is called p5-App-cpanminus:

sudo pkg install p5-App-cpanminus

cpanm HTTP::Tiny

A package install puts modules in the system Perl, which is fine on a personal machine. On a server, keep project modules in a local library so a package upgrade cannot change the code your application loads.

perlbrew in a home folder

For a Perl that is neither the base one nor the packaged one, perlbrew builds any release under your home folder. It needs the compiler and the GNU toolchain:

sudo pkg install gmake gcc

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

perlbrew install perl-5.40.0

The installer prints a line for your shell profile. After a new login, perlbrew switch perl-5.40.0 makes that build the default for everything the shell starts.

Inside a jail, perlbrew works the same way, but the build tools must be installed in the jail. For a throwaway environment, the Perl in Docker page is faster than a fresh jail — the image already contains a complete Perl and cpanm.

Next: Perl in Docker

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: