Author: Nabeel Ahmed
Last Updated: Wed, Dec 1, 2021Ruby on Rails or Rails is an open-source web framework written in Ruby. It enables developers to efficiently build server-side rendered web applications through a model-view-controller code structure.
Deploy a new Ubuntu 20.04 Vultr cloud server.
Set up a non-root user with sudo privileges.
Verify that your server is up to date.
Install build-essential.
$ sudo apt-get install build-essential
Install the developer dependencies.
$ sudo apt-get install libssl-dev zlib1g-dev sqlite3 libsqlite3-dev
Install Git and curl if not already installed.
$ sudo apt-get install git curl
Rails uses the Javascript runtime through Nodejs to build applications through its Asset Pipeline.
Install the latest LTS version of Nodejs.
$ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
$ sudo apt-get install nodejs
Verify successful Nodejs installation.
$ node -v
v16.xx.x
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
Verify successful Yarn installation.
$ yarn -v
1.2x.xx
rbenv is a Ruby version manager used to install and manage Ruby environments.
Install rbenv.
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
This script automatically installs and updates rbenv.
Add rbenv to the path.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
$ exec $SHELL
Test that rbenv is installed correctly.
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash
Confirm audit results.
$ Checking for `rbenv' in PATH: /home/user/.rbenv/bin/rbenv
$ Checking for rbenv shims in PATH: OK
Verify PATH is correct by replacing user with your user name.
List the latest stable versions of Ruby.
$ rbenv install -l
Install Ruby with the desired version.
Keep in mind, Rails requires Ruby 2.5.0 or greater.
$ rbenv install 3.0.2 -v
Set global Ruby version.
$ rbenv global 3.0.2
Confirm installation with similar output.
$ ruby -v
ruby 3.0.2pxxx
Install Bundler using gem.
$ gem install bundler
Install Rails using gem.
$ gem install rails
Confirm successful installation.
$ rails -v
Rails 6.x.x.x
Create a new Rails project.
$ cd ~
$ rails new hello-world
$ cd hello-world
Start Rails server.
$ rails server --binding=0.0.0.0
Navigate to your server's IP address at port 3000 in a web browser. For example:
$ http://192.0.2.123:3000
You should see a working Rails server response.