最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

CentOS 7下配置Ruby語(yǔ)言開(kāi)發(fā)環(huán)境的方法教程

 更新時(shí)間:2017年05月09日 11:41:46   作者:shaonbean  
對(duì)于新入門的開(kāi)發(fā)者,如何安裝 Ruby, Ruby Gems 和 Rails 的運(yùn)行環(huán)境可能會(huì)是個(gè)問(wèn)題,下面這篇文章主要給大家分享了在CentOS 7下配置Ruby語(yǔ)言開(kāi)發(fā)環(huán)境的方法教程,文中介紹的非常詳細(xì),需要的朋友們下面來(lái)一起看看吧。

本文跟大家分享的是在CentOS 7下配置Ruby語(yǔ)言開(kāi)發(fā)環(huán)境的方法教程,分享出來(lái)供大家參考學(xué)習(xí),下面來(lái)看看詳細(xì)的介紹:

安裝Ruby 2.2

CentOS7存儲(chǔ)庫(kù)中的Ruby版本為2.0,但如果需要,可以使用RPM軟件包安裝2.2

1、添加CentOS SCLo軟件集合存儲(chǔ)庫(kù)

[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-sclo install [Package]
# 安裝ruby
yum --enablerepo=centos-sclo-rh -y install rh-ruby22

2、軟件集合的軟件包安裝在/opt目錄下, 要使用它,需要加載環(huán)境變量,如下所示:

# 加載環(huán)境變量
[root@linuxprobe ~]# scl enable rh-ruby22 bash
[root@linuxprobe ~]# ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[root@linuxprobe ~]# which ruby
/opt/rh/rh-ruby22/root/usr/bin/ruby

3、設(shè)置登錄時(shí)自動(dòng)啟用Ruby 2.2,按如下所示進(jìn)行配置:

[root@linuxprobe ~]# vim /etc/profile.d/rh-ruby22.sh
#!/bin/bash
source /opt/rh/rh-ruby22/enable
export X_SCLS="`scl enable rh-ruby22 'echo $X_SCLS'`"
export PATH=$PATH:/opt/rh/rh-ruby22/root/usr/local/bin

安裝Ruby 2.3

# 安裝ruby
yum --enablerepo=centos-sclo-rh -y install rh-ruby23

1、軟件集合的軟件包安裝在/opt目錄下, 要使用它,需要加載環(huán)境變量,如下所示:

# 加載環(huán)境變量
[root@linuxprobe ~]# scl enable rh-ruby23 bash
[root@linuxprobe ~]# ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[root@linuxprobe ~]# which ruby
/opt/rh/rh-ruby22/root/usr/bin/ruby

2、設(shè)置登錄時(shí)自動(dòng)啟用Ruby 2.3,按如下所示進(jìn)行配置:

[root@linuxprobe ~]# vim /etc/profile.d/rh-ruby23.sh
#!/bin/bash
source /opt/rh/rh-ruby23/enable
export X_SCLS="`scl enable rh-ruby23 'echo $X_SCLS'`"
export PATH=$PATH:/opt/rh/rh-ruby23/root/usr/local/bin

安裝Ruby on Rails 4來(lái)構(gòu)建Ruby Framework環(huán)境

1、添加EPEL軟件存儲(chǔ)庫(kù)

[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、安裝Ruby 2.2,參考上面

2、安裝依賴包(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

安裝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 -v
Rails 4.2.8

Ruby on Rails 5

1、安裝Ruby 2.3,參考上面

2、安裝依賴包(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

安裝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 -v
Rails 5.0.2

創(chuàng)建一個(gè)示例應(yīng)用程序,并確保其正常工作

1、需要安裝MariaDB服務(wù)

[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 mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'

2、初始化MariaDB

[root@linuxprobe ~]# 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
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
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
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
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
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!

# connect to MariaDB with root
[root@linuxprobe ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (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 list
MariaDB [(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 list
MariaDB [(none)]> show databases;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| mysql    |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye

3、創(chuàng)建測(cè)試應(yīng)用程序

[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.yml
default: &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:create
Created 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 options
Puma 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:3000
Use Ctrl-C to stop 

4、客戶端訪問(wèn)http://10.1.1.53:3000/

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • ruby實(shí)現(xiàn)網(wǎng)頁(yè)圖片抓取

    ruby實(shí)現(xiàn)網(wǎng)頁(yè)圖片抓取

    本文給大家分享的是個(gè)人使用ruby編寫的抓取網(wǎng)頁(yè)圖片的代碼,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
    2015-06-06
  • 詳解Ruby中的異常

    詳解Ruby中的異常

    這篇文章主要介紹了詳解Ruby中的異常,異常的拋出和處理是各種編程語(yǔ)言學(xué)習(xí)中基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-04-04
  • Monkey Patch猴子補(bǔ)丁編程方式及其在Ruby中的運(yùn)用

    Monkey Patch猴子補(bǔ)丁編程方式及其在Ruby中的運(yùn)用

    Monkey Patch是指在程序運(yùn)行時(shí)追加代碼段,一般被認(rèn)為是解釋型語(yǔ)言的特長(zhǎng),下面我們就來(lái)看一下Monkey Patch猴子補(bǔ)丁編程方式及其在Ruby中的運(yùn)用
    2016-05-05
  • 安裝Ruby和安裝Rails詳細(xì)步驟詳解

    安裝Ruby和安裝Rails詳細(xì)步驟詳解

    這篇文章主要介紹了安裝Ruby和安裝Rails詳細(xì)步驟詳解,包括解決rbenv安裝慢,更新rbenv的ruby版本列表,多版本ruby共存,需要的朋友可以參考下
    2022-04-04
  • Java 版的 Ruby 解釋器 JRuby 1.7.14 發(fā)布

    Java 版的 Ruby 解釋器 JRuby 1.7.14 發(fā)布

    JRuby,一個(gè)采用純Java實(shí)現(xiàn)的Ruby解釋器,由JRuby團(tuán)隊(duì)開(kāi)發(fā)。它是一個(gè)自由軟件,在CPL/GPL/LGPL三種許可協(xié)議下發(fā)布。
    2014-08-08
  • Ruby語(yǔ)言建立Web服務(wù)器的過(guò)程詳解

    Ruby語(yǔ)言建立Web服務(wù)器的過(guò)程詳解

    這次選擇的Web服務(wù)器是Nginx,Nginx非常適合處理靜態(tài)資源,如圖片、CSS和JS文件,通過(guò)減輕應(yīng)用服務(wù)器的負(fù)擔(dān),Nginx使得Ruby?on?Rails應(yīng)用能夠更高效地運(yùn)行,這篇文章主要介紹了Ruby語(yǔ)言建立Web服務(wù)器,需要的朋友可以參考下
    2024-06-06
  • Ruby中g(shù)em包管理器的用法及用bundler來(lái)管理多版本的gem

    Ruby中g(shù)em包管理器的用法及用bundler來(lái)管理多版本的gem

    gem是Ruby環(huán)境中的包管理器,好比于Python中的pip與JavaScript本地Node.js的npm,非常有名和強(qiáng)大,下面就來(lái)看一下Ruby中g(shù)em包管理器的用法及用bundler來(lái)管理多版本的gem的方法:
    2016-05-05
  • ruby 流程控制 方法

    ruby 流程控制 方法

    ruby 流程控制 方法...
    2007-11-11
  • Ruby 迭代器及文件的輸入與輸出

    Ruby 迭代器及文件的輸入與輸出

    這篇文章主要介紹了Ruby的迭代器和文件的輸入輸出,文章中有詳細(xì)的代碼示例,需要的朋友可以參考閱讀一下
    2023-04-04
  • Ruby中使用Block、Proc、lambda實(shí)現(xiàn)閉包

    Ruby中使用Block、Proc、lambda實(shí)現(xiàn)閉包

    這篇文章主要介紹了Ruby中使用Block、Proc、lambda實(shí)現(xiàn)閉包,在編程領(lǐng)域我們可以通俗的說(shuō):子函數(shù)可以使用父函數(shù)中的局部變量,這種行為就叫做閉包,需要的朋友可以參考下
    2014-06-06

最新評(píng)論

开封县| 屯门区| 襄垣县| 永修县| 黄冈市| 奉贤区| 子长县| 华容县| 郧西县| 塘沽区| 夏津县| 玉门市| 木里| 青河县| 土默特右旗| 饶河县| 太康县| 乌鲁木齐市| 上饶市| 怀集县| 庆安县| 伽师县| 江城| 汉寿县| 固镇县| 玛多县| 郯城县| 东光县| 吕梁市| 永福县| 灵寿县| 马山县| 阿坝| 新邵县| 布尔津县| 潞西市| 广平县| 永丰县| 平凉市| 建湖县| 邹城市|