Guides
Ruby on Rails on Ubuntu

[2 min installs] Ruby on Rails on Ubuntu

Better Stack Team
Updated on August 30, 2022

Here is how to install Ruby on Rail in under two minutes:

Step 1 - Install dependencies

Before installing Ruby on Rails, you need to install its dependencies first.

  1. Update package list on your system:
sudo apt-get update -y
Copied!
  1. Install build-essentials
sudo apt-get install build-essential
Copied!
  1. Install the developer dependencies.
sudo apt-get install libssl-dev zlib1g-dev sqlite3 libsqlite3-dev
Copied!
  1. Install Git and curl if not already installed.
sudo apt-get install git curl
Copied!

Step 2 - Install Nodejs & Yarn

Rails use the JavaScript runtime through Node.js to build the applications.

  1. Install the latest Node.js version (if not already installed)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install nodejs
Copied!
  1. Install Yarn
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
Copied!

Step 3 - Install rbenv

rbenv is a Ruby version manager used to install and manage Ruby environments.

  1. Install rbenv
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Copied!
  1. Add rbenv to the path
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
exec $SHELL
Copied!

Step 4 - Install Ruby

Now it is time to install the latest stable version of Ruby language. If you have done this already, you can skip this step.

  1. List the latest Ruby versions
rbenv install -l
Copied!
  1. Install the desired version (rails require version 2.5.0 or newer)
rbenv install 3.0.2 -v
Copied!
  1. Set global Ruby version
rbenv global 3.0.2
Copied!
  1. Install ruby bundler using gem
gem install bundler
Copied!

Step 5 - Install Rails

Finally, install rails using the following command:

gem install rails
Copied!

That’s it

You have installed Ruby on Rails on your system. To test if everything worked, create a test project and run it:

rails new hello-world
cd hello-world
rails server --binding=0.0.0.0
http://192.0.2.123:3000
Copied!
Check Uptime, Ping, Ports, SSL and more.
Get Slack, SMS and phone incident alerts.
Easy on-call duty scheduling.
Create free status page on your domain.
Got an article suggestion? Let us know
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.