08.21.2019
How to install Ruby and Rails on Centos 7 via RPM
The version of Ruby in CentOS 7 repository is 2.0 but Install 2.2 with RPM package.
Install development packages.
[root@dlp ~]# yum -y groupinstall "Development Tools"
# install from EPEL
[root@dlp ~]# yum --enablerepo=epel -y install gdbm-devel libdb4-devel
libffi-devel libyaml libyaml-devel ncurses-devel openssl-devel readline-devel
tcl-devel
Download Ruby source and build RPM from it. Make sute the latest one and Download it from the site below.
⇒ https://www.ruby-lang.org/
The verion of it in this example is the latest Ruby 2.2.3 at Aug 2015 now.
[root@dlp ~]# mkdir -p
rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
# dowload source
[root@dlp
~]# wget http://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz -P
rpmbuild/SOURCES
# download SPEC file
[root@dlp
~]#
wget https://raw.githubusercontent.com/feedforce/ruby-rpm/master/ruby.spec
-P rpmbuild/SPECS --no-check-certificate[root@dlp ~]# rpmbuild -bb rpmbuild/SPECS/ruby22x.spec
[root@dlp ~]# rpm -Uvh rpmbuild/RPMS/x86_64/ruby-2.*.rpm
Preparing... #################################
[100%]
Updating / installing...
1:ruby-2.3.1-1.el7.centos ################################# [100%]
[root@dlp ~]# ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux-gnu]
[root@dlp ~]# gem -v
2.4.5.1
Install some other required packages.
# install from EPEL
[root@dlp ~]# yum --enablerepo=epel -y install nodejs mariadb-devel
Install Rails 4
[root@dlp ~]# gem install bundler
[root@dlp ~]# gem install rails --no-ri --no-rdoc
[root@dlp ~]# gem install mysql2 --no-ri --no-rdoc --
--with-mysql-config=/usr/bin/mysql_config
[root@dlp ~]# rails -v
Rails 4.2.4
Create a sample application and make sure it works normally.
[root@dlp ~]# rails new SampleApp -d mysql
[root@dlp ~]# cd SampleApp
[root@dlp SampleApp]# vi config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: password # MariaDB password
socket: /var/lib/mysql/mysql.sock
# create a sample app
[root@dlp SampleApp]# rake db:create:all
[root@dlp SampleApp]# rails generate scaffold testapp name:string title:string
body:text
[root@dlp SampleApp]# rake db:migrate
[root@dlp SampleApp]# rails server --binding=10.11.10.30
=> Booting WEBrick
=> Rails 4.2.3 application starting in development on
http://10.0.0.30:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-07-06 11:30:02] INFO WEBrick 1.3.1
[2015-07-06 11:30:02] INFO ruby 2.2.2 (2015-04-13) [x86_64-linux]
[2015-07-06 11:30:02] INFO WEBrick::HTTPServer#start: pid=13735
port=3000
Access to the "http://(server's hostname or IP address):3000/" from a client computer