2

I am trying to use the prawn gem. I am just trying out the basic hello world example, on an ubuntu machine.

require 'prawn'
Prawn::Document.generate("hello.pdf") do
text "Hello World!"
end

First problem was that I was using ruby 1.9.1, it produced an error and said it needed ruby 2.0, so using RVM I updated to 2.2.1. However everytime I run this, I get this error

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- prawn (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:inrequire' from prawnpdf.rb:1:in `'

Now I am bit a newbie with Ubuntu and ruby for that matter, but I assume the issue is that it is looking in the wrong place for the prawn gem which I have installed ie it is looking in the old verison of ruby.

When I run $ ruby -v I get

ruby 2.2.1p85 (2015-02-26 revision 49769) [i686-linux]

what am I doing wrong? any help would be most appreicated.

shivam
  • 16,048
  • 3
  • 56
  • 71
D133p53
  • 59
  • 7
  • did you try reinstalling prawn in your new Ruby? – shivam Mar 07 '16 at 06:56
  • I did try and reinstall prawn. This is what I did previously gem install prawn Successfully installed prawn-2.1.0 Parsing documentation for prawn-2.1.0 Done installing documentation for prawn after 2 seconds 1 gem installed – D133p53 Mar 07 '16 at 07:01
  • also tried rvm all do gem install prawn – D133p53 Mar 07 '16 at 07:02
  • Try to reinstall `rvm` http://stackoverflow.com/a/34523631/3098330 – Gupta Mar 07 '16 at 10:52

3 Answers3

0

Each time you switch ruby versions with rvm, you start using a new gemset. Having previously installed prawn doesn't mean it is currently installed, and the error message suggests it's not installed. So:

rvm use 2.2.1

and then

gem install prawn

Then your code should work.

Stephen Grimes
  • 398
  • 1
  • 7
  • `rvm use 2.2.1 --default` makes more sense for this particular case. – Aleksei Matiushkin Mar 07 '16 at 07:27
  • @StephenGrimes you are right it looks if it isn't installed, I have previous used the command rvm use 2.2.1 as well as rvm use 2.2.`1 --default – D133p53 Mar 07 '16 at 08:42
  • Be careful if you are changing directories after the gem install or rvm command. That could effect the ruby version. – Stephen Grimes Mar 07 '16 at 08:44
  • @StephenGrimes you were right on the money. I foolishly was using sudo gem install, not just gem install. Here is a paragraph from the rvm website - When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo. Thanks for your help. – D133p53 Mar 11 '16 at 02:13
0

I suggest you create a Gemfile for your project so it becomes easier to maintain the dependencies. See details: http://bundler.io/

Then cd into your project directory and install the bundle (once or after changes) and run your ruby script:

cd my_project
bundle install
ruby my_thing.rb

If you cannot/don't want to use bundler: you need to reinstall the Gem for every ruby.

Pascal
  • 8,464
  • 1
  • 20
  • 31
0

Follow the given step.

1: rvm list

rvm rubies

   ruby-2.0.0-p643 [ x86_64 ]
   ruby-2.2.1 [ x86_64 ]
=* ruby-2.2.4 [ x86_64 ]

2: rvm use < ruby-version > # for instances ruby-1.9.3-p125

rvm use 2.2.1

3: gem install prawn

Would work !!!

Gupta
  • 8,882
  • 4
  • 49
  • 59
  • I would have thought that it would have worked too $ rvm list rubies rvm rubies ruby-2.1.1 [ i686 ] =* ruby-2.2.1 [ i686 ] # => - current # =* - current && default # * - default rvm use 2.2.1 gem install prawn Successfully installed prawn-2.1.0 Parsing documentation for prawn-2.1.0 Done installing documentation for prawn after 2 seconds 1 gem installed But still the same error thanks for the idea though – D133p53 Mar 07 '16 at 08:36
  • @D133p53: I think so, But have my answer work for you ? – Gupta Mar 07 '16 at 08:40
  • @D133p53L: Once you install `prawn gem` close the `Terminal` and try with `New Terminal`. – Gupta Mar 07 '16 at 08:46
  • No sorry Vinay it didn't work, I have tried new terminal. – D133p53 Mar 07 '16 at 10:04
  • Go to Terminal => Edit => Profile Preference => Under Title and Command menu look for option, Run Command as login shell option" "Do Checked ". – Gupta Mar 07 '16 at 10:11
  • I had tried that, tried again without much luck. I have noticed that rvm has installed ruby 2.2.1 in a different location than ruby 1.9.1, /home/hamish/.rvm/gems/ruby-2.2.1/ vs /usr/lib/ruby/1.9.1/ do you think this has any bearing on my problem? – D133p53 Mar 07 '16 at 10:49
  • Vinay, your solution was correct but I was too dense to see it. Just out of habit I put sudo gem install prawn, not gem install prawn. As soon as I did exactly what you were saying it worked. Thanks for your patience, your were 100% right. – D133p53 Mar 11 '16 at 02:15