To install the DateTime
module in Perl, you have a few options depending on your system setup. I’ll outline the most reliable and professional methods, starting from the most standard approach.
1. Using CPAN (Perl’s built-in module manager)
This is the canonical method. Run the following command in your shell:
perl -MCPAN -e 'install DateTime'
If you haven’t configured CPAN before, it will walk you through an initial setup (you can accept defaults if unsure).
After installation, test it with:
perl -MDateTime -e 'print DateTime->now, "\n";'
If it prints a timestamp, it’s installed correctly.
2. Using cpanm
(Recommended for developers)
If you have or can install App::cpanminus, this is a cleaner and faster method:
cpanm DateTime
If cpanm
is not yet installed, install it first:
perl -MCPAN -e 'install App::cpanminus'
Then repeat:
cpanm DateTime
This approach is script-friendly and avoids the verbose CPAN shell.
3. Using your system package manager (less flexible)
If you’re on FreeBSD, Debian, or Red Hat, you can often install DateTime
through system packages:
-
FreeBSD:
pkg install p5-DateTime
-
Debian/Ubuntu:
sudo apt install libdatetime-perl
-
Red Hat/CentOS/Fedora:
sudo dnf install perl-DateTime
However, this version may lag behind CPAN.
4. Manual Installation (only if all else fails)
You can fetch it manually:
wget https://cpan.metacpan.org/authors/id/D/DR/DROLSKY/DateTime-*.tar.gz
tar xzf DateTime-*.tar.gz
cd DateTime-*
perl Makefile.PL
make
make test
sudo make install
⚙️ Dependencies
DateTime
depends on:
-
DateTime::Locale
-
DateTime::TimeZone
-
Params::Validate
cpanm
or CPAN will handle these automatically.
Would you like me to show you how to bundle it locally (e.g., without root privileges, for a custom Perl environment)? That’s often necessary on shared or restricted systems.