Friday, April 6, 2012

Installing and compiling Ruby from the source code

There are several different ways to install Ruby with the most popular being RVMand rbenv. Both have their advantages and disadvantages, but rbenv is a newer and more "lightweight" Ruby installer. I'll let you Google the differences between RVM and rbenv if you are more curious. I decided to install Ruby by downloading the source code and then compiling it myself. I'll be installing Ruby 1.9.3-p125 (the latest version as of writing this) on Debian Linux 6 (Squeeze).

1. First we need to install some development tools and libraries that Ruby needs to compile. Run the following commands from your terminal:
   apt-get install build-essential vim git-core curl

   apt-get install bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev

   apt-get install libcurl4-openssl-dev libopenssl-ruby apache2-prefork-dev libapr1-dev libaprutil1-dev

   apt-get install libx11-dev libffi-dev tcl-dev tk-dev
Note you may need to run these commands as root or use sudo.

2. Download the latest version of Ruby here: http://www.ruby-lang.org/en/downloads/ under the Compiling Ruby — Source code section.

3. Extract the tar.gz file e.g. ruby-1.9.3-p125.tar.gz by typing:
tar -xvf ruby-1.9.3-p125.tar.gz
4. Open the README and follow the instructions on how to compile and install Ruby.
./configure
make
make test
make install
The install process will probably take a while, but once it's done, we can test to see if ruby installed successfully by typing "ruby -v" in the terminal. You should see something like, "ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]" if ruby installed correctly. Next we can install the Bundler and Rails gems to make sure Ruby is working correctly.
gem install bundler
gem install rails
Lastly, create a new Rails project to test to make sure everything works!

26 comments:

  1. Worked like a charm! No warnings, just pure Ruby bliss. Thanks for the article.

    ReplyDelete
  2. Worked pretty fine for me, thank you fellow!

    ReplyDelete
  3. I'm having trouble, when I go to extract tar.gz file it says

    tar: ruby-1.9.3-p125.tar.gz: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now

    I have downloaded ruby, so I don't why this file can't be found. Any thoughts?

    ReplyDelete
    Replies
    1. just check if the file name is same in the command.

      Delete
  4. Fantastic. Well played. Kudos. Thanks for a well written post... I have installed Ruby/Rails on many computers and OSes before, but this time around, compiling it from source, the process was 10x more satisfying.

    ReplyDelete
  5. Thanks for the helpful tutorial :)

    ReplyDelete
  6. I get this error after following the entire process
    any suggestions
    The program 'ruby' can be found in the following packages:
    * ruby1.8
    * ruby1.9.1
    Try: sudo apt-get install

    ReplyDelete
    Replies
    1. same here... I ended up installing ruby using apt

      Delete
    2. This comment has been removed by the author.

      Delete
  7. Worked perfectly with ruby2.0.0 and rails4 on ubuntu, thanks a lot

    ReplyDelete
  8. Great !! Worked like a charm for me :) Thank you very much :)

    ReplyDelete
  9. I would love to stop by. But, I think it might have to wait until this summer. I did not know that Serlkay had ever expanded its size. I must say that a succesful family owned business in this day and age is a very refreshing sight! As well as this is a very refreshing site!
    Google Music Desktop Player

    ReplyDelete
  10. A small aside but I recently tried this on Open SUSE and ruby 2.1.2, I first had to install GCC via YaST.

    If this comment saves someone else that bafflement, it was worth it.

    ReplyDelete
  11. software development company delhi for outsourcing the projects, you need to put some extra efforts and research work to numbers of companies are available in the market to provide software development services.

    ReplyDelete
  12. Your site is very informative and your articles are wonderful. Hire PHP Developers

    ReplyDelete
  13. I am trying to compile for embedded linux-powerpc arch. And my rootfs does not come with base ruby. So i tried to compile ruby 2.2.1 from source but it has a pre-req for ruby and now this is a dead lock.
    So now how do i compile ruby from source without a base version of ruby already installed.

    ReplyDelete
  14. Very informative post, thanks for sharing. We offer best price in the industry and complete value of money to clients. We are one of the best companies offering Ruby on Rails in India.

    ReplyDelete
  15. Thanks for the post. I'm trying to get an old rails project to work under Docker and found this helpful!

    ReplyDelete
  16. Great post. If you are looking for Ruby on Rails experts in India then Cryptex Technologies is the best company for you. For any queries email us at: info@cryptextechnologies.com

    ReplyDelete
  17. Is there a way to compile Ruby by specifying the TK libraries rather than ActiveTcl, which is what Ruby is looking for with 2.3.1.

    ReplyDelete
    Replies
    1. My Ubuntu 16.04 keeps saying it can't find libtcltk-ruby, or any libraries, and whines it can't find ActiveTcl.

      Delete
  18. Very informative article, thanks for sharing! Ruby On Rails is powerful framework and it does require proper installation. If Proper installation is done as per the instruction, no one will find any kind of error at the time of compiling. To know more about RoR web Development check out this article: https://goo.gl/wySXDz

    ReplyDelete