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.
Table of Contents
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.
- Update your system packages using the
yum update
command. - Install Ruby by running
yum install ruby
. - 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.
- Start by installing necessary dependencies like
curl
,gcc
, andzlib-devel
. - Next, import the GPG keys required by RVM.
- Download and install RVM by running the installation script provided on the official site.
- After installation, load the RVM scripts by sourcing them into your shell.
- Use RVM to install Ruby. For instance, to install version 3.2.2, you’d use the command
rvm install 3.2.2
. - Set your installed Ruby version as the default by running
rvm use 3.2.2 --default
. - 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.
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.
- Install dependencies like
git
,gcc
, andopenssl-devel
using your package manager. - Clone the Rbenv and Ruby-build repositories to your home directory.
- 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. - Use Rbenv to install Ruby. For example, to get version 3.2.2, you’d use the
rbenv install 3.2.2
command. - Set this version as the default with
rbenv global 3.2.2
. - 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!