Installing Ruby on Your Operating System
Install Ruby where Ruby, known for its simplicity and productivity, is widely used for web development, especially with the Ruby on Rails framework. In this guide, we’ll walk you through how to install Ruby on Windows, macOS, and Linux, so you can start coding in Ruby with ease.
Whether you’re a beginner or an experienced developer, this installation guide will cover everything you need to get Ruby up and running on your computer.
Why Install Ruby?
Installing Ruby opens up a world of development possibilities. Ruby is perfect for building web applications, automating scripts, and exploring object-oriented programming concepts. Its clear syntax and active community make it a great choice for both hobbyists and professional developers.
Installing Ruby on Windows
Method 1: Installing Ruby Using the RubyInstaller
- Download RubyInstaller:
- Go to the official RubyInstaller website: RubyInstaller for Windows.
- Download the latest recommended version of the RubyInstaller, which includes the MSYS2 development environment.
- Run the Installer:
- Double-click the downloaded file and follow the installation instructions.
- Make sure to check the box that says “Run ‘ridk install’ to setup MSYS2” at the end of the installation.
- Setting Up MSYS2 and Development Tools:
- After the installation, a command prompt will open to install MSYS2 and development tools.
- Choose the default options by pressing “Enter” for each prompt to complete the setup.
- Verify the Installation:
- Open a new command prompt window.
- Type
ruby -v
and press Enter. You should see the version of Ruby you installed.
Method 2: Using Windows Subsystem for Linux (WSL)
For those comfortable with Linux, another option is to install Ruby via the Windows Subsystem for Linux:
- Enable WSL:
- Go to “Control Panel > Programs > Turn Windows features on or off”.
- Check “Windows Subsystem for Linux” and restart your computer.
- Install a Linux Distribution:
- Open the Microsoft Store, install Ubuntu, or another distribution.
- Install Ruby in WSL:
- Open the Linux terminal and type:
- Check your Ruby installation by running
ruby -v
.
Installing Ruby on macOS
macOS users can install Ruby using either the Homebrew package manager or by manually installing Ruby from source.
Method 1: Installing Ruby with Homebrew
- Install Homebrew (if not already installed):
- Open Terminal and paste:
- Install Ruby Using Homebrew:
- In Terminal, type:
- This installs the latest stable version of Ruby.
- Update Your PATH:
- To make sure Ruby is accessible from anywhere, update your PATH:
- Verify Installation:
- Check the Ruby version by typing
ruby -v
in Terminal.
- Check the Ruby version by typing
Method 2: Installing Ruby with rbenv (Version Management)
- Install rbenv:
- First, install rbenv using Homebrew:
- Set Up rbenv:
- Add rbenv to your shell:
- Install Ruby with rbenv:
- Use rbenv to install a specific version of Ruby:
- Verify:
- Run
ruby -v
to confirm that the correct Ruby version is installed.
- Run
Installing Ruby on Linux
Method 1: Using the Package Manager
On Linux, you can easily install Ruby through your package manager.
- For Ubuntu/Debian:
- For Fedora:
- For Arch Linux:
Method 2: Using rbenv on Linux (Recommended for Version Management)
- Install Dependencies:
- Run the following to install dependencies:
- Install rbenv and ruby-build:
- Clone rbenv and ruby-build repositories:
- Set Up rbenv:
- Update your shell configuration:
- Install Ruby Using rbenv:
- Choose a Ruby version and install:
- Verify Installation:
- Run
ruby -v
to check the version.
- Run
Setting Up Ruby Development Environment
Once Ruby is installed, consider setting up essential tools to streamline your development:
- RubyGems: RubyGems is a package manager that comes with Ruby. Use
gem install
to install libraries and frameworks. - Bundler: Bundler is a tool to manage dependencies, ensuring that your application always has the correct gems installed.
- Rails (optional): If you’re interested in web development, install Rails:
Installing Ruby on Windows, macOS, or Linux is straightforward with the right instructions. By setting up Ruby on your system, you’re ready to dive into Ruby programming and explore everything the language offers.