Install Ruby 1.9.3 with libyaml on CentOS

Ruby 1.9.3-p0 makes psych—the replacement for 1.8.7’s YAML library, Syck—the default YAML parser. Psych is a wrapper around libyaml, so you’re going to need it installed and configured before installing Ruby.

If you install 1.9.3-p0 without libyaml, you’ll see warnings like this:

It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

Installing libyaml

$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ tar xzvf yaml-0.1.4.tar.gz
$ cd yaml-0.1.4
$ ./configure --prefix=/usr/local
$ make
$ make install

Quick review of what’s going on: download and untar the source code, change to the directory and install the package. You may need to sudo the make install command. Your mileage may vary.

Installing Ruby 1.9.3-p0

$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
$ tar xzvf ruby-1.9.3-p0.tar.gz
$ cd ruby-1.9.3-p0
$ ./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
$ make
$ make install

After installing, you can verify that Ruby was installed with ruby -v. It’s also worth trying gem --version to make sure you don’t get any errors regarding psych.

I tried installing libyaml-devel and libyaml from Yum, but couldn’t get ruby installed and recognizing those packages. Out of frustration, I turned to installing libyaml by source and it Just Worked™.


Check out our latest product, Dead Man’s Snitch for monitoring cron, heroku scheduler or any periodic task.

Dead Man's Snitch

bryckbost@gmail.com

Comments

  1. October 31, 2011 at 16:52 PM

    If you don’t want to compile manually rbenv (with ruby-build) takes care of installing libyaml for you too

  2. October 31, 2011 at 19:14 PM

    just a quick note, rvm will install libyaml for you too :)

  3. October 31, 2011 at 19:56 PM

    Haris Amin* & *shapeshed: Great points! I should have pointed out this was for a server which isn’t using rvm or rbenv.

  4. November 01, 2011 at 4:34 AM

    Yup, rvm 1.9.2 installs it https://gist.github.com/1329273#gistcomment-60100

  5. v.ondruch@tiscali.cz
    Vít Ondruch
    November 01, 2011 at 9:18 AM

    You should be able to get installed libyaml from EPEL packages [1]. Also, you should be able to build RPM packages for R1.9.3 from my spec file [2].

    [1] https://admin.fedoraproject.org/pkgdb/acls/name/libyaml
    [2] https://github.com/voxik/ruby.spec

  6. hlogoma@hotmail.com
    Tom
    November 01, 2011 at 20:51 PM

    I get error running ‘make’ and error running ‘make install’ when I use rvm install 1.9.3

    I cannot read the log since I do not understand it, but it is a log tied to the yaml-0.1.4 folder.

    I would like to use RVM since I want to make gemsets and being a newbie it gives me some security …lol

    Any suggestions on how I can let RVM know that ruby 1.9.3 is installed if I install from source using the above.

    Thanks,

    Tom.

  7. November 02, 2011 at 12:28 PM

    @Tom: If you’re using RVM you won’t need to install libyaml from source. RVM will take care of that for you.

    To install Ruby 1.9.3-p0 via RVM run rvm install 1.9.3-p0

  8. hlogoma@hotmail.com
    Tom
    November 02, 2011 at 14:03 PM

    Hi Brian,

    Thanks for your reply to my earlier posting with respect to RVM install 1.93 and the subsequent errors as it tried to install yaml.

    That was the problem …. RVM tried to install Yaml 0.1.4 and in the process it gave me two warnings, one after the other and subsequently it did not install Ruby 1.9.3 even though it indicated that the installation was complete.

    The two warnings were, first “error running ‘make’” and the second was “error running ‘make install’”

    Maybe it is something about my setup …. I have just downloaded Ubuntu 11.10 for windows and I installed GIT and then RVM and they both worked just fine then I thought I would use RVM to install Ruby 1.9.3.

    I removed Ubuntu and now I am about to start all over … any other thoughts on this …. I know each installation is so different … but maybe you see a work around.

    Thanks again,

    Tom.

  9. hlogoma@hotmail.com
    Tom
    November 02, 2011 at 14:25 PM

    Hi Brian,

    Thanks for your reply to my earlier posting with respect to RVM install 1.93 and the subsequent errors as it tried to install yaml.

    That was the problem …. RVM tried to install Yaml 0.1.4 and in the process it gave me two warnings, one after the other and subsequently it did not install Ruby 1.9.3 even though it indicated that the installation was complete.

    The two warnings were, first “error running ‘make’” and the second was “error running ‘make install’”

    Maybe it is something about my setup …. I have just downloaded Ubuntu 11.10 for windows and I installed GIT and then RVM and they both worked just fine then I thought I would use RVM to install Ruby 1.9.3.

    I removed Ubuntu and now I am about to start all over … any other thoughts on this …. I know each installation is so different … but maybe you see a work around.

    Thanks again,

    Tom.

  10. hlogoma@hotmail.com
    Tom
    November 02, 2011 at 19:41 PM

    Hey Brian,
    I found a temporary work-around, that is for some folks it worked, unfortunately for me it did not.

    But if you are interested here is the link:
    https://github.com/wayneeseguin/rvm/issues/553

    Thanks,
    Tom.

  11. hlogoma@hotmail.com
    Tom
    November 02, 2011 at 19:41 PM

    Hey Brian,
    I found a temporary work-around, that is for some folks it worked, unfortunately for me it did not.

    But if you are interested here is the link:
    https://github.com/wayneeseguin/rvm/issues/553

    Thanks,
    Tom.

  12. djr.nzl@gmail.com
    djr
    November 08, 2011 at 21:21 PM

    Great - thanks the libyaml build install worked for me - and fixed the same problem you described with the 1.9.3 install.

  13. November 09, 2011 at 23:47 PM

    Hi! i’m repost you post: to my @urciibqo twitter

  14. November 14, 2011 at 20:18 PM

    For Debian Lenny, first add to /etc/sudoers:
    your_user ALL=NOPASSWD:/usr/bin/make

    Thany you! Gerald

  15. November 15, 2011 at 9:52 AM

    Correction.
    Sorry - it should bei Debian 6 - Squeeze.

    Best regards
    Gerald

  16. cpmmu@yahoo.com
    Christian Murphy
    November 18, 2011 at 18:17 PM

    Thanks for the useful tip.  I found that instead of
    –with-opt-dir=/usr/local/lib
    I need to run ./configure with
    –with-opt-dir=/usr/local
    (without the lib).  Otherwise, strace shows the loader trying to load the libyaml library from /usr/local/lib/lib.

  17. steve.andreas@ymail.com
    steve
    November 24, 2011 at 13:26 PM

    thanks for your article this helpfull with me

    best regards

  18. January 25, 2012 at 4:03 AM

    Why 1.9.3 is not yet recognize by rvm. Any ideas?

  19. January 28, 2012 at 3:38 AM

    Thank you. After wasting time with apt yaml, I got here. Installing from source works great. Thanks.

  20. January 31, 2012 at 6:29 AM

    Great tutorial, after a DAY trying to figure out how to install Ruby via other tutorials, this one was straight forward and easy to follow… you’re a life saver!!! TY!!! By the way could you also post a video for this?

  21. February 25, 2012 at 4:10 AM

    I have installed libyaml and libyaml-devel from yum(EPEL on CentOS 5) and I run:

    ./configure –with-opt-dir=/usr/include/

    Them, make and make install.
    It works!

    Thanks!

  22. david.kirk@surveysampling.com
    David
    March 14, 2012 at 22:10 PM

    I was hitting my head against the wall until I tried Ruby 1.9.3-p0 not the latest Ruby 1.9.3-p125.

    Thanks!

  23. sroby@uci.edu
    Seth A. Roby
    May 07, 2012 at 23:18 PM

    I got this working by changing the ruby configure line to:

        ./configure –prefix=/usr/local –enable-shared –disable-install-doc –with-opt-dir=/usr/local

    This picks up the library and the include file itself, which is apparently important, now.

  24. May 19, 2012 at 4:21 AM

    Thanks dude

  25. May 22, 2012 at 10:43 AM

    Thanks Ryan, this worked great for me.

  26. jaffer@i-waves.com
    jaffer
    May 30, 2012 at 12:14 PM

    Thanks bro ..! it works

  27. fc@forrestcorbett.com
    Forrest
    May 30, 2012 at 16:11 PM

    Followed it to a T, no errors, but when I check version it’s still at 1.8.5. :/

  28. June 10, 2012 at 19:47 PM

    Hello

    I had the same problem on openSUSE. After some searching, I found a blog post (http://blog.sethladd.com/2007/03/installing-openssl-support-for-ruby-on.html) that pointed me in the right direction. By following those instructions, I was able to install psych (and other stuff) with the libyaml available through my package manager.

    I don’t know how/if the openSUSE packaged version differs from CentOS and whether or not this would work for other uses, but hopefully it helps someone!

  29. thegrandpubah@hotmail.com
    Bryan
    July 12, 2012 at 22:48 PM

    Forrest, hopefully you solved this, but your PATH probably has /usr/bin ahead of /usr/local/bin, which is where these directions put the updated ruby. That’s what happened to me at least.

  30. dtkinzer@gmail.com
    David
    July 17, 2012 at 18:12 PM

    Thanks! This worked beautifully for me.

  31. admon@km69.com
    Peter
    July 22, 2012 at 17:27 PM

    how can i test if the libyaml is installed correctly?

    i have problems with the installation of libyaml and i think that it is the problem causes problems in my cpanel ( i can’t install ruby aplications with this error: “An unknown error was encountered when creating your rails application. “).

  32. flingfox63@hotmail.com
    laito
    July 25, 2012 at 12:17 PM

    Thanks . I got it at the version of ruby 1.93p134 on CentOS5.8

  33. September 29, 2012 at 16:23 PM

    Brian, you have no idea how much time (and money) you have just saved me.

    I was about to give up and outsource the install, usually I am able to do this sort of thing myself, however after 3 hours of trying to figure out the Linux commands, I was ready to throw in the towel.Then, I stumbled upon this article. Thanks very much!

  34. October 15, 2012 at 23:21 PM

    I´ve tried to complete the requierements of yeoman for almost 4 hours, most of the time was gone trying to successfully upgrade ruby. Thanks.

  35. carey.hinoki@gmail.com
    Carey Hinoki
    October 16, 2012 at 3:02 AM

    https://github.com/sstephenson/ruby-build/issues/119 check it out it worked for me and my comments are below - on Centos 6.3

  36. ben@doginthehat.com.au
    Ben
    October 23, 2012 at 3:45 AM

    Thanks, worked a treat!

  37. 8redkite8@gmail.com
    Do
    October 25, 2012 at 8:40 AM

    thank you, man, it helped!

  38. December 15, 2012 at 20:34 PM

    I was looking around on google, but could not find any satisfy answer, but your tips works great !!
    Thanks :)

  39. cbankester@immense.net
    cbankester
    December 19, 2012 at 16:21 PM

    Hey, I made a gist out of this for anyone to use. Check it out here:
    https://gist.github.com/4337899

    I updated the ruby version to the latest, ruby 1.9.3-p327. Now you can just run: ‘curl -L https://gist.github.com/raw/4337899/82702babb65ab72b6b8dec63b5346ca3c6f32e65/ruby_1.9.3-p327_install.sh | bash’ and it’ll just work.
    ;)

  40. February 14, 2013 at 18:11 PM

    Thank you for your help with this…

    I also had to leave off /lib from –with-opt-dir=$HOME

  41. edsanz@hotmail.com
    Eduardo Sanchez
    February 26, 2013 at 17:01 PM

    This worked great a couple of months ago.  Now, since I have 1.9.3-p0 installed: how do I update the ruby to 1.9.3-p392 ? Do I just follow the same ruby install steps above but replace with the p392 url?  Will it overwrite the p0 ruby or do I have to uninstall p0 first and then install p392? Do I have to reinstall all gems again?  Thanks.

  42. olivier.stas@skynet.be
    Olivier Stas
    March 07, 2013 at 10:51 AM

    Thanks for sharing, as adding libyaml via apitude on Ubuntu didn’t worked for me

  43. luccamordente@gmail.com
    Lucca Mordente
    April 06, 2013 at 19:52 PM

    Thanks a lot!!

  44. fred@polgardy.com
    Frederick Polgardy
    May 08, 2013 at 13:19 PM

    If you installed libyaml and libyaml-dev via yum, you need –with-opt-dir=/usr.

  45. mpc755@gmail.com
    mpc755
    October 01, 2013 at 13:25 PM

    Best post on the subject of libyml and ruby

  46. krishnanlathika0@gmail.com
    lathika
    February 21, 2014 at 11:34 AM

    Hi Brian ,

    I followed these steps for installing ruby , i have exported the values export CPPFLAGS=-I/scratch/gitlab/shared/include and export LDFLAGS=-L/scratch/gitlab/shared/lib
    But still i get this error when i run gem install bundler

    /scratch/gitlab/ruby/lib/ruby/1.9.1/yaml.rb:56:in `’:
    It seems your ruby installation is missing psych (for YAML output).
    To eliminate this warning, please install libyaml and reinstall your ruby.

    $ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
    $ tar xzvf ruby-1.9.3-p0.tar.gz
    $ cd ruby-1.9.3-p0
    $ ./configure –prefix=/scratch/gitlab/ruby –enable-shared –disable-install-doc –with-opt-dir=/scratch/gitlab/ruby/lib
    $ make
    $ make install

    $ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
    $ tar xzvf yaml-0.1.4.tar.gz
    $ cd yaml-0.1.4
    $ ./configure –prefix=/scratch/gitlab/shared
    $ make
    $ make install
    Please suggest what needs to be done for installing ruby

  47. December 22, 2016 at 5:51 AM

    Makes sense to me.

  48. December 22, 2016 at 5:52 AM

    Makes sense to me.

  49. May 11, 2019 at 10:03 AM

    Thanks for this nice tutorial.