Featured image of post Installing a Newer Version of Ruby on CentOS 7

Installing a Newer Version of Ruby on CentOS 7

The default Ruby version installed via yum on CentOS 7 is 2.0. To install a newer version of Ruby on CentOS...

The default Ruby version installed via yum install ruby on CentOS 7 is 2.0.

Installing a Newer Version of Ruby on CentOS 7

To install the latest version of Ruby on CentOS 7, you can follow these steps:

  1. Update the system: sudo yum update
  2. Install necessary dependencies: sudo yum install -y curl git-core gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison
  3. Install rbenv (for Ruby version management):
    1
    2
    3
    4
    
    git clone https://github.com/rbenv/rbenv.git ~/.rbenv 
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc 
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc 
    source ~/.bashrc
    
  4. Install the ruby-build plugin (for installing different Ruby versions):
    1
    2
    3
    
    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build 
    echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc 
    source ~/.bashrc
    
  5. Install OpenSSL: sudo yum install -y openssl-devel
  6. Install the latest version of Ruby:
    1
    2
    
    rbenv install --list # List available Ruby versions 
    rbenv install <version> # Install a specific Ruby version, e.g., rbenv install 3.0.2
    
  7. Set the global default Ruby version: rbenv global <version> # Set global default Ruby version, e.g., rbenv global 3.0.2
  8. Verify the installation:
    1
    2
    
    ruby --version # Check Ruby version 
    gem --version # Check gem (Ruby package manager) version
    

You have now successfully installed the latest version of Ruby. Please install the desired Ruby version based on your needs and set it as the default version.

Licensed under CC BY-NC-SA 4.0