0

I installed ruby 2.2.0 on Ubuntu 64-bit 14.04 to my home following https://railssavvy.wordpress.com/2012/06/02/install_ruby_and_rails/, and then installed a package called pdfbeads. When I run the package, I have this error:

$ /home/t/.rvm/gems/ruby-2.2.0/wrappers/pdfbeads -o all.pdf
/home/t/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- iconv (LoadError)
    from /home/t/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/t/.rvm/gems/ruby-2.2.0/gems/pdfbeads-1.1.1/bin/pdfbeads:35:in `<top (required)>'
    from /home/t/.rvm/gems/ruby-2.2.0/bin/pdfbeads:23:in `load'
    from /home/t/.rvm/gems/ruby-2.2.0/bin/pdfbeads:23:in `<main>'
    from /home/t/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
    from /home/t/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'

To solve the problem, I followed this reply https://stackoverflow.com/a/19332909/156458,

$ which iconv
/usr/bin/iconv

$ iconv --version
iconv (Ubuntu EGLIBC 2.19-0ubuntu6.6) 2.19
Copyright (C) 2014 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.

$ gem "iconv", "~> 1.0.3"
ERROR:  While executing gem ... (Gem::CommandLineError)
    Unknown command iconv,

So what happens to ruby and iconv? What shall I do now? Many thanks!


I have installed both 2.1.0 and 2.0.0 and pdfbeads under them respectively. But when I run pdfbeads located under their wrappers directories, I still have the same error:

in `require': cannot load such file -- iconv (LoadError)
Community
  • 1
  • 1
Tim
  • 1
  • 141
  • 372
  • 590

2 Answers2

3

This error:

ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- iconv (LoadError)

says that the ruby Standard Library module iconv cannot be found. That's because iconv no longer exists in ruby's Standard Library in ruby 2.2.

The line:

gem "iconv", "~> 1.0.3"

is supposed to go in a Gemfile, which is a file that is created when you create a rails project. In a rails project, you install all the gems listed in your Gemfile using Bundler, e.g.:

$ bundle install
7stud
  • 46,922
  • 14
  • 101
  • 127
  • Thanks. Does `pdfbeads` still depends on `iconv`? Is `iconv` it needs different from `/usr/bin/iconv`? How can I put `gem "iconv", "~> 1.0.3"` in my Gemfile? I didn't create a rails project, I think? I only installed a package called `pdfbeads`. Where shall I run `bundle install`? – Tim Mar 23 '15 at 00:29
  • *is iconv it needs different from /usr/bin/iconv* -- Yes. Your system has a command called iconv, which is not the same thing as a module in ruby's Standard Library. You system has no idea that ruby has even been invented. Whoever wrote the iconv module in ruby's Standard Library was obviously familiar with the Unix command iconv, and named the ruby module with the same name. – 7stud Mar 23 '15 at 00:34
  • Under which directory, shall I run `bundle install`? I got the error `Could not locate Gemfile or .bundle/ directory` when I run it. – Tim Mar 23 '15 at 00:36
  • I am not sure why you are following rails instructions to use pdfbeads. pdfbeads was written a long time ago, and it relies on ruby having a module called iconv in the ruby Standard Library, so if you want to use the pdfbeads module, you will need to install an old version of ruby, e.g. ruby 1.9.3. – 7stud Mar 23 '15 at 00:38
  • The latest pdfbeads is 1.1.1 - January 30, 2014. is it not so long ago? – Tim Mar 23 '15 at 00:39
  • Actually, you can install ruby 2.0 if you want to use pdfbeads. – 7stud Mar 23 '15 at 00:42
  • Thanks. How did you find ruby 2.0 out? – Tim Mar 23 '15 at 00:44
  • I looked at the ruby 2.0.0 Standard Library, and it has the iconv module. See here: http://ruby-doc.org/stdlib-2.0.0/ – 7stud Mar 23 '15 at 00:44
  • *The latest pdfbeads is 1.1.1 - January 30, 2014. is it not so long ago?* Let me see if I can install it with ruby 2.2. – 7stud Mar 23 '15 at 00:48
  • I have installed both ruby 2.0.0 and 2.1.0, and when I run pdfbeads, it always say `in `require': cannot load such file -- iconv (LoadError)`. What shall I do? – Tim Mar 23 '15 at 01:27
  • I installed 1.9.3, and pdfbeads, and when running its pdfbeads, it seems no problem now. But isn't `iconv` in 2.0.0 ? Last year, I installed pdfbeads on 2.1.0, and it rans well. Why does it not work on 2.0.0 and on 2.1.0 this time? – Tim Mar 23 '15 at 01:48
  • @Tim, When I run the following program: `require 'iconv'` in ruby 2.0, I get the error you get. In ruby 1.9.3, I get a warning: `'require': iconv will be deprecated in the future, use String#encode instead.` I was unable to install pdfbeads in ruby 2.2 because I couldn't install imagemagik. *The latest pdfbeads is 1.1.1 - January 30, 2014. is it not so long ago?* No it isn't. Maybe you should try emailing the author. – 7stud Mar 23 '15 at 05:40
1
gem install iconv

fixed the issue for me

maxfowler
  • 1,168
  • 13
  • 23