ubuntu上的`gem install`给出了无效的字节序列错误

时间:2014-02-24 09:29:09

标签: ruby ubuntu debian rvm

我使用RVM在Ubuntu(Debian)上安装Ruby。我可以使用irb并运行ruby脚本。

但是,当我尝试安装任何 gem时,我收到此错误:

ERROR:  While executing gem ... (ArgumentError)
    invalid byte sequence in UTF-8

当我为gem使用任何值时也会发生这种情况,例如gem install garbage

Ruby 1.9.3和2.0都会发生这种情况。

以下是命令locale报告的内容:

LANG=en_US.UTF-8
LANGUAGE=en_SG:en
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=en_US.UTF-8

这是跟踪:

ERROR:  While executing gem ... (ArgumentError)
invalid byte sequence in UTF-8
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:862:in `sub!'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:862:in `block (2 levels) in parse_resolv_conf'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:861:in `each'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:861:in `block in parse_resolv_conf'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:860:in `open'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:860:in `parse_resolv_conf'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:892:in `default_config_hash'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:913:in `block in lazy_initialize'
<internal:prelude>:10:in `synchronize'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:906:in `lazy_initialize'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:342:in `block in lazy_initialize'
<internal:prelude>:10:in `synchronize'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:340:in `lazy_initialize'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:494:in `each_resource'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb:475:in `getresource'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/remote_fetcher.rb:88:in `api_endpoint'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/source.rb:42:in `api_uri'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/source.rb:170:in `load_specs'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/spec_fetcher.rb:266:in `tuples_for'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/spec_fetcher.rb:226:in `block in available_specs'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/source_list.rb:97:in `each'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/source_list.rb:97:in `each_source'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/spec_fetcher.rb:222:in `available_specs'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/spec_fetcher.rb:102:in `search_for_dependency'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:216:in `find_gems_with_sources'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:292:in `find_spec_by_name_and_version'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:166:in `available_set_for'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:418:in `resolve_dependencies'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:371:in `install'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/commands/install_command.rb:219:in `install_gem'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/commands/install_command.rb:263:in `block in install_gems'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/commands/install_command.rb:259:in `each'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/commands/install_command.rb:259:in `install_gems'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/commands/install_command.rb:171:in `execute'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/command.rb:305:in `invoke_with_build_args'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/command_manager.rb:167:in `process_args'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/command_manager.rb:137:in `run'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:54:in `run'
/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/bin/gem:21:in `<main>'

2 个答案:

答案 0 :(得分:1)

〜/ .gemrc

中启用回溯
---
backtrace: true

进行安装,并提供跟踪日志。

根据跟踪日志,似乎ruby安装中的某些内容无效。它需要自己调试。只需打开文件即可。 {8}行上的/home/crazybob/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/resolv.rb,在插入行puts str.encodingputs str.inspect之前,或类似的行,以查看引发错误的String。< / p>

还尝试重新安装,或使用安装最新版本。

答案 1 :(得分:1)

我的 /etc/resolv.conf 有一些二进制垃圾,导致了这个问题。不确定,为什么 resolv.conf 有这个数据。