@@ -7,6 +7,13 @@ lang: zh_tw
7
7
有很多工具可以安裝 Ruby。本頁介紹如何使用主流的套件管理工具以及第三方工具來管理、安裝 Ruby 以及如何從原始碼來編譯 Ruby。
8
8
{: .summary}
9
9
10
+ 如果您已經在您的電腦上安裝了 Ruby。您可以在 [ terminal emulator] [ terminal ] 中執行以下指令確認:
11
+
12
+ {% highlight sh %}
13
+ ruby -v
14
+ {% endhighlight %}
15
+
16
+ 輸出結果應該會顯示已安裝的 Ruby 版本資訊。
10
17
11
18
## 選擇安裝方式
12
19
@@ -22,19 +29,26 @@ lang: zh_tw
22
29
* [ 套件管理系統] ( #package-management-systems )
23
30
* [ Debian、Ubuntu] ( #apt )
24
31
* [ CentOS、Fedora、RHEL] ( #yum )
32
+ * [ Snap] ( #snap )
25
33
* [ Gentoo] ( #portage )
26
34
* [ Arch Linux] ( #pacman )
27
35
* [ macOS] ( #homebrew )
28
- * [ Solaris、OpenIndiana] ( #solaris )
29
- * [ 其他發行版] ( #other-systems )
36
+ * [ FreeBSD] ( #freebsd )
37
+ * [ OpenBSD] ( #openbsd )
38
+ * [ OpenIndiana] ( #openindiana )
39
+ * [ Windows Package Manager] ( #winget )
40
+ * [ Chocolatey package manager for Windows] ( #chocolatey )
41
+ * [ 其它發行版] ( #other-systems )
30
42
* [ 安裝工具] ( #installers )
31
43
* [ ruby-build] ( #ruby-build )
32
44
* [ ruby-install] ( #ruby-install )
33
45
* [ RubyInstaller] ( #rubyinstaller ) (Windows)
34
- * [ RailsInstaller 和 Ruby 安裝包 ] ( #railsinstaller )
46
+ * [ Ruby Stack ] ( #rubystack )
35
47
* [ 版本管理] ( #managers )
48
+ * [ asdf-vm] ( #asdf-vm )
36
49
* [ chruby] ( #chruby )
37
50
* [ rbenv] ( #rbenv )
51
+ * [ rbenv for Windows] ( #rbenv-for-windows )
38
52
* [ RVM] ( #rvm )
39
53
* [ uru] ( #uru )
40
54
* [ 從原始碼編譯] ( #building-from-source )
@@ -47,19 +61,31 @@ lang: zh_tw
47
61
48
62
許多 Ruby 社群的成員強烈建議不要使用套件管理工具來安裝 Ruby,應該使用下面羅列的工具來取代。完整的優缺點超出了本文的範疇,最簡單的理由是,多數的套件管理工具安裝的 Ruby 版本老舊,如果想要使用最新版的 Ruby,確認你安裝了正確名稱的套件,或使用下面其他的工具吧。
49
63
64
+ 本文包含以下套件管理工具說明:
65
+
66
+ * [ Debian, Ubuntu] ( #apt )
67
+ * [ CentOS, Fedora,RHEL] ( #yum )
68
+ * [ Snap] ( #snap )
69
+ * [ Gentoo] ( #portage )
70
+ * [ Arch Linux] ( #pacman )
71
+ * [ macOS] ( #homebrew )
72
+ * [ FreeBSD] ( #freebsd )
73
+ * [ OpenBSD] ( #openbsd )
74
+ * [ OpenIndiana] ( #openindiana )
75
+ * [ Windows Package manager] ( #winget )
76
+ * [ Chocolatey package manager for Windows] ( #chocolatey )
77
+ * [ Other Distribution] ( #other-systems )
50
78
51
79
### apt(Debian 或 Ubuntu)
52
80
{: #apt}
53
81
54
- Debian GNU/Linux 和 Ubuntu 的使用者可以使用 apt。
82
+ Debian GNU/Linux 和 Ubuntu 的使用者可以使用 apt 套件管理工具 。
55
83
用法:
56
84
57
85
{% highlight sh %}
58
- $ sudo apt-get install ruby
86
+ $ sudo apt-get install ruby-full
59
87
{% endhighlight %}
60
88
61
- 撰文當下 ` ruby ` 套件在 Debian 與 Ubuntu 平台上所提供的版本是老舊的穩定版 Ruby 2.3.1。
62
-
63
89
64
90
### yum(CentOS、Fedora 或 RHEL)
65
91
{: #yum}
@@ -73,6 +99,23 @@ $ sudo yum install ruby
73
99
74
100
安裝的版本通常是作業系統發行版發行日所打包的最新版 Ruby。
75
101
102
+ ### snap (Ubuntu or other Linux distributions)
103
+ {: #snap}
104
+
105
+ Snap 是 Canonical 所開發的套件管理工具。內建於 Ubuntu,但 snap 也能在許多其他的 Linux 發行版上使用。
106
+ 用法:
107
+
108
+ {% highlight sh %}
109
+ $ sudo snap install ruby --classic
110
+ {% endhighlight %}
111
+
112
+ 我們為每個 Ruby 小版本提供了幾個 channel。
113
+ 例如,使用以下指令切換到 Ruby 2.3:
114
+
115
+ {% highlight sh %}
116
+ $ sudo snap switch ruby --channel=2.3/stable
117
+ $ sudo snap refresh
118
+ {% endhighlight %}
76
119
77
120
### portage(Gentoo)
78
121
{: #portage}
@@ -83,7 +126,7 @@ Gentoo 使用 portage 套件管理工具。
83
126
$ sudo emerge dev-lang/ruby
84
127
{% endhighlight %}
85
128
86
- 預設會試著安裝 1.9 和 2.0,但還能安裝更多版本。 要安裝特定版本,在 ` make.conf ` 設定 ` RUBY_TARGETS ` 。進一步了解請參考 [ Gentoo Ruby 專案網站] [ gentoo-ruby ] 。
129
+ 要安裝特定版本,在 ` make.conf ` 設定 ` RUBY_TARGETS ` 。進一步了解請參考 [ Gentoo Ruby 專案網站] [ gentoo-ruby ] 。
87
130
88
131
89
132
### pacman (Arch Linux)
@@ -102,39 +145,81 @@ $ sudo pacman -S ruby
102
145
### Homebrew(macOS)
103
146
{: #homebrew}
104
147
105
- OS X El Capitan、Yosemite 以及 Mavericks 內建 Ruby 2.0。
106
- OS X Mountain Lion、Lion 以及 Snow Leopard 出廠內建 Ruby 1.8.7。
148
+ 從 macOS El Capitan(10.11) 以上內建 Ruby 2.0 以上版本。
107
149
108
- macOS 的使用者使用 [ Homebrew] [ homebrew ] 作為套件管理工具。
150
+ macOS 使用者多數使用 [ Homebrew] [ homebrew ] 作為套件管理工具。
109
151
用法:
110
152
111
153
{% highlight sh %}
112
154
$ brew install ruby
113
155
{% endhighlight %}
114
156
115
- 會安裝最新穩定版的 Ruby。
157
+ 會安裝最新版的 Ruby。
158
+
159
+ ### FreeBSD
160
+ {: #freebsd}
161
+
162
+ FreeBSD 提供以預編譯和從原始碼編譯的方法安裝 Ruby。
163
+ 預編譯的套件可以透過 pkg 工具安裝:
164
+
165
+ {% highlight sh %}
166
+ $ pkg install ruby
167
+ {% endhighlight %}
116
168
169
+ 從原始碼編譯的方法可以透過使用 [ Ports Collection] [ freebsd-ports-collection ] 來安裝 Ruby。
170
+ 當您想要客製化建置設定選項時,這非常好用。
117
171
118
- ### Solaris 和 OpenIndiana 平台
119
- {: #solaris}
172
+ 更多在 FreeBSD 上使用 Ruby 與其生態系的資訊,請參考 [ FreeBSD Ruby Project website] [ freebsd-ruby ] 。
120
173
121
- [ Sunfreeware] [ sunfreeware ] 上的 Solaris 8 到 10 版有 Ruby 1.8.7 可用,同時 Blastwave 上也有 Ruby 1.8.7。Ruby 1.9.2p0 在 [ Sunfreeware] [ sunfreeware ] 也有,但版本已經過時了。
174
+ ### OpenBSD
175
+ {: #openbsd}
122
176
123
- 要在 [ OpenIndiana] [ openindiana ] 安裝 Ruby,請使用:
124
- [ Image Packaging System (IPS)] [ opensolaris-pkg ] 客戶端。
125
- 這會直接從 OpenSolaris 網路的原始碼庫安裝最新的 Ruby 1.9 以及 RubyGems:
177
+ OpenBSD 在發行版本 adJ 中有三個主要 Ruby 版本套件。以下指令可以看到可用的版本並進行安裝:
126
178
127
179
{% highlight sh %}
128
- $ pkg install runtime/ruby-18
180
+ $ doas pkg_add ruby
181
+ {% endhighlight %}
182
+
183
+ 您可以同時安裝多個主要版本,因為它們的執行檔的名稱不同 (例如:` ruby27 ` , ` ruby26 ` )。
184
+
185
+ OpenBSD ports collection 的 ` HEAD ` 分支可能會在最新的 Ruby 版本釋出幾天後,在該平台提供,請參考 [ 最新 ports collections 的 lang/ruby] [ openbsd-current-ruby-ports ] 。
186
+
187
+ ### Ruby on OpenIndiana
188
+ {: #openindiana}
189
+
190
+ 在 [ OpenIndiana] [ openindiana ] 上安裝 Ruby,請使用 Image Packaging System (IPS) 客戶端。
191
+ 這將會直接從 OpenIndiana repositories 安裝 Ruby 與 RubyGems。用法:
192
+
193
+ {% highlight sh %}
194
+ $ pkg install runtime/ruby
129
195
{% endhighlight %}
130
196
131
197
但用第三方工具來獲得最新版本 Ruby 可能比較好。
132
198
199
+ ### Windows Package Manager
200
+ {: #winget}
201
+
202
+ 在 Windows 上您可以使用 [ Windows Package Manager CLI] ( https://github.com/microsoft/winget-cli ) 來安裝 Ruby:
203
+
204
+ {% highlight sh %}
205
+ > winget install RubyInstallerTeam.Ruby
206
+ {% endhighlight %}
207
+
208
+ ### Chocolatey package manager for Windows
209
+ {: #chocolatey}
210
+
211
+ 在 Windows 上您也可以使用 [ Chocolatey Package Manager] ( https://chocolatey.org/install ) 來安裝 Ruby:
212
+
213
+ {% highlight sh %}
214
+ > choco install ruby
215
+ {% endhighlight %}
216
+
217
+ 它會使用現有的 ` msys2 ` 或是進行安裝以提供完整的 Ruby 開發環境。
133
218
134
219
### 其它發行版
135
220
{: #other-systems}
136
221
137
- 其它作業系統可以在發行版的套件庫上搜尋 Ruby,或是使用第三方工具可能會比較好 。
222
+ 其它作業系統可以在發行版的套件庫上搜尋 Ruby,或是使用 [ 第三方工具 ] ( #installers ) 可能會比較好 。
138
223
139
224
140
225
## 安裝工具
@@ -164,14 +249,11 @@ Windows 使用者,可以使用這個很棒的專案來幫助您安裝 Ruby:
164
249
下載、執行,即可!
165
250
166
251
167
- ### RailsInstaller 和 Ruby 安裝包
168
- {: #railsinstaller }
252
+ ### Ruby Stack
253
+ {: #rubystack }
169
254
170
255
若安裝 Ruby 是為了要開發 Ruby on Rails,則可用下列的安裝工具:
171
256
172
- * [ RailsInstaller] [ railsinstaller ] ,
173
- 背後使用的是 RubyInstaller,但帶有 Rails 開發環境所需的工具。
174
- 支援 OS X 與 Windows。
175
257
* [ Bitnami Ruby Stack] [ rubystack ] ,
176
258
提供完整的 Rails 開發環境。
177
259
兼容 macOS、Linux、Windows、虛擬機器以及雲鏡像。
@@ -182,17 +264,26 @@ Windows 使用者,可以使用這個很棒的專案來幫助您安裝 Ruby:
182
264
183
265
許多 Rubyists 使用 Ruby 版本管理工具來管理多版本的 Ruby。版本管理工具有很多優點,但要注意 Ruby 官方並不提供技術支援。但要提的是每個工具背後的社群都非常有幫助。
184
266
267
+ ### asdf-vm
268
+ {: #asdf-vm}
269
+
270
+ [ asdf-vm] [ asdf-vm ] 是一個可擴展的版本管理工具,可基於個別專案來管理多語言執行版本。您需要 [ asdf-ruby] [ asdf-ruby ] 插件 (使用 [ ruby-build] [ ruby-build ] ) 來安裝 Ruby。
271
+
185
272
186
273
### chruby
187
274
{: #chruby}
188
275
189
- [ chruby] [ chruby ] 可以切換 Ruby 版本。chruby 可以管理由 [ ruby-install] ( #ruby-install ) 所安裝的 Ruby,或是從原始碼所編譯的 Ruby。
190
-
276
+ [ chruby] [ chruby ] 可以在系統上管理多個版本的 Ruby。chruby 本身無法安裝 Ruby 但可以透過插件像是 [ ruby-install] [ ruby-install ] 或 [ ruby-build] [ ruby-build ] 安裝 Ruby。支援 macOS、Linux 和其他類 UNIX 的作業系統。
191
277
192
278
### rbenv
193
279
{: #rbenv}
194
280
195
- [ rbenv] [ rbenv ] 可以在系統上安裝多個版本的 Ruby。rbenv 本身不能安裝 Ruby,但有一個流行的插件,叫做 ruby-build,可以用來安裝 Ruby。支援 macOS、Linux 和其它類 Unix 的作業系統。
281
+ [ rbenv] [ rbenv ] 可以在系統上管理多個版本的 Ruby。rbenv 本身不能安裝 Ruby,但可以使用插件 [ ruby-build] [ ruby-build ] 安裝 Ruby。支援 macOS、Linux 和其它類 Unix 的作業系統。
282
+
283
+ ### rbenv for Windows
284
+ {: #rbenv-for-windows}
285
+
286
+ [ rbenv for Windows] [ rbenv-for-windows ] 可以在 Windows 作業系統上安裝多個版本的 Ruby。它是用 PowerShell 撰寫並提供 Windows 使用者原生方法來使用 Ruby。使用方式相容於在類 Unix 的作業系統上的 [ rbenv] [ rbenv ] 。
196
287
197
288
198
289
### RVM ("Ruby Version Manager")
@@ -221,20 +312,29 @@ $ sudo make install
221
312
222
313
預設會安裝 Ruby 到 ` /usr/local ` 目錄。要更改安裝目錄請在使用 ` ./configure ` 腳本時傳入 ` --prefix=DIR ` 選項。
223
314
315
+ 您可以在 [ Building Ruby instructions] [ building-ruby ] 找到更多關於從原始碼編譯的資訊。
316
+
224
317
使用第三方工具或套件管理工具來安裝可能比較好,因為從原始碼編譯安裝的 Ruby 無法用任何工具管理。
225
318
226
319
227
320
[ rvm ] : http://rvm.io/
228
- [ rbenv ] : https://github.com/rbenv/rbenv#readme
321
+ [ rbenv ] : https://github.com/rbenv/rbenv
322
+ [ rbenv-for-windows ] : https://github.com/ccmywish/rbenv-for-windows#readme
229
323
[ ruby-build ] : https://github.com/rbenv/ruby-build#readme
230
324
[ ruby-install ] : https://github.com/postmodern/ruby-install#readme
231
- [ chruby ] : https://github.com/postmodern/chruby#readme
232
- [ uru ] : https://bitbucket.org/jonforums/uru
325
+ [ chruby ] : https://github.com/postmodern/chruby
326
+ [ uru ] : https://bitbucket.org/jonforums/uru/src/master/
233
327
[ rubyinstaller ] : https://rubyinstaller.org/
234
- [ railsinstaller ] : http://railsinstaller.org/
235
328
[ rubystack ] : http://bitnami.com/stack/ruby/installer
236
- [ sunfreeware ] : http://www.sunfreeware.com
237
329
[ openindiana ] : http://openindiana.org/
238
330
[ opensolaris-pkg ] : http://opensolaris.org/os/project/pkg/
239
331
[ gentoo-ruby ] : http://www.gentoo.org/proj/en/prog_lang/ruby/
332
+ [ freebsd-ruby ] : https://wiki.freebsd.org/Ruby
333
+ [ freebsd-ports-collection ] : https://docs.freebsd.org/en/books/handbook/ports/#ports-using
240
334
[ homebrew ] : http://brew.sh/
335
+ [ terminal ] : https://en.wikipedia.org/wiki/List_of_terminal_emulators
336
+ [ building-ruby ] : https://github.com/ruby/ruby/blob/master/doc/contributing/building_ruby.md
337
+ [ wsl ] : https://learn.microsoft.com/zh-tw/windows/wsl/about
338
+ [ asdf-vm ] : https://asdf-vm.com/
339
+ [ asdf-ruby ] : https://github.com/asdf-vm/asdf-ruby
340
+ [ openbsd-current-ruby-ports ] : https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/lang/ruby/?only_with_tag=HEAD
0 commit comments