Ruby-on-rails 在`require'中:没有要加载的文件- iconv (LoadError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7829886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:12:30  来源:igfitidea点击:

in `require': no such file to load -- iconv (LoadError)

ruby-on-railsrubyterminalrvmiconv

提问by Ava

    ?  expertiza git:(master) ? ruby -v
    ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.1.0]
    ?  expertiza git:(master) ? rails -v
    Rails 2.3.14
    ?  expertiza git:(master) ? script/server
/Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/inflector.rb:3:in `require': no such file to load -- iconv (LoadError)
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/inflector.rb:3
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext/integer/inflections.rb:1:in `require'
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext/integer/inflections.rb:1
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext/integer.rb:2:in `require'
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext/integer.rb:2
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext.rb:8:in `require'
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext.rb:8
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext.rb:8:in `each'
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/core_ext.rb:8
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support.rb:56:in `require'
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support.rb:56
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.14/lib/commands/server.rb:1:in `require'
    from /Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.14/lib/commands/server.rb:1
    from script/server:3:in `require'

I have tried installing

我试过安装

rvm pkg install readline
rvm pkg install iconv
rvm install 1.8.7
rvm use 1.8.7 

Even tried Why does installing Nokogiri on Mac OS fail with libiconv is missing?.

甚至尝试过为什么在 Mac OS 上安装 Nokogiri 会失败并且缺少 libiconv?.

Nothing works. Please help!

什么都行不通。请帮忙!

Thanks!

谢谢!

回答by fantaxy025025

It shows that the iconv not exist but the iconv has installed in my production env.

它显示 iconv 不存在,但 iconv 已安装在我的生产环境中。

root@AY130/current# iconv --version
iconv (Ubuntu EGLIBC 2.15-0ubuntu10.4) 2.15
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

To resolve it, add this in your Gemfile:

要解决它,请将其添加到您的 Gemfile 中:

gem "iconv", "~> 1.0.3"

Then run bundle install.

然后运行bundle install

Note: iconv has been deprecated for a while. It is replaced by (builtin) String#encode
See here: https://bbs.archlinux.org/viewtopic.php?id=160369

注意: iconv 已被弃用一段时间。它被(内置)String#encode 替换
见这里:https: //bbs.archlinux.org/viewtopic.php?id=160369

回答by jassa

For those using rbenvinstead of rvm

对于那些使用rbenv而不是 rvm 的人

$ which iconv
$ /usr/local/bin/iconv

Then use the directory location of iconv to reinstall ruby

然后使用iconv的目录位置重新安装ruby

$ CONFIGURE_OPTS="--with-iconv-dir=/usr/local" rbenv install 1.8.7-p358

Good luck

祝你好运

(As a side note, this error has been reported to happen in Ruby 1.8.7-p3xx)

(作为旁注,此错误已报告发生在 Ruby 1.8.7-p3xx 中)