Last updated on July 8, 2020 by Dan Nanni
If you want to detect Linux distribution within a Perl script, you can use a Perl module named Linux::Distribution. This module guesses the underlying Linux operating system by examining /etc/lsb-release
, and other distro-specific files under /etc
directory. It supports detecting all major Linux distributions, including Fedora, CentOS, Arch Linux, Debian, Ubuntu, SuSe, Red Hat, Gentoo, Slackware, Knoppix, and Mandrake.
To use this module in a Perl program, you need to install it first.
Linux::Distribution
Perl module on Debian or UbuntuInstallation on Debian-based system is straightforward with apt-get
:
$ sudo apt-get install liblinux-distribution-packages-perl
If Linux::Distribution
module is not available as a package in your Linux (such as on Red Hat based systems), you can use CPAN to build/install it.
First, make sure that you have CPAN installed on your Linux system:
$ sudo yum -y install perl-CPAN
Then use this command to build and install the module:
$ sudo perl -MCPAN -e 'install Linux::Distribution'
Once Linux::Distribution module is installed, you can use the following code snippet to identify on which Linux distribution you are running.
use Linux::Distribution qw(distribution_name distribution_version); my $linux = Linux::Distribution->new; if ($linux) { my $distro = $linux->distribution_name(); my $version = $linux->distribution_version(); print "Distro: $distro $versionn"; } else { print "Distro: unknownn"; }
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean