How to fix the iconv require error in Ruby 1.9
Posted by Marcus Wyatt on 3 February 2010
So you’re trying out the pre-release version of Rails 3.0 with Ruby 1.9 and you keep on getting the following error:
activesupport-3.0.pre/lib/active_support/inflector/transliterate.rb:2:in `require’: no such file to load – iconv (LoadError)
If you are using rvm to install and switch between different versions of ruby then follow the following steps:
- Install readline using rvm:
rvm install readlinervm package install readline - Now install iconv by executing:
rvm install iconvrvm package install iconv - if you already have a version of Ruby 1.9 installed, we need to remove it by executing: rvm remove 1.9.1/1.9.2
- The final step is to re-install the version of ruby: rvm install –trace 1.9.2 -C –with-iconv-dir=$HOME/.rvm/us
(If you are having problems with the command, use the pastie that Glenn Rempe posted in the comments. Thanks Glenn)
Now to test that it worked:
- Change to the ruby version you installed: rvm use 1.9.1/1.9.2
- Check you are on the right version of ruby: ruby -v #=> ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0]
- Start a new irb session
- Now you should be able to require ‘iconv’ and get a ‘true’ result
irb(main):001:0> require ‘iconv’
Now you should be good to go!
This entry was posted on 3 February 2010 at 22:07:39 and is filed under Rails, Ruby. Tagged: iconv, rails3.0, ruby1.9. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Glenn Rempe said
This is great, thanks.
However, your blog formatting is destroying the proper command line to issue for installation.
Try : http://pastie.org/808142
This also seems to have addressed a bug I filed with the rails team:
https://rails.lighthouseapp.com/projects/8994/tickets/3552-running-rails-foo-under-ruby-191-fails-w-undefined-method-camelize-for-appstring
Marcus Wyatt said
Hi Glenn,
Yes, i’ve seen the lighthouse ticket. This solution is out there, I just wanted to bring all the info together for the less experienced rails developer. Thanks for pointing out the command gets destroyed by wordpress. I’ve posted late last night while fighting with the exact problem.
Cheers,
Marcus
Shahrier Akram said
Just what I was looking for. Thanks!
Tim Chater said
Thanks for this. I think you mean “rvm package install readline” and “rvm package install iconv”…
Marcus Wyatt said
yes, that is correct. changed some time ago and I’ve not updated the post yet.
Zak Greant said
If you’ve installed RVM as root, don’t forget to update the path to libiconv – it’ll be shown in the output of
rvm package install iconv
and is likely/usr/local/rvm/usr
, which means you’d run:rvm install --trace 1.9.1 -C --with-iconv-dir=/usr/local/rvm/usr
How to fix the iconv require error in Ruby 1.9 and RVM « notes from a coder said
[…] post was copied from exceptions.wordpress.com with minor […]
Jimish said
Thanks but you need to use rvm pkg install readline and rvm pkg install iconv
pkg not package 🙂
Joe Admin said
On HPUX at least I found the error to be related to the path ruby was looking for shared libs. Since libiconv.so comes from the HPUX Porting Center as a depot, the /etc/SHLIB_PATH was not updated to point to the /usr/local/lib/hpux32 location for the libiconv.so files. Once SHLIB_PATH was setup the issue we resolved without recompiling or rebuilding Ruby.