The default Ruby version installed via yum install ruby
on CentOS 7 is 2.0.
To install the latest version of Ruby on CentOS 7, you can follow these steps:
- Update the system:
sudo yum update
- 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
- 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
- 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
- Install OpenSSL:
sudo yum install -y openssl-devel
- 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
- Set the global default Ruby version:
rbenv global <version> # Set global default Ruby version, e.g., rbenv global 3.0.2
- 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.