How to specify a higher ruby version for installing a gem?

11,188

Solution 1

You may wish to consider using a ruby package manager like rvm or rbenv

You can install different rubies and switch between them easily.

You might also want to consider trying 2.0+

Sample output from rvm:

21:59:48 durrantm Castle2012 /home/durrantm 
$ rvm list

rvm rubies

   ruby-1.8.7-p374 [ x86_64 ]
   ruby-1.9.3-p125 [ x86_64 ]
   ruby-1.9.3-p194 [ x86_64 ]
   ruby-1.9.3-p448 [ x86_64 ]
   ruby-2.0.0-p195 [ x86_64 ]
=* ruby-2.0.0-p247 [ x86_64 ]
   ruby-2.0.0-p481 [ x86_64 ]
   ruby-2.1.1 [ x86_64 ]
   ruby-2.1.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

21:59:50 durrantm Castle2012 /home/durrantm 
$ rvm use 2.0.0
Using /home/durrantm/.rvm/gems/ruby-2.0.0-p481

$ rvm use 2.1.1
Using /home/durrantm/.rvm/gems/ruby-2.1.1

$ rvm use 1.9.3
ruby-1.9.3-p547 is not installed.

$ rvm use 1.9.3-p448
Using /home/durrantm/.rvm/gems/ruby-1.9.3-p448

Get rvm at http://rvm.io/

Install with its famous 1 liner:

$ \curl -sSL https://get.rvm.io | bash -s stable

Solution 2

Install RVM and use the following:

rvm install 1.9.3
rvm use 1.9.3 --default
gem install pdfbeads  # Avoid sudo, will not fix real problems here.
Share:
11,188

Related videos on Youtube

Tim
Author by

Tim

Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.

Updated on September 18, 2022

Comments

  • Tim
    Tim over 1 year

    I install a ruby package.

    $ sudo gem install pdfbeads
    ERROR:  Error installing pdfbeads:
        nokogiri requires Ruby version >= 1.9.2.
    

    says that it needs ruby version greater than 1.9.1.

    My ruby is 1.8.7.

    $ which ruby
    /usr/bin/ruby
    $ ruby --version
    ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
    $ gem --version
    1.8.15
    

    I have ruby 1.9.1 and 1.9.3.

    $ whereis ruby1.9.1
    ruby1.9: /usr/bin/ruby1.9.1 /usr/bin/ruby1.9.3 /usr/bin/X11/ruby1.9.1 /usr/bin/X11/ruby1.9.3
    

    but 1.9.3 is linked to 1.9.1.

    $ ls /usr/bin/ruby* -l
    lrwxrwxrwx 1 root root   22 Jul 10 02:33 /usr/bin/ruby -> /etc/alternatives/ruby
    -rwxr-xr-x 1 root root 5504 Nov 26  2013 /usr/bin/ruby1.8
    -rwxr-xr-x 1 root root 5552 Nov 26  2013 /usr/bin/ruby1.9.1
    lrwxrwxrwx 1 root root    9 Nov 26  2013 /usr/bin/ruby1.9.3 -> ruby1.9.1
    

    It says itself is 1.9.3 however:

    $  /usr/bin/ruby1.9.3 --version
    ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]
    

    I change the link to ruby1.9.3 anyway

    $ ls -l /usr/bin/ruby*
    lrwxrwxrwx 1 root root    9 Aug 20 21:16 /usr/bin/ruby -> ruby1.9.3
    -rwxr-xr-x 1 root root 5504 Nov 26  2013 /usr/bin/ruby1.8
    -rwxr-xr-x 1 root root 5552 Nov 26  2013 /usr/bin/ruby1.9.1
    lrwxrwxrwx 1 root root    9 Nov 26  2013 /usr/bin/ruby1.9.3 -> ruby1.9.1
    

    The installation still says it needs ruby >= 1.9.2

    $ sudo gem install pdfbeads
    ERROR:  Error installing pdfbeads:
        nokogiri requires Ruby version >= 1.9.2.
    $ gem --version
    1.8.15
    $ ruby --version
    ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]
    

    Do I have ruby1.9.3 or just ruby1.9.1?

    How can I make sudo gem install pdfbeads use ruby 1.9.3?


    Update:

    I have now followed the way of installing ruby 2.1.0 by RVM, I have added the path of rvm to my PATH. I then successfully installed ruby2.1.0 by

    $ rvm install 2.1.0
    

    and made it default

    $ rvm use 2.1.0
    
    $ ruby -v
    ruby 2.1.0p0 (2013-12-25 revision 44422) [i686-linux]
    $ which ruby
    /home/tim/.rvm/rubies/ruby-2.1.0/bin/ruby
    

    Now back to install the package pdfbeads, but without sudo (because I thought I had installed ruby 2.1.0 under my account, not under root, and installation of the package requires the newer version ruby)

    $ gem install pdfbeads
    ERROR:  While executing gem ... (Gem::FilePermissionError)
        You don't have write permissions into the /var/lib/gems/1.8 directory.
    

    So I think I have to use sudo. But I still get the original error,

    $ sudo gem install pdfbeads
    
    ERROR:  Error installing pdfbeads:
        nokogiri requires Ruby version >= 1.9.2.
    

    I think it is because under sudo, the user is root, which still has the older version ruby1.8.7 as the default. So I wonder what can I do now?

    • cuonglm
      cuonglm over 9 years
      Is rvm path is in root's PATH?
    • Tim
      Tim over 9 years
      rvm is in $PATH. I am not sure what you mean by "root's PATH". are there other's PATH?
    • cuonglm
      cuonglm over 9 years
      I mean PATH when you are root.
    • Tim
      Tim over 9 years
      It is not. Will it work if I switch to root, and add rvm path to the root's PATH by PATH=$PATH:/home/tim/.rvm/bin? I will have to switch back to my account, and install pdfbeads.
    • Tim
      Tim over 9 years
      Shall I install rvm and ruby under the home of the root?
    • slm
      slm over 9 years
      Confirm you're using the gem from one of your rvm rubies. type gem.
    • Michael Durrant
      Michael Durrant over 9 years
      Also make sure that the rvm line is the LAST line of your .bashrc The line is: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    • Tim
      Tim over 9 years
      @MichaelDurrantn (1) without sudo, You don't have write permissions into the /var/lib/gems/1.8 directory. Do you suggest using sudo or not? (2) Why "make sure that the rvm line is the LAST line of your .bashrc"? If in the future I add something to .bashrc, should I append that thing before or after [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"? What if everything wants to be at the end of the .bashrc?
  • Tim
    Tim over 9 years
    Thanks. I am now trying what you suggest. Btw, ruby1.9.3 is a symlink, linking to 1.9.1. Bu why it says itself is 1.9.3?
  • Tim
    Tim over 9 years
    Why is ruby1.9.3 I installed not working?
  • Tim
    Tim over 9 years
    Still get "nokogiri requires Ruby version >= 1.9.2" error, after installing ruby 2.1.0. I update my post at its end.