Install Ruby on Rails Server on CentOS 8 - CentLinux


Sunday, 26 April 2020

Install Ruby on Rails Server on CentOS 8

Install Ruby on Rails Server on CentOS 8

In this article, you will learn how to install Ruby on Rails Server on CentOS 8 and create and run a Ruby web application on the same Ruby on Rails server.


This Article Provides:


    What is Ruby on Rails? :

    Ruby on Rails, or Rails, is a server-side web application framework written in Ruby under the MIT License. Rails is a MVC (Model-View-Controller) framework, providing default structures for a database, a web service, and web pages. (Courtesy: Wikipedia)

    Ruby on Rails encourages and facilitates the use of web standards such as JSON and XML for data transfer; HTML, CSS and JavaScript for user interfacing.


    Environment Specification:

    We are using a CentOS 8 based virtual machine with following specifications.

    • CPU - 3.4 Ghz (2 cores)
    • Memory - 2 GB
    • Storage - 20 GB
    • Operating System - CentOS 8.0
    • Hostname –
    • IP Address - /24


    Update CentOS 8 Software Packages:

    Connect with as root user by using an SSH tool.

    Before starting any installation, it is a good practice to update your Linux distribution to the latest software packages.

    In CentOS, the software packages are uploaded in online yum repositories as soon as they got updated. Therefore, we can easily update our CentOS 8 server by using a single dnf command.

    [root@ruby-on-rails ~]# yum update ... Installed: kernel-4.18.0-147.8.1.el8_1.x86_64 kernel-core-4.18.0-147.8.1.el8_1.x86_64 kernel-modules-4.18.0-147.8.1.el8_1.x86_64 Removed: kernel-4.18.0-80.el8.x86_64 kernel-core-4.18.0-80.el8.x86_64 kernel-modules-4.18.0-80.el8.x86_64 Complete!

    Since, we frequently update our Linux distros, therefore, only a few packages are updated this time.


    Install Ruby on Rails Prerequisites on CentOS 8:

    Ruby on Rails requires some software packages. However, most of the dependencies are automatically resolved by the RVM (Ruby Version Manager) but there are some software packages that we have to install manually.

    The first dependency of Ruby on Rails is Git. Git is available in standard yum repository, therefore we can install git on CentOS 8 as follows.

    [root@ruby-on-rails ~]# dnf install -y git ... Installed: git-2.18.2-2.el8_1.x86_64 perl-IO-Socket-IP-0.39-5.el8.noarch perl-IO-Socket-SSL-2.066-3.el8.noarch perl-Mozilla-CA-20160104-7.el8.noarch git-core-2.18.2-2.el8_1.x86_64 git-core-doc-2.18.2-2.el8_1.noarch perl-Digest-1.17-395.el8.noarch perl-Digest-MD5-2.55-396.el8.x86_64 perl-Error-1:0.17025-2.el8.noarch perl-Git-2.18.2-2.el8_1.noarch perl-Net-SSLeay-1.88-1.el8.x86_64 perl-TermReadKey-2.37-7.el8.x86_64 perl-URI-1.73-3.el8.noarch perl-libnet-3.11-3.el8.noarch emacs-filesystem-1:26.1-5.el8.noarch perl-Carp-1.42-396.el8.noarch perl-Data-Dumper-2.167-399.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-MIME-Base64-3.15-396.el8.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-3.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 Complete!

    Some components of Ruby on Rails requires Node.js, therefore, we are also need to install it.

    Node.js is not available in standard yum repositories. However, Node.js can be installed from NodeSource yum repository.

    Add NodeSource yum repository in CentOS 8 server.

    [root@ruby-on-rails ~]# curl -sL | bash - ## Installing the NodeSource Node.js 12.x repo... ## Inspecting system... + rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release + uname -m ## Confirming "el8-x86_64" is supported... + curl -sLf -o /dev/null '' ## As yum will try to install Node.js from the AppStream repository instead of the NodeSource repository, the AppStream's version of Node.js has to be disabled. ## Run `sudo yum module enable -y nodejs` to reactivate the AppStream's Node.js repository. + yum module disable -y nodejs Last metadata expiration check: 23:08:51 ago on Sat 25 Apr 2020 12:52:37 PM PKT. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Disabling modules: nodejs Transaction Summary ================================================================================ Complete! ## Downloading release setup RPM... + mktemp + curl -sL -o '/tmp/tmp.mwRVNDdser' '' ## Installing release setup RPM... + rpm -i --nosignature --force '/tmp/tmp.mwRVNDdser' ## Cleaning up... + rm -f '/tmp/tmp.mwRVNDdser' ## Checking for existing installations... + rpm -qa 'node|npm' | grep -v nodesource ## Run `sudo yum install -y nodejs` to install Node.js 12.x and npm. ## You may also need development tools to build native addons: sudo yum install gcc-c++ make ## To install the Yarn package manager, run: curl -sL | sudo tee /etc/yum.repos.d/yarn.repo sudo yum install yarn

    Now, we can install Node.js on CentOS 8 with dnf command.

    [root@ruby-on-rails ~]# dnf install -y nodejs ... Installed: nodejs-2:12.16.2-1nodesource.x86_64 python2-pip-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch python2-setuptools-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64 python2-libs-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64 python2-pip-wheel-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch python2-setuptools-wheel-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch Complete!

    Besides Node.js, Ruby on Rails also required YARN (Package Manager). YARN is also provided by its official yum repository. Therefore, we are adding the YARN yum repository in CentOS 8.

    [root@ruby-on-rails ~]# curl -sL | tee /etc/yum.repos.d/yarn.repo [yarn] name=Yarn Repository baseurl= enabled=1 gpgcheck=1 gpgkey=

    Now, we can easily install yarn using dnf command.

    [root@ruby-on-rails ~]# dnf install -y yarn Yarn Repository 338 kB/s | 363 kB 00:01 Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: yarn noarch 1.22.4-1 yarn 1.2 M Transaction Summary ================================================================================ Install 1 Package Total download size: 1.2 M Installed size: 5.1 M Downloading Packages: yarn-1.22.4-1.noarch.rpm 979 kB/s | 1.2 MB 00:01 -------------------------------------------------------------------------------- Total 977 kB/s | 1.2 MB 00:01 warning: /var/cache/dnf/yarn-39eb54bf733530c3/packages/yarn-1.22.4-1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 6963f07f: NOKEY Yarn Repository 6.5 kB/s | 1.6 kB 00:00 Importing GPG key 0x6963F07F: Userid : "Yarn RPM Packaging <>" Fingerprint: 9A6F 73F3 4BEB 7473 4D8C 6914 9CBB B558 6963 F07F From : Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : yarn-1.22.4-1.noarch 1/1 Verifying : yarn-1.22.4-1.noarch 1/1 Installed: yarn-1.22.4-1.noarch Complete!


    Install MariaDB Server on CentOS 8:

    MariaDB Server 10.3 is available in standard yum repository, therefore, we are installing it using dnf command.

    [root@ruby-on-rails ~]# dnf install -y mariadb-server ... Installed: mariadb-devel-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-backup-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-gssapi-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-server-utils-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-common-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-connector-c-3.0.7-1.el8.x86_64 mariadb-connector-c-config-3.0.7-1.el8.noarch mariadb-connector-c-devel-3.0.7-1.el8.x86_64 mariadb-errmsg-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64 perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64 keyutils-libs-devel-1.5.10-6.el8.x86_64 krb5-devel-1.17-9.el8.x86_64 libcom_err-devel-1.44.6-3.el8.x86_64 libkadm5-1.17-9.el8.x86_64 libselinux-devel-2.9-2.1.el8.x86_64 libsepol-devel-2.9-1.el8.x86_64 libverto-devel-0.3.0-5.el8.x86_64 openssl-devel-1:1.1.1c-2.el8_1.1.x86_64 pcre2-devel-10.32-1.el8.x86_64 pcre2-utf16-10.32-1.el8.x86_64 pcre2-utf32-10.32-1.el8.x86_64 perl-Math-BigInt-1:1.9998.11-7.el8.noarch perl-Math-Complex-1.59-416.el8.noarch psmisc-23.1-3.el8.x86_64 zlib-devel-1.2.11-10.el8.x86_64 Complete!

    Enable and start MariaDB service.

    [root@ruby-on-rails ~]# systemctl enable --now mariadb.service Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/mariadb.service.

    Configure MariaDB server and set root user password using following command.

    [root@ruby-on-rails ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!

    We have successfully installed MariaDB Server on CentOS 8.


    Install RVM on CentOS 8:

    RVM (Ruby Version Manager) is a command line tool that allows you to easily install, manage work with multiple Ruby environments from interpreter to set of gems.

    We are installing RVM on CentOS 8 and later we will install Ruby by using RVM commandline.

    RVM is available in its official yum repository. Therefore, we need to add the RVM yum repository in CentOS 8.

    Before adding RVM yum repository, we are required to add the GPG key for the RVM repo as follows.

    [root@ruby-on-rails ~]# gpg --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB gpg: directory '/root/.gnupg' created gpg: keybox '/root/.gnupg/pubring.kbx' created gpg: key 105BD0E739499BDB: 8 signatures not checked due to missing keys gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <>" imported gpg: key 3804BB82D39DC0E3: 108 signatures not checked due to missing keys gpg: key 3804BB82D39DC0E3: public key "Michal Papis (RVM signing) <>" imported gpg: no ultimately trusted keys found gpg: Total number processed: 2 gpg: imported: 2

    If you face problem installing the GPG key, then you should refer to RVM official website.

    Now, we can install RVM as follows.

    [root@ruby-on-rails ~]# curl -sSL | bash -s stable Downloading Downloading gpg: Signature made Thu 26 Mar 2020 02:58:42 AM PKT gpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB gpg: Good signature from "Piotr Kuczynski <>" [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB GPG verified '/usr/local/rvm/archives/rvm-1.29.10.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete: * First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. * To start using RVM you need to run `source /etc/profile.d/` in all your open shell windows, in rare cases you need to reopen all shell windows. * Please do NOT forget to add your users to the rvm group. The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect! Thanks for installing RVM ð Please consider donating to our open collective to help us maintain RVM. ð Donate:

    However, we can also install latest stable Ruby and Rails along with the RVM. But we are installing each component separately for the sake of demonstration.

    RVM environment script has been copied to /etc/profile.d/ directory. To set the RVM environment for the current session, we need to execute it once.

    [root@ruby-on-rails ~]# source /etc/profile.d/

    RVM has been installed on CentOS 8.


    Install Ruby on CentOS 8:

    Check and resolve any missing prerequisites for Ruby by using the rvm command.

    [root@ruby-on-rails ~]# rvm requirements Checking requirements for centos. Installing requirements for centos. Installing required packages: patch, autoconf, automake, bison, bzip2, gcc-c++, libffi-devel, libtool, make, patch, readline-devel, ruby, sqlite-devel, glibc-headers, glibc-devel........................ Requirements installation successful.

    Check list of known versions of Ruby language.

    [root@ruby-on-rails ~]# rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.10] [ruby-]2.2[.10] [ruby-]2.3[.8] [ruby-]2.4[.9] [ruby-]2.5[.7] [ruby-]2.6[.5] [ruby-]2.7[.0] ruby-head # for forks use: rvm install ruby-head-<name> --url --branch 2.2 # JRuby jruby-1.6[.8] jruby-1.7[.27] jruby-9.1[.17.0] jruby[-] jruby-head # Rubinius rbx-1[.4.3] rbx-2.3[.0] rbx-2.4[.1] rbx-2[.5.8] rbx-3[.107] rbx-4[.12] rbx-head # TruffleRuby truffleruby[-20.0.0] # Opal opal # Minimalistic ruby implementation - ISO 30170:2012 mruby-1.0.0 mruby-1.1.0 mruby-1.2.0 mruby-1.3.0 mruby-1[.4.1] mruby-2.0.1 mruby-2[.1.0] mruby[-head] # Ruby Enterprise Edition ree-1.8.6 ree[-1.8.7][-2012.02] # Topaz topaz # MagLev maglev-1.0.0 maglev-1.1[RC1] maglev[-1.2Alpha4] maglev-head # Mac OS X Snow Leopard Or Newer macruby-0.10 macruby-0.11 macruby[-0.12] macruby-nightly macruby-head # IronRuby ironruby[-1.1.3] ironruby-head

    Install your required version of Ruby. We are installing MRI Ruby 2.7 as follows.

    [root@ruby-on-rails ~]# rvm install 2.7 Searching for binary rubies, this might take some time. No binary rubies available for: centos/8/x86_64/ruby-2.7.0. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for centos. Requirements installation successful. Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.7.0, this may take a while depending on your cpu(s)... ruby-2.7.0 - #downloading ruby-2.7.0, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 14.0M 100 14.0M 0 0 1134k 0 0:00:12 0:00:12 --:--:-- 1211k ruby-2.7.0 - #extracting ruby-2.7.0 to /usr/local/rvm/src/ruby-2.7.0..... ruby-2.7.0 - #configuring........................................................................ ruby-2.7.0 - #post-configuration.. ruby-2.7.0 - #compiling............................................................................................ ruby-2.7.0 - #installing.................. ruby-2.7.0 - #making binaries executable... Installed rubygems 3.1.2 is newer than 3.0.8 provided with installed ruby, skipping installation, use --force to force installation. ruby-2.7.0 - #gemset created /usr/local/rvm/gems/ruby-2.7.0@global ruby-2.7.0 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................ ruby-2.7.0 - #generating global wrappers....... ruby-2.7.0 - #gemset created /usr/local/rvm/gems/ruby-2.7.0 ruby-2.7.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.7.0 - #generating default wrappers....... ruby-2.7.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-2.7.0 - #complete Ruby was built without documentation, to build it run: rvm docs generate-ri

    By using RVM, we can install multiple Ruby environments on the same platform. Therefore, we need to set a default version in use.

    Set default version of Ruby language.

    [root@ruby-on-rails ~]# rvm use 2.7 --default Using /usr/local/rvm/gems/ruby-2.7.0

    Verify the current Ruby version.

    [root@ruby-on-rails ~]# ruby --version ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]

    Ruby language has been installed on CentOS 8.


    Install Ruby on Rails on CentOS 8:

    Now its time to install Rails on CentOS 8 server. We can do this conveniently by using the gem (Ruby Package Manager).

    [root@ruby-on-rails ~]# gem install rails Fetching concurrent-ruby-1.1.6.gem Fetching mini_portile2-2.4.0.gem Fetching nokogiri-1.10.9.gem Fetching crass-1.0.6.gem Fetching loofah-2.5.0.gem Fetching rails-html-sanitizer-1.3.0.gem Fetching rails-dom-testing-2.0.3.gem Fetching builder-3.2.4.gem Fetching erubi-1.9.0.gem Fetching actionview- Fetching actionpack- Fetching activemodel- Fetching activerecord- Fetching globalid-0.4.2.gem Fetching activejob- Fetching mini_mime-1.0.2.gem Fetching mail-2.7.1.gem Fetching actionmailer- Fetching nio4r-2.5.2.gem Fetching websocket-extensions-0.1.4.gem Fetching websocket-driver-0.7.1.gem Fetching actioncable- Fetching mimemagic-0.3.4.gem Fetching marcel-0.3.3.gem Fetching activestorage- Fetching actionmailbox- Fetching actiontext- Fetching thor-1.0.1.gem Fetching method_source-1.0.0.gem Fetching railties- Fetching sprockets-4.0.0.gem Fetching sprockets-rails-3.2.1.gem Fetching rails- Fetching thread_safe-0.3.6.gem Fetching zeitwerk-2.3.0.gem Fetching rack-2.2.2.gem Fetching i18n-1.8.2.gem Fetching activesupport- Fetching tzinfo-1.2.7.gem Fetching rack-test-1.1.0.gem Successfully installed concurrent-ruby-1.1.6 HEADS UP! i18n 1.1 changed fallbacks to exclude default locale. But that may break your application. If you are upgrading your Rails application from an older version of Rails: Please check your Rails app for 'config.i18n.fallbacks = true'. If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be 'config.i18n.fallbacks = [I18n.default_locale]'. If not, fallbacks will be broken in your app by I18n 1.1.x. If you are starting a NEW Rails application, you can ignore this notice. For more info see: Successfully installed i18n-1.8.2 Successfully installed thread_safe-0.3.6 Successfully installed tzinfo-1.2.7 Successfully installed zeitwerk-2.3.0 Successfully installed activesupport- Successfully installed rack-2.2.2 Successfully installed rack-test-1.1.0 Successfully installed mini_portile2-2.4.0 Building native extensions. This could take a while... Successfully installed nokogiri-1.10.9 Successfully installed crass-1.0.6 Successfully installed loofah-2.5.0 Successfully installed rails-html-sanitizer-1.3.0 Successfully installed rails-dom-testing-2.0.3 Successfully installed builder-3.2.4 Successfully installed erubi-1.9.0 Successfully installed actionview- Successfully installed actionpack- Successfully installed activemodel- Successfully installed activerecord- Successfully installed globalid-0.4.2 Successfully installed activejob- Successfully installed mini_mime-1.0.2 Successfully installed mail-2.7.1 Successfully installed actionmailer- Building native extensions. This could take a while... Successfully installed nio4r-2.5.2 Successfully installed websocket-extensions-0.1.4 Building native extensions. This could take a while... Successfully installed websocket-driver-0.7.1 Successfully installed actioncable- Successfully installed mimemagic-0.3.4 Successfully installed marcel-0.3.3 Successfully installed activestorage- Successfully installed actionmailbox- Successfully installed actiontext- Successfully installed thor-1.0.1 Successfully installed method_source-1.0.0 Successfully installed railties- Successfully installed sprockets-4.0.0 Successfully installed sprockets-rails-3.2.1 Successfully installed rails- Parsing documentation for concurrent-ruby-1.1.6 Installing ri documentation for concurrent-ruby-1.1.6 Parsing documentation for i18n-1.8.2 Installing ri documentation for i18n-1.8.2 Parsing documentation for thread_safe-0.3.6 Installing ri documentation for thread_safe-0.3.6 Parsing documentation for tzinfo-1.2.7 Installing ri documentation for tzinfo-1.2.7 Parsing documentation for zeitwerk-2.3.0 Installing ri documentation for zeitwerk-2.3.0 Parsing documentation for activesupport- Installing ri documentation for activesupport- Parsing documentation for rack-2.2.2 Installing ri documentation for rack-2.2.2 Parsing documentation for rack-test-1.1.0 Installing ri documentation for rack-test-1.1.0 Parsing documentation for mini_portile2-2.4.0 Installing ri documentation for mini_portile2-2.4.0 Parsing documentation for nokogiri-1.10.9 Installing ri documentation for nokogiri-1.10.9 Parsing documentation for crass-1.0.6 Installing ri documentation for crass-1.0.6 Parsing documentation for loofah-2.5.0 Installing ri documentation for loofah-2.5.0 Parsing documentation for rails-html-sanitizer-1.3.0 Installing ri documentation for rails-html-sanitizer-1.3.0 Parsing documentation for rails-dom-testing-2.0.3 Installing ri documentation for rails-dom-testing-2.0.3 Parsing documentation for builder-3.2.4 Installing ri documentation for builder-3.2.4 Parsing documentation for erubi-1.9.0 Installing ri documentation for erubi-1.9.0 Parsing documentation for actionview- Installing ri documentation for actionview- Parsing documentation for actionpack- Installing ri documentation for actionpack- Parsing documentation for activemodel- Installing ri documentation for activemodel- Parsing documentation for activerecord- Installing ri documentation for activerecord- Parsing documentation for globalid-0.4.2 Installing ri documentation for globalid-0.4.2 Parsing documentation for activejob- Installing ri documentation for activejob- Parsing documentation for mini_mime-1.0.2 Installing ri documentation for mini_mime-1.0.2 Parsing documentation for mail-2.7.1 Installing ri documentation for mail-2.7.1 Parsing documentation for actionmailer- Installing ri documentation for actionmailer- Parsing documentation for nio4r-2.5.2 Installing ri documentation for nio4r-2.5.2 Parsing documentation for websocket-extensions-0.1.4 Installing ri documentation for websocket-extensions-0.1.4 Parsing documentation for websocket-driver-0.7.1 Installing ri documentation for websocket-driver-0.7.1 Parsing documentation for actioncable- Installing ri documentation for actioncable- Parsing documentation for mimemagic-0.3.4 Installing ri documentation for mimemagic-0.3.4 Parsing documentation for marcel-0.3.3 Installing ri documentation for marcel-0.3.3 Parsing documentation for activestorage- Installing ri documentation for activestorage- Parsing documentation for actionmailbox- Installing ri documentation for actionmailbox- Parsing documentation for actiontext- Installing ri documentation for actiontext- Parsing documentation for thor-1.0.1 Installing ri documentation for thor-1.0.1 Parsing documentation for method_source-1.0.0 Installing ri documentation for method_source-1.0.0 Parsing documentation for railties- Installing ri documentation for railties- Parsing documentation for sprockets-4.0.0 Installing ri documentation for sprockets-4.0.0 Parsing documentation for sprockets-rails-3.2.1 Installing ri documentation for sprockets-rails-3.2.1 Parsing documentation for rails- Installing ri documentation for rails- Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, zeitwerk, activesupport, rack, rack-test, mini_portile2, nokogiri, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 68 seconds 40 gems installed

    Verify version of Rails.

    [root@ruby-on-rails ~]# rails -v Rails

    Ruby on Rails default service port is 3000/tcp. Therefore, we need to allow this port in Linux firewall.

    [root@ruby-on-rails ~]# firewall-cmd --permanent --add-port=3000/tcp success [root@ruby-on-rails ~]# firewall-cmd --reload success


    Install Required Ruby Gems on CentOS 8:

    We are installing mysql2 gem, for Ruby connectivity with MariaDB/MySQL database servers.

    [root@ruby-on-rails ~]# gem install mysql2 Fetching mysql2-0.5.3.gem Building native extensions. This could take a while... Successfully installed mysql2-0.5.3 Parsing documentation for mysql2-0.5.3 Installing ri documentation for mysql2-0.5.3 Done installing documentation for mysql2 after 0 seconds 1 gem installed

    Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.

    We can install Bundler by using the gem command.

    [root@ruby-on-rails ~]# gem install bundler Fetching bundler-2.1.4.gem Successfully installed bundler-2.1.4 Parsing documentation for bundler-2.1.4 Installing ri documentation for bundler-2.1.4 Done installing documentation for bundler after 4 seconds 1 gem installed

    Our Ruby on Rails server is configured and ready to use now.


    HelloWorld - First Ruby Project:

    To test our Ruby on Rails environment, we are creating a HelloWorld Project.

    Following command will create the HelloWorld project directory with default skeleton of files and directories.

    [root@ruby-on-rails ~]# rails new HelloWorld -d mysql ... ââ serve-index@1.9.1 ââ serve-static@1.14.1 ââ sockjs-client@1.4.0 ââ sockjs@0.3.19 ââ spdy-transport@3.0.0 ââ spdy@4.0.2 ââ thunky@1.1.0 ââ type-is@1.6.18 ââ unpipe@1.0.0 ââ utils-merge@1.0.1 ââ wbuf@1.7.3 ââ webpack-dev-middleware@3.7.2 ââ webpack-dev-server@3.10.3 ââ websocket-extensions@0.1.3 ââ ws@6.2.1 ââ yargs-parser@11.1.1 ââ yargs@12.0.5 Done in 11.72s.

    Set MariaDB database credentials in the database.yml file.

    [root@ruby-on-rails ~]# cd HelloWorld [root@ruby-on-rails HelloWorld]# vi config/database.yml

    Under the default configurations set the root user password.

    default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: 123 # Set the MariaDB Password here socket: /var/lib/mysql/mysql.sock

    Create the database for our Ruby project by using rake command.

    [root@ruby-on-rails HelloWorld]# rake db:create /usr/local/rvm/gems/ruby-2.7.0/gems/actionpack- warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/local/rvm/gems/ruby-2.7.0/gems/actionpack- warning: The called method `initialize' is defined here Created database 'HelloWorld_development' Created database 'HelloWorld_test'

    Start our Ruby on Rails application.

    [root@ruby-on-rails HelloWorld]# rails server -b Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`. The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`. => Booting Puma => Rails application starting in development => Run `rails server --help` for more startup options /usr/local/rvm/gems/ruby-2.7.0/gems/actionpack- warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/local/rvm/gems/ruby-2.7.0/gems/actionpack- warning: The called method `initialize' is defined here Puma starting in single mode... * Version 4.3.3 (ruby 2.7.0-p0), codename: Mysterious Traveller * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp:// Use Ctrl-C to stop

    Browse URL in google chrome browser.


    We have successfully installed Ruby on Rails Server on CentOS 8.

    If you wish to learn more about the Ruby on Rails, then you should attend Ruby on Rails 6 Complete Beginner's Course [2020] at Udemy or read Agile Web Development with Rails 6 by Pragmatic Bookshelf.

    No comments:

    Post a comment