قالب وردپرس درنا توس
Home / How To / How to install Ruby on Rails (RoR) on Debian 10

How to install Ruby on Rails (RoR) on Debian 10



Ruby on Rails (RoR) is an open source application for web applications, published under the MIT license. It is a server-side web application framework that follows the Model-View-Controller (MVC) concept.

Rails provides standard structures for the database, web service and web pages. More than 3000 developers have contributed code to the Rails framework and there are many well-known applications based on Rails, such as Github, Airbnb, Soundcloud, etc.

In this tutorial we will show you how to install Ruby on Rails on Debian Buster 10. This guide will cover the RVM (Ruby Version Manager) installation, PostgreSQL database installation and create the simple CRUD application with Ruby on Rails and use PostgreSQL as a backend database.

Prerequisites

For this guide, we will use the latest Debian Buster 1

0 with 2 GB RAM and 25 GB free disk space and 2 CPU.

What to do?

  • Install RVM (Ruby Version Manager)
  • Install Ruby with RVM
  • Install Nodejs and Yarn
  • Upgrade RubyGem (Ruby Package Manager)
  • Install Ruby on Rails Stable
  • Install and configure PostgreSQL- database
  • Start projects with Ruby on Rails
  • 19659014] Step 1 – Install RVM (Ruby V ersion Manager)

    First we will install RVM (Ruby Version Manager) on our Debian server. RVM makes it easy to install and manage Ruby on your system, especially when using multiple Ruby versions.

    Before you go any further, install the gnupg2 package with the apt command below.

      sudo apt install gnupg2 [19659018] Then import the GPGP key for the RVM package using the gpg command below. 

      gpg --keyserver hkp: //pool.sks-keyservers.net --recv keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E4B9D701D07D09 installation script and install it below with the command. 

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

      Install RVM

    When the installation is complete, load RVM to the Debian system.

      source / usr / local / rvm / scripts / rvm [19659018] And Ruby Version Manager has been installed in the Debian 10 system, check it with the & # 39; rvm & # 39; below. 

      rvm version 

    As a result, RVM (Ruby Version Manager) xxx has been installed on Debian Buster 10.

     Check the RVM installation on Debian

    Step 2 - Install Ruby with RVM

    In this step, we will upgrade the RVM package to the latest version and install the latest stable version of Ruby, and make it the standard Ruby version on our system.

    Upgrade RVM to the latest stable version with the command below.

      rvm get stable --autolibs = enable 

    Then add "root" "user to the" rvm "group. In fact, the root user will be able to run the rvm command.

      usermod -a -G rvm root 

    Then install the latest stable version "Ruby 2.6" with the command rvm below.

      rvm install ruby-2.6 

    When the installation is complete, you will make Ruby 2.6 as the default Ruby version on the Debian system. [19659017] rvm - default use ruby-2.6

    Now check the installed version of Ruby with the command below.

      ruby ​​- version 

    As a result, the latest stable version of & # 39; Ruby 2.6 & # 39; installed via RVM and it is used by default Ruby on Debian 10. System

     Installing Ruby on Debian

    Step 3 - Install Nodejs and Yarn

    In this step we install Nodejs and Yarn in The Debian system will be used by Rails to process JavaScript-fi

    First install the Debian system development tools using the apt command below.

      sudo apt install gcc g ++ make 

    Then add the Nodesource archive for Nodejs 12.

      curl -sL https://deb.nodesource.com/setup_12.x | bash - 

    Then add the yarn GPG key and 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.listebrit19659018 ?? Update and update all repositories and install NodeJS and Yarn with the apt command below.

      sudo apt update 
    sudo apt install -y nodejs yarn

    When installation is complete, check using the command below.

      node --version 
    yarn --version

    As a result, Nodej's JavaScript Runtime and Yarn package manager have been installed on Debian Buster 10.

     Install NodeJS and Yarn

    Step 4 - Upgrade RubyGem (Ruby Package Manager)

    RubyGems is a Ruby Package Manager that comes with the clip command line tool and installs automatically when we install Ruby on the system. For this step, we will upgrade RubyGem to the latest version.

    Upgrade RubyGem with the command below.

      gem update - system 

    When finished, check the gem version with the command below. [19659017] gem -v

    As a result, RubyGem has been upgraded to the latest version.

    Optional:

    RubyGem is a package manager for installing Ruby packages. It will install the Ruby packages and its documentation.

    To make the installation of Ruby packages small, you can disable the installation of the Ruby package documentation through the RubyGem configuration.

    Add / create the gem option in the ~ / .gemrc configuration as below.

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

    As a result, RubyGem will only install the core package with Ruby packages without the documentation.

    Step 5 - Installing Ruby on Rails Stable

    In this step we will install Ruby on Rails on the Debian system. We will install the latest version of Ruby on Rails v6.0.2.1.

    Install Ruby on Rails with the RubyGem command as below.

      gem install rails -v 6.0.2 

    When installation is complete, check the rails command as below.

      rails -v 

    As a result, Ruby on Rails 6.0.2.1 has been installed on Debian Buster 10. And you are ready to launch a new application with Rails. [19659002]   Installing Ruby on Rails

    Step 6 - Installing and configuring PostgreSQL database

    For this tutorial, we will use PostgreSQL as a backend database for Ruby on Rails.

    Install PostgreSQL to the Debian system with the apt command below.

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

    When the installation is complete, start the PostgreSQL service and add it to the system boot.

      systemctl start postgresql 
    systemctl enable postgresql

    The PostgreSQL service is running.

     I install and configure PostgreSQL

    Then log into the PostgreSQL shell with the command below.

      sudo -i -u postgres psql 

    Change the password of the PostgreSQL user's postgres.

       password postgres 

    Enter the new password for & # 39; postgres & # 39; -användaren.

    Then create a new PostgreSQL role named & # 39; rails_dev & # 39; with the & # 39; CreateDB & # 39; permission and the password & # 39; aqwe123 & # 39; using the PostgreSQL query below. [19659017] create role rails_dev with created login password & # 39; aqwe123 & # 39 ;;

    The privileges & # 39; createb & # 39; allows the user & # 39; rails_dev & # 39; to create a new database for the Ruby on Rails project.

    Now all available users are on PostgreSQL with the command below.

       you 

    You get the user & # 39; rails_dev & # 39; with the & # 39; CreateDB & # 39; permissions to create databases.

     Add rails user to postgres

    Type " exit " to log out of the PostgreSQL shell.

    As a result, you have installed the PostgreSQL database on Debian buster 10. You have also created a new PostgreSQL role & # 39; rails_dev & # 39; with the & # 39; CreateDB & # 39; for the project & # 39; Ruby on Rails & # 39 ;.

    Step 7 - Start projects with Ruby on Rails

    In this step we create a new simple CRUD project with Ruby on Rails with PostgreSQL as a backend database.

    Start Rails project with PostgreSQL

    First start a new project named & # 39; myapp & # 39; using the rails command below.

      rails new myapp -d postgresql 

    It will generate project directory named & # 39; myapp & # 39; with PostgreSQL as a backend database.

    Now go to the "myapp" directory and edit the database configuration & # 39; config / database.yml & # 39;

      cd myapp / 
    vim config / database.yml

    In the "Development" section, add the PostgreSQL information configuration below.

      username: rails_dev 
    password: aqwe123
    host: localhost
    port: 5432

    In the "Test" section, add the PostgreSQL information configuration below.

      host: localhost 
    port: 5432
    username: rails_dev
    password: aqwe123

    Save and close.

    Then generate PostgreSQL database schema and make sure there is no error.

      rails db: setup 
    rails db: migrate

     Create Ruby on Rails project

    When all is done, start puma rails web server with the command below.

      rails s -b 149.28.140.6 -p 8080 

    The Ruby on Rails project is running on port & # 39; 8080 & # 39 ;.

    Open your web browser and enter the server IP address using port & # 39; 8080 & # 39 ;.

    http: //10.5.5.31: 8080 /

    You will get the default index.html page for the Rails project. In addition, it will detect your Rails deployment environment.

     Ruby on Rails (RoR) successfully installed

    As a result, you have created a new project with Ruby on Rails using PostgreSQL as a database backend.

    Create simple CRUD app

    Then we will generate the simple CRUD for our "myapp" project.

    Generate CRUD on Ruby on Rails with the command below.

      rails g scaffold Post title: string body: text 
    rake db: migrate

     Create Rails CRUD app

    Start the rails project with the command below.

      rails s -b 192.168.1.10 -p 8080 [19659018] Return to your browser and check your rail project with URL below. 

    http://10.5.5.31:8080/posts/

    Now you get the simple CRUD application as below.

     Test form

    The following is the result after a test score has been created.

     Test form submitted

    Fi Nally, the installation of Ruby on Rails with the PostgreSQL database on Debian Buster 10 has been successfully completed.


Source link