How to Install, Set Up, And Get Started Coding With The Ruby Programming Language - On Linux

A List For 2025

By Rob Rockwell

Ruby is a dynamic, object-oriented language known for its expressiveness, simplicity, and productivity. Made famous by the Rails web framework, Ruby has a strong community and is well-loved by developers who value elegant syntax and developer happiness. It excels in web development, scripting, DevOps, automation, and more, making it a versatile tool in any developer's toolkit.

This guide will help you install Ruby on Linux, set up version managers like rbenv or RVM, and configure your system to manage gems and dependencies using Bundler. Whether you're interested in writing small scripts or full-fledged web apps, you'll find Ruby a joy to work with—and easy to get started with on your Linux machine.

Retro Mainframe Smiling Guy Install Ruby

Ruby Prerequisites

Before installing Ruby, ensure your system is up to date and has the essential development tools. These are needed whether you build Ruby from source or use a version manager like rbenv or RVM. At a minimum, you'll want Git, build tools, and libraries for SSL and compression support.

Run the following command to install the necessary packages on Ubuntu or similar distributions:

sudo apt update 
sudo apt install -y git curl gnupg build-essential libssl-dev libreadline-dev zlib1g-dev

Installing Ruby

You can install Ruby directly using your system package manager, but this often gives you an older version. For most development workflows, using a version manager is the better option. Still, here’s how to get Ruby using the official Ubuntu package:

sudo apt install -y ruby-full

Once installed, verify it with:

ruby -v

Using rbenv or RVM for Version Management

If you need flexibility or want to work on projects requiring different Ruby versions, use a version manager. Both rbenv and RVM let you install and switch between Ruby versions easily, without affecting the system Ruby.

To install rbenv and ruby-build:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv cd ~/.rbenv && src/configure && make -C src echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc exec "$SHELL" git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Then install a specific Ruby version:

rbenv install 3.2.2 rbenv global 3.2.2 ruby -v

Alternatively, you can install RVM with:

curl -sSL https://get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm rvm install 3.2.2 rvm use 3.2.2 --default

Verifying Your Installation

After installing Ruby—whether through `apt`, `rbenv`, or `RVM`—you can verify that it's properly set up by checking the version and testing a quick script. This ensures the binary is in your path and functioning correctly.

Run the following command to check the Ruby version:

ruby -v

If Ruby is installed correctly, you’ll see output somewhat like:

ruby 3.2.2p53 (2023-03-30 revision 1234567890) [x86_64-linux]

Setting Up Gems and Bundler

Ruby uses a package management system called RubyGems to install and manage libraries. It's usually bundled with Ruby, but you can upgrade it using:

gem update --system

Bundler is the standard tool for managing project dependencies. Install it globally with:

gem install bundler

Once installed, you can use a `Gemfile` to declare dependencies and run `bundle install` to set up your environment consistently across machines.

Using IRB (Interactive Ruby)

IRB stands for Interactive Ruby and is a REPL (Read-Eval-Print Loop) for quickly testing Ruby code in your terminal. It comes preinstalled with most Ruby setups.

To start IRB, simply run:

irb

You can type Ruby expressions directly and get immediate feedback. This is especially useful for learning, experimenting, or debugging small snippets of code.

Writing Your First Ruby Script

Once Ruby is installed and verified, you can write a simple script to make sure everything is working. Use any text editor to create a file called hello.rb:

puts "Hello, Ruby world!"

Save the file and run it from the terminal with:

ruby hello.rb

You should see the message printed to the console. Congratulations—you’ve just run your first Ruby script!

Configuring Your Editor or IDE

Ruby works well with many text editors and IDEs. Popular choices include Visual Studio Code, RubyMine, Sublime Text, and even Vim or Emacs. At a minimum, make sure your editor supports Ruby syntax highlighting and integrates with terminal commands.

For VS Code, you can install the Ruby Extension Pack, which includes support for linting, IntelliSense, and formatting:

code --install-extension rebornix.Ruby

Creating a Basic Ruby Project

Ruby projects are usually structured with a few conventional files. To start a new project, create a directory and add a Gemfile and an app.rb or similar entry point:


mkdir my_ruby_app
cd my_ruby_app
bundle init

Edit the Gemfile to add dependencies:


source "https://rubygems.org"
gem "httparty"

Then run:

bundle install

Now you can start building your app in app.rb or organize it into subdirectories like lib/ and spec/ as your codebase grows.

Next Steps and Learning Resources

Next Steps and Learning Resources

To continue learning Ruby, check out official documentation at ruby-lang.org, or explore books like The Well-Grounded Rubyist and Eloquent Ruby.

If you're more visual or hands-on, our Code Visualization course is a great place to strengthen your understanding of Ruby through interactive, visual representations of code execution.

Start mastering programming with our revolutionary Code Visualization course!