一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Ruby - CentOS 7下配置Ruby語言開發環境的方法教程

CentOS 7下配置Ruby語言開發環境的方法教程

2020-05-12 10:29shaonbean Ruby

對于新入門的開發者,如何安裝 Ruby, Ruby Gems 和 Rails 的運行環境可能會是個問題,下面這篇文章主要給大家分享了在CentOS 7下配置Ruby語言開發環境的方法教程,文中介紹的非常詳細,需要的朋友們下面來一起看看吧。

本文跟大家分享的是在CentOS 7下配置Ruby語言開發環境的方法教程,分享出來供大家參考學習,下面來看看詳細的介紹:

安裝Ruby 2.2

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

1、添加CentOS SCLo軟件集合存儲庫

?
1
2
3
4
5
6
7
8
9
10
11
12
[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目錄下, 要使用它,需要加載環境變量,如下所示:

?
1
2
3
4
5
6
# 加載環境變量
[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、設置登錄時自動啟用Ruby 2.2,按如下所示進行配置:

?
1
2
3
4
5
[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

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

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

?
1
2
3
4
5
6
# 加載環境變量
[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、設置登錄時自動啟用Ruby 2.3,按如下所示進行配置:

?
1
2
3
4
5
[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來構建Ruby Framework環境

1、添加EPEL軟件存儲庫

?
1
2
3
4
5
6
7
[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)

?
1
[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

?
1
2
3
4
5
[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)

?
1
[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

?
1
2
3
4
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

創建一個示例應用程序,并確保其正常工作

1、需要安裝MariaDB服務

?
1
2
3
4
5
6
7
8
[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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
[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、創建測試應用程序

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[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、客戶端訪問http://10.1.1.53:3000/

CentOS 7下配置Ruby語言開發環境的方法教程

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。

原文鏈接:http://blog.csdn.net/wh211212/article/details/70060854

延伸 · 閱讀

精彩推薦
  • Ruby剖析 Ruby 訪問控制

    剖析 Ruby 訪問控制

    前面,我們說 Ruby 沒有函數,只有方法.而且實際上有不止一種方法.這一節我們介紹 訪問控制 (accesscontrols). 想想當我們在最高層而不是在一個類的定義里定義...

    ruby教程網3572020-04-08
  • RubyRuby簡潔學習筆記(一):字符串、數字、類和對象

    Ruby簡潔學習筆記(一):字符串、數字、類和對象

    這篇文章主要介紹了Ruby簡潔學習筆記(一):字符串、數字、類和對象,本文是學習筆記第一篇,需要的朋友可以參考下 ...

    腳本之家2472020-04-20
  • RubyRuby迭代器的7種技巧分享

    Ruby迭代器的7種技巧分享

    這篇文章主要介紹了Ruby迭代器的7種技巧分享,Ruby中的迭代器非常人性化,本文既是講解了7個技巧也是講解了7種迭代器,需要的朋友可以參考下 ...

    腳本之家4782020-04-20
  • Ruby簡要說明Ruby中的迭代器

    簡要說明Ruby中的迭代器

    這篇文章主要介紹了Ruby中的迭代器,迭代器的概念在動態語言的編程中十分重要,文章中介紹了Ruby中的each迭代器和collect迭代器,需要的朋友可以參考下 ...

    goldensun2772020-04-25
  • RubyRuby環境下安裝使用bundler來管理多版本的gem

    Ruby環境下安裝使用bundler來管理多版本的gem

    這篇文章主要介紹了Ruby環境下安裝使用bundler來管理多版本的gem的方法,舉了Ruby On Rails中的應用實例來進行演示,需要的朋友可以參考下 ...

    日拱一卒4332020-05-10
  • RubyCentOS中配置Ruby on Rails環境

    CentOS中配置Ruby on Rails環境

    經過一個上午的折騰,終于把ROR環境在CentOS中搞定,繞了很多彎路,把文章寫下來總結一下 ...

    可樂加糖4762020-04-12
  • RubyRuby進行文件信息輸出實例代碼

    Ruby進行文件信息輸出實例代碼

    Ruby進行文件信息輸出實例代碼,數據是隨機的,所以每次的記錄都會不同。 ...

    ruby教程網2962020-04-10
  • RubyRuby設計模式編程中使用Builder建造者模式的實例

    Ruby設計模式編程中使用Builder建造者模式的實例

    這篇文章主要介紹了Ruby設計模式編程中使用Builder建造者模式的實例,建造者模式將一個復雜對象的構造與它的表示分離,使同樣的構建過程可以創建不同的表...

    范孝鵬2192020-05-07
主站蜘蛛池模板: 1024人成网站色 | 国产91精品在线观看 | 国产福利你懂的 | 午夜 在线播放 | 狠狠干狠狠插 | 天天av天天翘天天综合网 | 18日本xxxxxxⅹxx96 | 国产精品福利在线观看免费不卡 | 亚洲福利精品电影在线观看 | 70岁多老妇人特黄a级毛片 | 奇米9999 | 好大好深好涨好烫还要 | 美妇在男人胯下哀求 | 日本在线观看视频网站 | 精品视频一区二区三区免费 | 精品国产一区二区在线观看 | 日本高清中文字幕一区二区三区 | 国产精品毛片久久久久久久 | a级片欧美 | 99精品视频在线观看免费播放 | 久久亚洲精品AV成人无 | 男女肉粗暴进来下面好紧 | 色老板免费在线观看 | 91看片淫黄大片.在线天堂 | 欧美日韩精品亚洲精品v18 | 午夜家庭影院 | se婷婷| 国产3p在线| 性色欲情网站IWWW | 3x免费高清视频 | 俺去啦最新地址 | 操到翻白眼 | 国产 日韩 一区 | 垫底辣妹免费观看完整版 | 色中色导航 | 天天色天天舔 | 亚洲 日本 天堂 国产 在线 | 国产一区二区精品久久 | 国产日韩欧美综合在线 | 牧教师| 免费看男人使劲躁女人小说 |