Today, we will install Ruby on Rails (RoR) on my Dell E7240 Workstation Laptop i7 8gb 256 SSD running a linux operating system (Ubuntu 22.04.1 LTS). Moving forward, RoR is compatible with other operating systems ie Windows, MacOS. This guide will help in installing RoR with a simple step-by-step process. Your installation may differ, for other operating systems refer to this site.

Introduction

I am new to developing and have been using Ubuntu 22.04.1 LTS for my future projects. This overview is a reminder of the steps and information needed to get the environment and dependencies installed for RoR so you can get started.

Ruby on Rails is an excellent framework for web application development. For those of you who are new to RoR, like me, you will need to install several different applications (referred to as dependencies) to ensure this runs smoothly.

Tools You Will Need

Here are the packages, tools, and databases we will be installing:

  • git – A distributed version control system.

  • Create a GitHub accountOur preferred vendor that allows us to host git repositories in the cloud.

  • SSH Key – Secure Shell is a protocol that allows users to control and modify their remote servers over the Internet while ensuring security.

  • HomeBrew Software package manager that simplifies the installation process for Mac OSX and Linux.

  • rbenv – A tool that manages, installs and runs multiple versions of Ruby.

  • Visual Studio Code – My preferred code editor.

  • NodeJS – Javascript runtime environment. Runs on the Chrome V8 engine and executes javascript code outside of a web browser.

  • yarn – A more secure npm (node package manager – gets installed with NodeJS).

Step-By-Step Directions

Here are some steps to get your development environment setup and all of the dependencies installed.

Quick Note: For addition help guide go here: Linux MacOS. Windows

Install git

You will need to run the commands below in your terminal to install git.

$ sudo add-apt-repository ppa:git-core/ppa -y
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git -y

Remember git is the program for distributed version control, and GitHub is our preferred vendor. So if you haven’t create an account with GitHub.

Create SSH Key

You will need to create an SSH key and connect it to GitHub. We will first check to see if there are any existing SSH keys. Run this command to see if there are any pre-existing SSH keys.

$ ls -al ~/.ssh

If there are none, you will then run the next commands to generate a new one.

$ ssh-keygen -t ed25519 -C "your_email@example.com"
Quick Note: remember to add the email address used in your GitHub account! 

Next, press ENTER.

> Enter a file in which to save the key (/home/you/.ssh/id_ed25519): [Press enter]

Now you need to add your information for a passphrase or not if you don’t wish too.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again] 

Once you have the SSH key generated you will need to add it to the ssh-agent to manage. In the command line enter:

$ eval "$(ssh-agent -s)
> Agent pid 59566

To add itENTER.

$ ssh-add ~/.ssh/id_ed25519

The final step is to add it to GitHub. Follow this guide to do so.

Install HomeBrew

Homebrew is a package manager (similar to apt-get) that helps us install other packages to our system. To get the Homebrew package installed, you will have to run the below command:

Homebrew Help go here: Linux MacOS Windows

Linux
$ sudo apt install linuxbrew-wrapper  
Quick note: if this dosent work for you then make sure you have $(curl already installed on your system!
MacOS / Linux ( as per the Homebrew Offical Website )
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installing Ruby Environment

Install rbenv

Now things to note, rbenv is a tool that will help us manage installing and running multiple version of Ruby. To install rbenv, run the following:

$ brew install rbenv ruby-build

Now, rbenv should be installed, but we also need to add some startup scripts to your bash profile, so that your terminal uses rbenv instead of the system wide Ruby version.

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
Quick Note: If your using a new version of MacOS then ./bash_profile will be ./zshrc instead

Install Ruby 3.0.1

So, let’s start by using this (released on December 25th 2020) version of Ruby (3.0.1). To install this version of Ruby, we will use rbenv. Run the following in your terminal:

$ rbenv install 3.0.1 -v
$ rbenv rehash
$ rbenv global 3.0.1 # set the global
$ ruby -v

Installing Ruby v3.1.2 – latest version

Choose the version of Ruby you want to install:  

3.1.2 (current release since: 12 April 2022(Recommended)   

Older Versions: 3.0.4   2.7.6   2.6.10   2.5.9   2.4.10   2.3.8   2.2.10   2.1.10   2.0.0-p648  

The first step is to install some dependencies for Ruby and Rails.

To make sure we have everything necessary for Webpacker support in Rails, we’re first going to start by adding the Node.js and Yarn repositories to our system before installing them.

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
curl -sS 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 git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

Next we’re going to be installing Ruby using a version manager called Rbenv.

Installing with rbenv is a simple two step process. First you install rbenv, and then ruby-build:

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

To install Ruby and set the default version, we’ll run the following commands:

rbenv install 3.1.2
rbenv global 3.1.2

Confirm the default Ruby version matches the version you just installed.

ruby -v

The last step is to install Bundler

gem install bundler

rbenv users need to run rbenv rehash after installing bundler.

Install Visual Studio Code

You can follow the directions in the Visual Studio Code link to get the correct version installed on your device.

Install Postgres

Postgres will be our relational database preference for our RoR setup. To install:

$ brew install postgresql

Install Redis

Redis is our key value database that RoR uses for caching.

$ brew install redis

Install NodeJS

The link will take you through the steps to get the correct version of NodeJS installed to your device and will give a thorough understanding.

Install Yarn

For the final step we will be installing the package manager Yarn) by running the command below.

$ brew install yarn

Conclusion

Now, RoR is a great development environment. It is easy to navigate, scalable, and is excellent for solo developers wanting to learn Full Stack development and how it all works together.

I will be documenting my path on this developer journey by doing the “Odin Project – “Ruby on Rails” track: and also some other learning paths from Udemy

the-complete-ruby-on-rails-developer-course/

learn-to-code-with-ruby-lang/

professional-rails-5-development-course/

comprehensive-ruby-programming-tutorial/

I hope that who ever finds this may it guide you on the journey through web & software development.

lwa.{dev} for R.O.R


lwadevs@gmail.com

OpenSource Advocate - WordPress / PHP / Laravel / RubyOnRails Developer - GWS & Linux Administrator - Ex iOS Technician

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *