Kategorie: Linux

Installing Ruby on Rails on Ubuntu 22.04

The guide describes how to install Ruby on Rails on Ubuntu 22.04.
We will do everything through the console in a few steps.

We add the repository key to the system:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDB

We download the RPM installer

curl -sSL https://get.rvm.io | bash -s stable --ruby

The command will automatically install the required packages and install the Ruby version 2.7.

After completing all the installation, load the RVM to the system with the following command.

source /usr/local/rvm/scripts/rvm

Then update the RVM to the latest stable version and add the root user to the rvm group.

rvm get stable --autolibs=enable
usermod -a -G rvm root

Then check the rvm version with the command below.

rvm version

We move on to installing Ruby on Rails.

rvm install ruby-2.7.1

When the entire installation is complete, set Ruby 2.7.1 as the default version.

rvm --default use ruby-2.7.1

Now check the Ruby version with the command below.

ruby --version

Installation of the necessary Nodejs and Yarn packages

sudo apt install gcc g++ make

Now add the Nodejs Nodesource repository.

curl -sL https://deb.nodesource.com/setup_14.x | -E sudo bash -

Then add the GPG key and the Yarn package manager repository.

curl -sL 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

Then update all available packages on your system and install Nodejs and Yarn, using the apt command below.

sudo apt update
sudo apt install yarn nodejs

After completing all the installation, check the Nodejs version with the following command.

node --version

We are updating GEM packages:

gem update --system

Otrzymasz pomyślną wiadomość, as below.

Then create a new configuration for RubyGem '~ / .gemrc' and disable package documentation installation with command below.

echo "gem: --no-document" >> ~/.gemrc

We install rails

gem install rails

In this tutorial, we will use PostgreSQL as the database for our Rails project. In this step, we will install the PostgreSQL database server provided by the official ubuntu repository.

Install the PostgreSQL database server on Ubuntu 20.04, using the apt command below.

sudo apt install postgresql postgresql-contrib libpq-dev -y

We run in the system:

systemctl start postgresql
systemctl enable postgresql

Then log in to the PostgreSQL shell and create a new role "user_dev" with the password "password" and permissions "createdb" and "login".

sudo -i -u postgres psql
create role uzytkownik_dev with createdb login password 'haslo';

Now see all available users in PostgreSQL, using the following query.

\from

By default, Ruby on Rails used SQLite as the default database. In this guide, we're going to start a new Rails project, using the PostgreSQL database.

Create a new 'application' project with the default PostgreSQL database, using the following command 'rails'.

rails new application -d postgresql

Now you will get the project directory 'application', go to the project directory and edit the database configuration 'config / database.yml' with the nano editor.

cd application /
nano config/database.yml

In the developer section, add the database configuration as below.

host: localhost
  port: 5432
  username: uzytkownik_dev
  password: haslo

Save and close.

Then run the rails command below, to generate and migrate the database for our Rails project, and make sure, that there is no error.

rails db:setup
rails db:migrate

After the installation is complete, start the default puma rails web server, using the command below.

rails s -b 0.0.0.0 -p 8080

"Application" will run on your public IP address with port "8080".

Now open your web browser and enter the server's IP address with port "8080" in the address bar.
You will see the first Ruby on Rails project.

In this step, we will create a new simple CRUD application using Ruby on Rails and a PostgreSQL database.

Generate a simple CRUD application with ruby ​​scaffold command, as below.

rails g scaffold Post title:string body:text

Then migrate your database with the following command.

rake db:migrate

make sure, that there is no error, and then restart the puma server.

rails s -b 0.0.0.0 -p 8080

Go back to the web browser and enter the server's IP address with port "8080", followed by the "/ posts" path.

http://10.5.5.32:8080/posts

Create a new post and enter a title and content.

As a result, a simple CRUD application with a PostgreSQL database was created using Rails.

Ultimately installing and configuring Ruby on Rails with PostgreSQL database on Ubuntu 20.04 has been successfully completed.

Linux

Udostępnij
Opublikowane przez
Linux

Recent posts

KeePass2 2.52 w Ubuntu 22.04

The guide below describes how to install KeePass on Ubuntu. Całość wykonamy za pomocą kilku poleceń

2 years temu

Installing Master PDF editor in Ubuntu 22.04

Master PDF Editor is a comprehensive PDF program, which includes many features. Oprócz tworzenia i edycji

2 years temu

iotop - memory monitoring

Iotop jest prostym narzędziem dla systemów Uniksowych umożliwiającym monitorowanie użycia dowolnego nośnika pamięci flash/hdd/ssd w

2 years temu

Run multiple commands in one cron job

You can separate two or more commands with semicolons (;), Semicolon (;): służy do oddzielania

2 years temu

Changing the exif data of a photo in the Linux terminal

Poniższy poradnik opisuje w jaki sposób za pomocą konsoli możemy dokonać edycji danych zdjęcia exif.

2 years temu

Installing Rocket.Chat Server on Rocky Linux 8

The following guide describes how to install Rocket.Chat on Rocky Linux 8 Całość bardzo prosto zainstalujemy

2 years temu