How to configure the Ruby development environment in CentOS 7, centosruby
This article will share with you a tutorial on how to configure the Ruby development environment in CentOS 7 for your reference. Here is a detailed introduction:
Install Ruby 2.2
The Ruby version in the CentOS7 repository is 2.0, but if necessary, you can use the RPM package to install 2.2
1. Add a collection repository of CentOS SCLo Software
[Root @ linuxprobe ~] # Yum-y install centos-release-scl-rh centos-release-scl # set [priority = 10] [root @ linuxprobe ~] # Sed-I-e "s/\] $/\] \ npriority = 10/g"/etc/yum. repos. d/CentOS-SCLo-scl.repo [root @ linuxprobe ~] # Sed-I-e "s/\] $/\] \ npriority = 10/g"/etc/yum. repos. d/CentOS-SCLo-scl-rh.repo # for another way, change to [enabled = 0] and use it only when needed [root @ linuxprobe ~] # Sed-I-e "s/enabled = 1/enabled = 0/g"/etc/yum. repos. d/CentOS-SCLo-scl.repo [root @ linuxprobe ~] # Sed-I-e "s/enabled = 1/enabled = 0/g"/etc/yum. repos. d/CentOS-SCLo-scl-rh.repo # if [enabled = 0], input a command to use the repository [root @ linuxprobe ~] # Yum -- enablerepo = centos-sclo-rh install [Package] [root @ linuxprobe ~] # Yum -- enablerepo = centos-sclo install [Package] # install rubyyum -- enablerepo = centos-sclo-rh-y install rh-ruby22
2. The software package of the software set is installed in the/opt directory. to use it, you need to load the environment variable, as shown below:
# Loading environment variables [root @ linuxprobe ~] # Scl enable rh-ruby22 bash [root @ linuxprobe ~] # Ruby-vruby 2.2.2p95 (revision 50295) [x86_64-linux] [root @ linuxprobe ~] # Which ruby/opt/rh/rh-ruby22/root/usr/bin/ruby
3. Set Ruby 2.2 to be automatically enabled during logon, as shown in the following figure:
[root@linuxprobe ~]# vim /etc/profile.d/rh-ruby22.sh#!/bin/bashsource /opt/rh/rh-ruby22/enableexport X_SCLS="`scl enable rh-ruby22 'echo $X_SCLS'`"export PATH=$PATH:/opt/rh/rh-ruby22/root/usr/local/bin
Install Ruby 2.3
# Install rubyyum -- enablerepo = centos-sclo-rh-y install rh-ruby23
1. The software package of the software set is installed in the/opt directory. to use it, you need to load the environment variable, as shown below:
# Loading environment variables [root @ linuxprobe ~] # Scl enable rh-ruby23 bash [root @ linuxprobe ~] # Ruby-vruby 2.2.2p95 (revision 50295) [x86_64-linux] [root @ linuxprobe ~] # Which ruby/opt/rh/rh-ruby22/root/usr/bin/ruby
2. Set Ruby 2.3 to be automatically enabled during logon, as shown in the following figure:
[root@linuxprobe ~]# vim /etc/profile.d/rh-ruby23.sh#!/bin/bashsource /opt/rh/rh-ruby23/enableexport X_SCLS="`scl enable rh-ruby23 'echo $X_SCLS'`"export PATH=$PATH:/opt/rh/rh-ruby23/root/usr/local/bin
Install Ruby on Rails 4 to build the Ruby Framework Environment
1. Add an EPEL software Repository
[root@linuxprobe ~]# yum -y install epel-release# set [priority=5][root@linuxprobe ~]# sed -i -e "s/\]$/\]\npriority=5/g" /etc/yum.repos.d/epel.repo# for another way, change to [enabled=0] and use it only when needed[root@linuxprobe ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo# if [enabled=0], input a command to use the repository[root@linuxprobe ~]# yum --enablerepo=epel install [Package]
Ruby on Rails 4
1. Install Ruby 2.2. Refer to the above
2. Install the dependency package (epel + SCLo)
[root@linuxprobe ~]# yum --enablerepo=epel,centos-sclo-rh -y install rh-ruby22-ruby-devel nodejs libuv gcc make libxml2 libxml2-devel mariadb-devel zlib-devel libxslt-devel
Install Rails 4
[root@linuxprobe ~]# gem install bundler[root@linuxprobe ~]# gem install nokogiri -- --use-system-libraries[root@linuxprobe ~]# gem install rails --version="~>4.0" --no-ri --no-rdoc[root@linuxprobe ~]# /opt/rh/rh-ruby22/root/usr/local/bin/rails -vRails 4.2.8
Ruby on Rails 5
1. Install Ruby 2.3. Refer to the above
2. Install the dependency package (epel + SCLo)
[root@linuxprobe ~]# yum --enablerepo=epel,centos-sclo-rh -y install rh-ruby23-ruby-devel nodejs libuv gcc make libxml2 libxml2-devel mariadb-devel zlib-devel libxslt-devel
Install Rails 5
[root@linuxprobe ~]# gem install bundler[root@linuxprobe ~]# gem install nokogiri -- --use-system-libraries[root@linuxprobe ~]# gem install rails --no-ri --no-rdoc[root@linuxprobe ~]# rails -vRails 5.0.2
Create a sample application and make sure it works properly
1. Install the MariaDB Service
[root@linuxprobe ~]# yum -y install mariadb-server[root@linuxprobe ~]# vi /etc/my.cnf# add follows within [mysqld] section[mysqld]character-set-server=utf8[root@linuxprobe ~]# systemctl start mariadb[root@linuxprobe ~]# systemctl enable mariadbln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
2. initialize MariaDB
[root@linuxprobe ~]# mysql_secure_installationNOTE: 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 currentpassword for the root user. If you've just installed MariaDB, andyou 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 MariaDBroot user without the proper authorisation.# set root passwordSet root password? [Y/n] yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.# remove anonymous usersRemove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.# disallow root login remotelyDisallow root login remotely? [Y/n] y ... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.# remove test databaseRemove 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 farwill take effect immediately.# reload privilege tablesReload privilege tables now? [Y/n] y ... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!# connect to MariaDB with root[root@linuxprobe ~]# mysql -u root -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 11Server version: 5.5.52-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.# show user listMariaDB [(none)]> select user,host,password from mysql.user;+------+-----------+-------------------------------------------+| user | host | password |+------+-----------+-------------------------------------------+| root | localhost | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 || root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 || root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |+------+-----------+-------------------------------------------+3 rows in set (0.00 sec)# show database listMariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema |+--------------------+3 rows in set (0.00 sec)MariaDB [(none)]> exitBye
3. Create a test application
[root@linuxprobe ~]# gem install mysql2 --no-ri --no-rdoc -- --with-mysql-config=/usr/bin/mysql_config[root@linuxprobe ~]# rails new SampleApp -d mysql[root@linuxprobe ~]# cd SampleApp[root@linuxprobe SampleApp]# vi config/database.ymldefault: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: password # MariaDB password socket: /var/lib/mysql/mysql.sock# create test application[root@dlp SampleApp]# rails db:createCreated database 'SampleApp_development'Created database 'SampleApp_test'[root@dlp SampleApp]# rails generate scaffold testapp name:string title:string body:text[root@dlp SampleApp]# rails db:migrate[root@dlp SampleApp]# rails server --binding=0.0.0.0=> Booting Puma=> Rails 5.0.2 application starting in development on http://0.0.0.0:3000=> Run `rails server -h` for more startup optionsPuma starting in single mode...* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander* Min threads: 5, max threads: 5* Environment: development* Listening on tcp://0.0.0.0:3000Use Ctrl-C to stop
4. Access http: // 10.1.1.53: 3000/from the client/
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.