A Linux distribution is a collection of software, usually distinguishable by their package manager, window system, window manager, and desktop environment. That's a lot of interchangeable parts. If a system keeps the package manager, but changes the window system and desktop environment, do we call it a new distribution? There's no definitive answer, so various tools will give slightly different answers.
Train has a whole hierarchy of distribution families and may be the most sophisticated of the bunch. A quick comparison of Train and Ohai is here. It's designed to be run over a network connection, but works fine locally, too, as shown here:
# gem install train
Train.create('local').connection.os[:name] #=> eg. "centos", "linuxmint"
Train.create('local').connection.os[:family] #=> eg. "redhat", "debian"
Facter's osfamily fact returns, eg. "Debian" for Ubuntu. With Facter, the general form for retrieving facts is Facter[factname].value
.
# gem install facter
require 'facter'
puts Facter['osfamily'].value
Ohai's platform
fact returns, eg. "debian" for Ubuntu and "rhel" for CentOS. With Ohai, the general form for retrieving facts is node[factname]
.
# gem install ohai
node['platform'] #=> eg. "ubuntu" or "mint"
node['platform_family'] #=> eg. "debian" for Ubuntu and Mint
Ruby system info libraries which won't distinguish platforms
Platform retrieves some basic data, and can distinguish well between a variety of Unix platforms. However, it doesn't handle different distributions of Linux at all. Platform::IMPL
will return :freebsd, :netbsd, :hpux, etc., but all Linux distros are just :linux. sys-uname and sysinfo are similar. utilinfo is even more basic, and will fail on any systems beyond Windows, Mac, and Linux.