11.12.2024

Installing Ruby on Rails 3.1.2 on Ubuntu 20.04 server

A short note about the framework:

Ruby on Rails was written in the programming language "Ruby". It was created as far back as 2004, and gained its popularity through an interaction with Apple in 2006. At that time "Apple" announced that it will ship "Ruby on Rails" together with Mac OS X 10.5 "Leopard" operating system.

Also we must not forget that this framework has influenced the development of web applications through innovative features such as creation of database tables, migration and creation of presentation frameworks to ensure fast application development.

The uniqueness of Ruby

There are many web development frameworks in the programming world, but Django and Ruby on Rails stand out the most.

This makes them the most popular web development frameworks and this popularity will continue to grow.

Scalability

While Django inherited its scalability from Python, it is still slightly behind Rails. It has better scalability, which is a result of its qualities of freedom and code flexibility. Both are heavyweight web development frameworks, so they are both designed with scalability in mind, but in this case the win goes to Ruby on Rails.

Syntax

Ruby's syntax is known to be very flexible. However, this can not always be attributed to the advantages of Ruby on Rails. It can cause problems and make it difficult to pass a project to other team members, as the same function can be implemented in different ways, creating confusion.

Whereas Python advocates that there should only be one obvious way to do something, which makes the code easier to debug and read.

Update the packages on the system:

apt-get update && apt-get upgrade

Install packages:

apt install curl # Install the curl program

apt install git # Install the git program

apt-get install -y nodejs # Install the nodejs program.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - # Install the yarn program

Now it remains to install the remaining packages to make it work:

sudo apt-get install 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 -y

Installation through Rbenv:

Next, the Ruby installation will be handled by the Rbenv manager. This will speed up the installation process. First install rbenv , then ruby-build.

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

Install ruby-build:

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 the Ruby programming language using the commands below:

rbenv install 3.1.2
rbenv global 3.1.2

A bit about Rbenv:

This is a command line tool used to install Ruby on Rails, it also provides a good environment for developing applications using Ruby on Rails.

gem install bundler # Last step, install bundler.

gem install rails -v 7.0.2.4 # Install Rails software

rbenv rehash # Make available the executable with the command below

Databases for Rails:

By standard, sqlite3 is installed, but it is better to use another database, for example PostgreSQL or MySQL. In our case, we will use PosgreSQL. (But it also takes into account how to enable MySQL).

A little bit about sqlite3:

This database was developed in the spring of 2000. The purpose of developing SQLite - was to be able to work with the program without installing a database management system or the need to involve the database administrator.

SQLite is one of the four formats recommended for long-term storage of data sets approved for use by the Library of Congress.

A little about PostgreSQL:

It is a free, open-source relational database management system. It began back in 1982, evolving from the Ingres project which was developed at the University of California, Berkeley.

PostgreSQL gained popularity due to its query optimizations. It combines many indexes for different purposes and makes query execution much simpler and more efficient because it prescribes which steps to perform and in what time frame.

sudo apt install postgresql-11 libpq-dev # Now install PostgreSQL

rails new myapp -d postgresql # Include PostgreSQL in Rails

sudo apt-get install mysql-server mysql-client libmysqlclient-dev -y # Install MySQL

 

A little about MySQL:

It is free and open source software under the GNU General Public License and is also available under various proprietary licenses. MySQL has standalone clients which allow users to directly access and interact with the database, but more often MySQL is used with other programs to implement applications that require relational database capabilities.

rails new myapp -d mysql # Enable MySQL on Rails

cd myapp # Go to the myapp directory.

rake db:create # Create a new database there.

To change the ip address of the server, type the command below:

rails s -b y.y.y.y (y.y.y.y is our server ip address)
rails s -b 45.138.24.121

We can go to our server using ip-server:3000

Conclusion:
This publication makes it easy to install Ruby on Rails on your Ubuntu server.
The only question that remains is what framework to choose and why?