Ruby cannot see NLS_LANG environmental variable

robertrv picture robertrv · May 11, 2012 · Viewed 10k times · Source

I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3).

I've set the NLS_LANG variable in .bash_profile.

[app@box stasis]$ echo $NLS_LANG
en_US.UTF-8
[app@box stasis]$ which ruby
~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby

However when trying to access it via ruby (which the oci8 driver does), it cannot find it:

 1.9.3-p194 :001 > ENV['NLS_LANG']
 => nil 

Accessing other vars seems to work:

 1.9.3-p194 :004 > ENV['USER']
 => "app"

My script shows the following: Warning: NLS_LANG is not set. fallback to US7ASCII.

Thing is I'm running sqlplus from the ruby script (to execute some .sql files), and special characters are all messed up.

How can I get ruby to see the value?

Answer

mpapis picture mpapis · May 11, 2012

You need to export your variables to be available in any applications run (unless they are functions):

export NLS_LANG

or together with setting:

export NLS_LANG=en_US.UTF-8

or as on most systems LANG should be available:

export NLS_LANG=$LANG