1. Computing

Install Ruby on Linux

By

Ruby is installed on most Linux distributions by default. Follow these steps to determine if Ruby is installed and, if not, install the Ruby interpreter on your Linux computer.

Difficulty: Easy
Time Required: 15 minutes

Here's How:

  1. Open a terminal window. It may also be referred to as a "shell" or "bash shell" in the menus. On Ubuntu, go to Applications -> Accessories -> Terminal.
  2. Run the command which ruby.
  3. If you see a path such as /usr/bin/ruby, Ruby is installed. If you don't see any response or get an error message, Ruby is not installed.

  4. To verify that you have a current version of Ruby, run the command ruby -v.
  5. Compare the version number returned with the version number on the Ruby download page. These numbers don't have to be exact, but if you are running a version that's too old, some of the features may not work correctly.
  6. Install appropriate Ruby packages. This differs between distributions, but on Ubuntu run the following command:
    
    sudo apt-get install ruby1.8 ruby1.8-dev irb rdoc ri
    
  7. Open a text editor and save the following as test.rb.
    
    #!/usr/bin/env ruby

    puts "Hello world!"
  8. In the terminal window, change directory to the directory you saved test.rb.
  9. Run the command chmod +x test.rb.
  10. Run the command ./test.rb. You should see the message Hello world! displayed if Ruby is installed correctly.

Tips:

  1. Every distribution is different. Refer to your distribution's documentation and community forums for help installing Ruby.
  2. For distributions other than Ubuntu, if your distribution doesn't provide a tool like apt-get then you can use a site such as RPMFind to find Ruby packages. Be sure to look for the irb, ri and rdoc pacakges as well, but depending on how the RPM package was built it may already include these programs.

  1. About.com
  2. Computing
  3. Ruby
  4. Tutorials
  5. Installing Ruby
  6. How to Install Ruby on Linux

©2014 About.com. All rights reserved.