Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get OS and OS ARCH information in Ruby?

Tags:

ruby

In Ruby script, I want to get OS information, not only Linux, but also 32bit or 64bit.

That's because my program will run on multiple Linux platform. It calls a third part tool, the tool has sub-folder: lin32, lin64, I need to call proper version based on OS info.

like image 992
TieDad Avatar asked Oct 20 '25 05:10

TieDad


2 Answers

In Ruby you can use RUBY_PLATFORM constant. This constant produces a base name of your OS and kernel bits level. E.g. in irb:

1.9.3-p392 :001 > RUBY_PLATFORM
=> "x86_64-linux" - Linux based OS with 64-bit
=> "i686-linux" - Linux based OS with 32-bit
like image 132
Alexander Shlenchack Avatar answered Oct 21 '25 18:10

Alexander Shlenchack


Also, you can try someth like:

ver = `getconf LONG_BIT`

or

ver = `arch`
like image 25
Alex Holubenko Avatar answered Oct 21 '25 17:10

Alex Holubenko