Setup Ruby On Rails Development Environment On Ubuntu/Debian

Exported on 07-Oct-2021 22:41:02

Install Ruby On Rails Development Environment On Debian Based Servers With AttuneOps

This Blueprint Installs Ruby On Rails Development Server On Debian Based Servers

Ruby on Rails is a server-side web application framework under the MIT License written in Ruby. Rails is a model–view–controller framework, providing web services, web pages, and default structures for a database,.

Ruby ranks amongst the top ten programming languages predominantly because of the voguishness of Rails. While it's clear that Ruby is a more difficult programming language to master, in many ways, it is a more robust language that is better suited for creating business applications.

Pre-Blueprint Attune setup
  1. On the Inputs tab, create a Linux node for the host you wish to install the stack on.
  2. On the Inputs tab, create Linux credentials to connect to the host you wish to install the stack on.
Steps Involved
  • Update apt repositories.
  • Install prerequisites.
  • Install Node, rbenv and postgres Database.
  • Create ROR project.
  • Launch ROR development server.
Supported Operating Systems
  • Ubuntu
  • Debian

Parameters

Name Type Script Reference Default Value Comment
Linux Node Linux / Unix Server linuxNode
Linux User Linux OS Credential linuxUser

1 - Install ROR Dependencies

Installs prerequisites for the Ruby on Rails environment

The connection details have changed from the last step.

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Install curl
sudo apt-get install curl

# Install NodeJS
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

# Configure source list
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

# Install dependencies
sudo apt-get -y update
sudo apt-get -y 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

2 - Install rbenv

Install rbenv and ruby version 3.0.1

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Configure git
git clone https://github.com/rbenv/rbenv.git ~/.rbenv

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

# Install rbenv and set global version
~/.rbenv/bin/rbenv install 3.0.1
~/.rbenv/bin/rbenv global 3.0.1

#Create symlinks
sudo ln -s ~/.rbenv/versions/3.0.1/bin/* /usr/bin/

ruby -v

3 - Install Rails

Installs rails and bundler

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Install bundler
gem install bundler

# Install rails
gem install rails -v 6.1.3.2

# Link rails
sudo ln -s ~/.rbenv/versions/3.0.1/bin/rails /usr/bin/rails

# Rehash and check version
~/.rbenv/bin/rbenv rehash
rails -v

4 - Install PostgreSQL

Installs PostgreSQL database and PSQL development libraries

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Installs and configures postgreSQL
sudo apt -y install postgresql libpq-dev

5 - Setup Rails Application

Creates new rails project, sets up a new postgres role and executes the migration for the ROR app.

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
#Create ror project
rails new myapp -d postgresql
cd myapp

# Create postgres user/role
sudo -u postgres createuser --superuser $(whoami)

# Run migration
rake db:create

6 - Start Rails Development Server

Starts the rails development server, accessible at https://YOUR_IP:3000/

You can access the server process by using the command: screen -x

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
cd myapp

# Install screen 
sudo apt -y install screen
sudo echo "zombie xy" >> ~/.screenrc

# Start the development 
screen -d -m rails server -b 0.0.0.0