Nokogiri をWindowsに入れる場合のエラーについて

環境

症状

Nokogiri のgemをインストールしようとすると、

gem install nokogiri

以下のように変換できない文字があってエラーが発生する。

Fetching: nokogiri-1.5.5-x86-mingw32.gem (100%)
Successfully installed nokogiri-1.5.5-x86-mingw32
1 gem installed
Installing ri documentation for nokogiri-1.5.5-x86-mingw32...
unable to convert "\xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.ja.rdoc, skipping
unable to convert "\xE8" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.rdoc, skipping
unable to convert "\xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.ja.rdoc, skipping
unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for ext/nokogiri/xml_node_set.c, skipping
Installing RDoc documentation for nokogiri-1.5.5-x86-mingw32...
unable to convert "\xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.ja.rdoc, skipping
unable to convert "\xE8" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.rdoc, skipping
unable to convert "\xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.ja.rdoc, skipping
unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for ext/nokogiri/xml_node_set.c, skipping

対処

gem コマンドの実行前に、コマンドプロンプトのコードページをUTF-8に変更しておく。

chcp 65001
gem install nokogiri

これで、上のようにエラーが出ていたファイルも正しく変換される。ファイルがUTF-8になってしまうがたぶんHTMLだけなので問題ない。