问题
I installed RVM and Ruby through Cygwin on Windows 7. I am now trying to install Omega bundle following this guide. The command is
bundle install
Which gives an error 'command not found'. The solution for this is to install bundler via
gem install bundler
But this gives an 'Invalid byte sequence in UTF-8 error'. The solution for this is described in this post. But I don't understand where I should place this snippet.
require 'iconv' unless String.method_defined?(:encode)
if String.method_defined?(:encode)
file_contents.encode!('UTF-8', 'UTF-8', :invalid => :replace)
else
ic = Iconv.new('UTF-8', 'UTF-8//IGNORE')
file_contents = ic.iconv(file_contents)
end
Please explain where to put this code in.
Thank you!
回答1:
I have 64 bit Cygwin, Ruby 2.0.0 and gem 2.4.1 and was experiencing the same issue. gem install ...
, gem update
, everything ended with "ERROR: While executing gem ... (ArgumentError) invalid byte sequence in UTF-8".
I had also all locales set to "en_US.UTF-8".
I have read somewhere that it should help to set LANG
to an empty string or "C.BINARY", but it didn't help. But it was good hint to start experimenting.
Finally I have solved that by setting both LANG
and LC_ALL
to an empty string. All other locale environment variables (LC_CTYPE
etc.) was automatically set to "C.UTF-8" by that, LANG
and LC_ALL
remained empty.
Now gem
is finally working.
UPDATE
It seems that specifically LC_CTYPE
is causing that issue if it's set to UTF-8. So setting it to C.BINARY should help. Other locale environment variables can be set to UTF-8 without affecting it.
export LC_CTYPE=C.BINARY
回答2:
Just set character to something other than UTF-8 of Cygwin
Click left top icon --> Options --> Text --> set "Character set" to something (e.g. GBK)
回答3:
You can try this, it has worked for me:
> $ LANG=C.BINARY gem install bundler
You can find out more information here
来源:https://stackoverflow.com/questions/22039916/ruby-1-9-3-invalid-byte-sequence-in-utf-8-explanation-needed