How to Install Ruby 3.0 on AlmaLinux
Categories:
Ruby 3.0, released as a major update to the Ruby programming language, brings significant improvements in performance, features, and usability. It is particularly favored for its support of web development frameworks like Ruby on Rails and its robust library ecosystem. AlmaLinux, being a stable, enterprise-grade Linux distribution, is an excellent choice for running Ruby applications.
In this guide, we’ll cover step-by-step instructions on how to install Ruby 3.0 on AlmaLinux. By the end of this article, you’ll have a fully functional Ruby 3.0 setup, ready for development.
Why Ruby 3.0?
Ruby 3.0 introduces several noteworthy enhancements:
- Performance Boost: Ruby 3.0 is up to 3 times faster than Ruby 2.x due to the introduction of the MJIT (Method-based Just-in-Time) compiler.
- Ractor: A new actor-based parallel execution feature for writing thread-safe concurrent programs.
- Static Analysis: Improved static analysis features for identifying potential errors during development.
- Improved Syntax: Cleaner and more concise syntax for developers.
By installing Ruby 3.0, you ensure that your applications benefit from these modern features and performance improvements.
Prerequisites
Before installing Ruby 3.0, ensure the following:
Updated AlmaLinux System:
Update your system packages to avoid conflicts.sudo dnf update -y
Development Tools Installed:
Ruby requires essential development tools for compilation. Install them using:sudo dnf groupinstall "Development Tools" -y
Dependencies for Ruby:
Ensure the required libraries are installed:sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel
Methods to Install Ruby 3.0 on AlmaLinux
There are multiple ways to install Ruby 3.0 on AlmaLinux. Choose the one that best suits your needs.
Method 1: Using RVM (Ruby Version Manager)
RVM is a popular tool for managing Ruby versions and environments. It allows you to install Ruby 3.0 effortlessly.
Step 1: Install RVM
Install required dependencies for RVM:
sudo dnf install -y curl gnupg tar
Import the RVM GPG key:
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
Install RVM:
curl -sSL https://get.rvm.io | bash -s stable
Load RVM into your current shell session:
source ~/.rvm/scripts/rvm
Step 2: Install Ruby 3.0 with RVM
To install Ruby 3.0:
rvm install 3.0
Set Ruby 3.0 as the default version:
rvm use 3.0 --default
Step 3: Verify the Installation
Check the installed Ruby version:
ruby --version
It should output a version starting with 3.0
.
Method 2: Using rbenv
rbenv is another tool for managing Ruby installations. It is lightweight and designed to allow multiple Ruby versions to coexist.
Step 1: Install rbenv and Dependencies
Clone rbenv:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Add rbenv to your shell:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Install
ruby-build
:git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Step 2: Install Ruby 3.0 with rbenv
Install Ruby 3.0:
rbenv install 3.0.0
Set Ruby 3.0 as the global version:
rbenv global 3.0.0
Step 3: Verify the Installation
Check the Ruby version:
ruby --version
Method 3: Installing Ruby 3.0 from Source
For complete control over the installation, compiling Ruby from source is a reliable option.
Step 1: Download Ruby Source Code
Visit the official Ruby Downloads Page to find the latest Ruby 3.0 version. Download it using:
curl -O https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Extract the tarball:
tar -xvzf ruby-3.0.0.tar.gz
cd ruby-3.0.0
Step 2: Compile and Install Ruby
Configure the build:
./configure
Compile Ruby:
make
Install Ruby:
sudo make install
Step 3: Verify the Installation
Check the Ruby version:
ruby --version
Post-Installation Steps
Install Bundler
Bundler is a Ruby tool for managing application dependencies. Install it using:
gem install bundler
Verify the installation:
bundler --version
Test the Ruby Installation
Create a simple Ruby script to test your setup:
Create a file named
test.rb
:nano test.rb
Add the following code:
puts "Ruby 3.0 is successfully installed on AlmaLinux!"
Run the script:
ruby test.rb
You should see:
Ruby 3.0 is successfully installed on AlmaLinux!
Troubleshooting Common Issues
Ruby Command Not Found
Ensure Ruby’s binary directory is in your PATH. For RVM or rbenv, reinitialize your shell:
source ~/.bashrc
Library Errors
If you encounter missing library errors, recheck that all dependencies are installed:
sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel
Permission Denied Errors
Run the command with sudo
or ensure your user has the necessary privileges.
Conclusion
Installing Ruby 3.0 on AlmaLinux provides access to the latest performance enhancements, features, and tools that Ruby offers. Whether you choose to install Ruby using RVM, rbenv, or by compiling from source, each method ensures a robust development environment tailored to your needs.
With Ruby 3.0 installed, you’re ready to build modern, high-performance applications. If you encounter issues, revisit the steps or consult the extensive Ruby documentation and community resources.