Skip to content
Daniel Berger edited this page Sep 7, 2022 · 6 revisions

Description

The sys-uname library is a Ruby interface for getting operating system information. The name comes from the Unix 'uname' command, but this library works on MS Windows as well.

Installation

gem install sys-uname

If you're on MS Windows, and the above doesn't work try:

gem install sys-uname --platform universal-mingw32

Synopsis

require 'sys/uname'
include Sys

p Uname.uname # => Display everything

puts Uname.sysname  # => The operating system name. e.g. "SunOS"
puts Uname.nodename # => This is usually, but not necessarily, the same as the system's hostname.
puts Uname.machine  # => The machine hardware type. e.g. "i686"
puts Uname.version  # => The operating system version. e.g. "5.8". Windows includes patch information.
puts Uname.release  # => The operating system release. e.g. "2.2.16-3"

Solaris Only

puts Uname.architecture     # => Returns the instruction set architecture. e.g. "sparc"
puts Uname.platform         # => The platform identifier. e.g. "SUNW,Sun-Blade-100"
puts Uname.isa_list         # => List of supported instr. sets, e.g. "amd64 pentium_pro+mmx pentium_pro"
puts Uname.hw_provider      # => The name of the hardware manufacturer.
puts Uname.hw_serial_number # => The hardware serial number
puts Uname.srpc_domain      # => The name of the Secure Remote Procedure Call domain, if any.
puts Uname.dhcp_cache       # => The boot(1M) interface encoding, in hexidecimal format.

Note that future versions of this library may drop Solaris support since it is all but dead at this point.

HP-UX Only

puts Uname.id_number # => OS identification number

See the doc/uname.rdoc file for more detailed descriptions of some of these fields.

Platform

require 'sys/uname' # NOT 'sys/platform'
include Sys

# On my local Mac
puts Platform::ARCH # => x86_64
puts Platform::OS   # => :unix
puts Platform::IMPL # => :macosx

puts Platform.windows? # => false
puts Platform.unix?    # => true
puts Platform.mac?     # => true
puts Platform.linux?   # => false
puts Platform.solaris? # => false
puts Platform.bsd?     # => false (no, Macs don't count)
Clone this wiki locally