Tutorial: How to install Ruby on CentOS Linux

ruby, php, java, python code

If you’re working on CentOS and need to install Ruby, there are a few ways to get it done. Whether you need the default version for simple tasks or want the latest release for a specific project, this guide has you covered. Let’s walk through the top three methods to install Ruby on CentOS.

Method #1 – Install Ruby from CentOS Repositories

The easiest way to install Ruby on CentOS is through the system’s default repositories. While this method might not give you the latest version, it’s quick and gets the job done.

  1. Update your system packages using the yum update command.
  2. Install Ruby by running yum install ruby.
  3. Once that’s done, verify the installation with ruby --version.

This method is perfect for getting started quickly without worrying about compatibility issues.

Method #2 – Install Ruby Using RVM

RVM, or Ruby Version Manager, is an excellent tool if you need to install and manage multiple Ruby versions. It’s especially handy for developers working on projects that require specific Ruby versions.

  1. Start by installing necessary dependencies like curl, gcc, and zlib-devel.
  2. Next, import the GPG keys required by RVM.
  3. Download and install RVM by running the installation script provided on the official site.
  4. After installation, load the RVM scripts by sourcing them into your shell.
  5. Use RVM to install Ruby. For instance, to install version 3.2.2, you’d use the command rvm install 3.2.2.
  6. Set your installed Ruby version as the default by running rvm use 3.2.2 --default.
  7. Finally, check if everything’s set up by running ruby --version.

RVM is a powerful tool if you want flexibility. You can switch between Ruby versions or upgrade seamlessly as needed.

See also  Linux Tips: Using 'tail' to Display File Updates in Realtime

Method #3- Install Ruby Using Rbenv

Rbenv is another tool you can use to install Ruby on CentOS. It’s lightweight and designed to give you control over Ruby versions without extra frills.

  1. Install dependencies like git, gcc, and openssl-devel using your package manager.
  2. Clone the Rbenv and Ruby-build repositories to your home directory.
  3. Update your environment variables by adding Rbenv to your PATH. You’ll need to update your .bashrc file and reload it to apply the changes.
  4. Use Rbenv to install Ruby. For example, to get version 3.2.2, you’d use the rbenv install 3.2.2 command.
  5. Set this version as the default with rbenv global 3.2.2.
  6. Confirm your setup is working by running ruby --version.

If you like things lightweight and minimal, Rbenv is a great choice. It lets you focus on the essentials without unnecessary complexity.

Which Method Should You Choose?

When deciding how to install Ruby on CentOS, think about what you need:

  • Default Repositories: Best for a quick and straightforward setup.
  • RVM: Ideal for managing multiple versions of Ruby on the same system.
  • Rbenv: Great for a lightweight and hands-on approach to Ruby version management.

Each method has its perks, so pick the one that works best for your workflow.

Installing Ruby on CentOS doesn’t have to be complicated. Whether you go with the built-in package manager, RVM, or Rbenv, you’ll have Ruby up and running in no time. So dive in, choose the method that fits your needs, and start building something amazing with Ruby today!

Photo of author
As Editor in Chief of HeatWare.net, Sood draws on over 20 years in Software Engineering to offer helpful tutorials and tips for MySQL, PostgreSQL, PHP, and everyday OS issues. Backed by hands-on work and real code examples, Sood breaks down Windows, macOS, and Linux so both beginners and power-users can learn valuable insights.

11 thoughts on “Tutorial: How to install Ruby on CentOS Linux”

  1. Well unfortunately this didn’t work out for me…

    I got this during make install:

    ./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ./instruby.rb –make=”make” –dest-dir=”” –extout=”.ext” –mflags=”” –make-flags=”” –data-mode=0644 –prog-mode=0755 –installed-list .installed.list –mantype=”doc”
    /bin/sh: ./miniruby: No such file or directory
    make: *** [do-install-nodoc] Error 127

  2. @Kat – Are you using CentOS 5.5? Can you try going through the steps one more time and let me know if you still see the error?

  3. Even after repeating the steps in centos 5.5 ,it does’t work.I meant I am getting same error like Kat is getting

  4. This worked in compiling it but it still does not work in the correct path :

    [root@hostname ruby-1.8.7-p330]# ruby -v
    ruby 1.8.5 (2006-08-25) [x86_64-linux]
    [root@hostname ruby-1.8.7-p330]# ./ruby -v
    ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux]
    [root@hostname ruby-1.8.7-p330]# which ruby
    /usr/local/bin/ruby
    [root@hostname ruby-1.8.7-p330]# which ./ruby
    ./ruby
    [root@hostname ruby-1.8.7-p330]#

  5. @alainchiaasson Try running configure with the prefix tag set to the default path. /usr.
    If you’ve ever used pirut or downloaded the rpm from the CentOS repos, then your gems and everything else expect ruby to be in /usr/bin, the libraries in /urr/lib and so on in that fashion.

    The default location specified in the config file is to put everything in /usr/local which will sort of mostly work, but may cause you some grief if you don’t feel like putting in the whole path when running a ruby executable. The fix is as easy as running configure again with the expected prefix location, then make and make install again.

    ./configure –prefix=/usr –enable-shared –enable-pthread
    make && sudo make install

    Best of luck.

Leave a Comment