Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Environment Variables

Tags:

ruby

I am experiencing a strange problem with Ruby and Environment variables.

I am currently on a x64 machine running Windows Server 2008 R2

If I do the following in ruby: puts ENV['PROCESSOR_ARCHITECTURE']

I expect to see AMD64, however, Ruby is displaying x86

If I do: echo %PROCESSOR_ARCHITECTURE%, in the command prompt, I am greeted with AMD64

My Ruby version is: ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]

As far as I am aware, ENV['PROCESSOR_ARCHITECTURE'] should just read my environment variable...

Any ideas?

Cheers, Gareth

like image 319
Gareth Williams Avatar asked Aug 09 '10 15:08

Gareth Williams


People also ask

Where are Ruby environment variables stored?

You store separate environment variables in config/development. rb , config/testing. rb and config/production. rb respectively.

How do you use environment variables in Ruby on Rails?

How to Set Environment Variables. You can set an environment variable for a one time use. Use this in a terminal, outside of irb, then Ruby will have access to this API_KEY value. This is helpful for API keys, but also to set Rails mode.

What is .ENV file Ruby?

.env file is meant for use in development and test environments.


1 Answers

It does read your environment variable, but since your ruby executable is compiled for 32-bit, it runs in a 32-bit environment where the value of PROCESSOR_ARCHITECTURE is indeed "x86".

If you put system "echo %PROCESSOR_ARCHITECTURE%" in your ruby script, you will see that it will also output "x86".

like image 165
sepp2k Avatar answered Nov 12 '22 19:11

sepp2k