While installing a new Ubuntu server on Linode for a client using the “Stackscripts for Ruby 1.9.2, Passenger, Nginx, Rails, and MySQL”, I ran into an issue with bundler unable to install a few gems, notably mislav/will_paginate and collectiveidea/delayed_job. The gemspecs files of these particular gems have UTF-8 characters, and rubygems barks with the following errors:
Using will_paginate (3.0.pre3) from https://github.com/mislav/will_paginate.git (at rails3) /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:724:in `gsub': invalid byte sequence in US-ASCII (ArgumentError)
It turned out that for the default LANG environment variable wasn’t set by default. If you run
$ locale
you’d see something similar to this
LANG=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
Notice that the $LANG variable is empty. Since ruby relies on the LANG to pick out the correct encoding, it got confused when trying to process the gemspecs containing the UTF-8 characters. To fix this issue, you can set the LANG option system-wise by adding 1 more line to your /etc/environment file. Just run this 1-liner and you’ll be all set.
$ sudo echo LANG=en_US.UTF-8 >> /etc/environment
Now the LANG will be set for your system, and thus will be passed to your ruby and passenger environment properly.
Here’s the updated version of the stackscript: http://www.linode.com/stackscripts/view/?StackScriptID=2166