@@ -11,8 +11,7 @@ next: /what-is-a-gem
11
11
The ` gem ` command allows you to interact with RubyGems.
12
12
13
13
Ruby 1.9 and newer ships with RubyGems built-in but you may need to upgrade for
14
- bug fixes or new features. To upgrade RubyGems or install it for the first
15
- time (if you need to use Ruby 1.9) visit the
14
+ bug fixes or new features. To upgrade RubyGems, visit the
16
15
[ download] ( https://rubygems.org/pages/download ) page.
17
16
18
17
If you want to see how to require files from a gem, skip ahead to [ What is a
@@ -37,11 +36,11 @@ expression characters in your query:
37
36
38
37
*** REMOTE GEMS ***
39
38
40
- rails (4 .0.0 )
39
+ rails (7 .0.3 )
41
40
rails-3-settings (0.1.1)
41
+ rails-acm (0.1.0)
42
42
rails-action-args (0.1.1)
43
- rails-admin (0.0.0)
44
- rails-ajax (0.2.0.20130731)
43
+ rails-action-authorization (1.1.2)
45
44
[...]
46
45
47
46
If you see a gem you want more information on you can add the details option.
@@ -52,9 +51,9 @@ with details requires downloading more files:
52
51
53
52
*** REMOTE GEMS ***
54
53
55
- rails (4 .0.0 )
54
+ rails (7 .0.3 )
56
55
Author: David Heinemeier Hansson
57
- Homepage: http ://www. rubyonrails.org
56
+ Homepage: https ://rubyonrails.org
58
57
59
58
Full-stack web application framework.
60
59
@@ -68,23 +67,23 @@ The `install` command downloads and installs the gem and any necessary
68
67
dependencies then builds documentation for the installed gems.
69
68
70
69
$ gem install drip
71
- Fetching: rbtree -0.4 .1.gem (100%)
72
- Building native extensions. This could take a while...
73
- Successfully installed rbtree-0.4.1
74
- Fetching: drip -0.0.2.gem (100%)
75
- Successfully installed drip-0.0.2
76
- Parsing documentation for rbtree-0.4.1
77
- Installing ri documentation for rbtree-0.4.1
78
- Parsing documentation for drip-0.0.2
79
- Installing ri documentation for drip-0.0.2
70
+ Fetching drip -0.1 .1.gem
71
+ Fetching rbtree-0.4.5.gem
72
+ Building native extensions. This could take a while...
73
+ Successfully installed rbtree -0.4.5
74
+ Successfully installed drip-0.1.1
75
+ Parsing documentation for rbtree-0.4.5
76
+ Installing ri documentation for rbtree-0.4.5
77
+ Parsing documentation for drip-0.1.1
78
+ Installing ri documentation for drip-0.1.1
80
79
Done installing documentation for rbtree, drip after 0 seconds
81
80
2 gems installed
82
81
83
82
Here the drip command depends upon the rbtree gem which has an extension. Ruby
84
83
installs the dependency rbtree and builds its extension, installs the drip gem,
85
84
then builds documentation for the installed gems.
86
85
87
- You can disable documentation generation using the ` --no-doc ` argument when
86
+ You can disable documentation generation using the ` --no-document ` argument when
88
87
installing gems.
89
88
90
89
Requiring code
@@ -93,31 +92,47 @@ Requiring code
93
92
RubyGems modifies your Ruby load path, which controls how your Ruby code is
94
93
found by the ` require ` statement. When you ` require ` a gem, really you're just
95
94
placing that gem's ` lib ` directory onto your ` $LOAD_PATH ` . Let's try this out
96
- in ` irb ` and get some help from the ` pretty_print ` library included with Ruby .
95
+ in ` irb ` .
97
96
98
- * Tip: Passing ` -r ` to
99
- ` irb ` will automatically require a library when irb is loaded.*
100
-
101
- % irb -rpp
102
- >> pp $LOAD_PATH
103
- [".../lib/ruby/site_ruby/1.9.1",
97
+ % irb
98
+ irb(main):001:0> pp $LOAD_PATH
99
+ [".../lib/ruby/site_ruby/3.1.0",
100
+ ".../lib/ruby/site_ruby/3.1.0/x86_64-linux",
104
101
".../lib/ruby/site_ruby",
105
- ".../lib/ruby/vendor_ruby/1.9.1",
102
+ ".../lib/ruby/vendor_ruby/3.1.0",
103
+ ".../lib/ruby/vendor_ruby/3.1.0/x86_64-linux",
106
104
".../lib/ruby/vendor_ruby",
107
- ".../lib/ruby/1.9.1 ",
108
- "."]
105
+ ".../lib/ruby/3.1.0 ",
106
+ ".../lib/ruby/3.1.0/x86_64-linux "]
109
107
110
108
By default you have just a few system directories on the load path and the Ruby
111
109
standard libraries. To add the awesome_print directories to the load path,
112
110
you can require one of its files:
113
111
114
- % irb -rpp
115
- >> require 'ap'
112
+ $ gem install awesome_print
113
+ [...]
114
+ $ irb
115
+ irb(main):001:0> require "ap"
116
116
=> true
117
- >> pp $LOAD_PATH.first
118
- ".../gems/awesome_print-1.0.2/lib"
119
-
120
- Note: For Ruby 1.8 you must ` require 'rubygems' ` before requiring any gems.
117
+ irb(main):002:0> pp $LOAD_PATH.first
118
+ ".../gems/awesome_print-1.9.2/lib"
119
+
120
+ * Tip: Passing ` -r ` to ` irb ` will automatically require a library when irb is
121
+ loaded.*
122
+
123
+ $ irb -rap
124
+ irb(main):001:0> ap $LOAD_PATH
125
+ [
126
+ [0] ".../bundle/gems/awesome_print-1.9.2/lib",
127
+ [1] ".../lib/ruby/site_ruby/3.1.0",
128
+ [2] ".../lib/ruby/site_ruby/3.1.0/x86_64-linux",
129
+ [3] ".../lib/ruby/site_ruby",
130
+ [4] ".../lib/ruby/vendor_ruby/3.1.0",
131
+ [5] ".../lib/ruby/vendor_ruby/3.1.0/x86_64-linux",
132
+ [6] ".../lib/ruby/vendor_ruby",
133
+ [7] ".../lib/ruby/3.1.0",
134
+ [8] ".../lib/ruby/3.1.0/x86_64-linux"
135
+ ]
121
136
122
137
Once you've required ` ap ` , RubyGems automatically places its
123
138
` lib ` directory on the ` $LOAD_PATH ` .
@@ -150,36 +165,45 @@ The `list` command shows your locally installed gems:
150
165
151
166
*** LOCAL GEMS ***
152
167
153
- bigdecimal (1.2.0)
154
- drip (0.0.2)
155
- io-console (0.4.2)
156
- json (1.7.7)
157
- minitest (4.3.2)
158
- psych (2.0.0)
159
- rake (0.9.6)
160
- rbtree (0.4.1)
161
- rdoc (4.0.0)
162
- test-unit (2.0.0.0)
168
+ abbrev (default: 0.1.0)
169
+ awesome_print (1.9.2)
170
+ base64 (default: 0.1.1)
171
+ benchmark (default: 0.2.0)
172
+ bigdecimal (default: 3.1.1)
173
+ bundler (default: 2.3.7)
174
+ cgi (default: 0.3.1)
175
+ csv (default: 3.2.2)
176
+ date (default: 3.2.2)
177
+ debug (1.4.0)
178
+ delegate (default: 0.2.0)
179
+ did_you_mean (default: 1.6.1)
180
+ digest (default: 3.1.0)
181
+ drb (default: 2.1.0)
182
+ drip (0.1.1)
183
+ english (default: 0.7.1)
184
+ [...]
163
185
164
- (Ruby ships with some gems by default, bigdecimal, io-console, json, minitest,
165
- psych, rake, rdoc, test-unit for ruby 2.0.0).
186
+ The list includes defaults gems and bundled gems both of which were shipped
187
+ with Ruby by default. In Ruby 3.1, the default gems are 70 gems in total
188
+ including bigdecimal, bundler, csv, did_you_mean etc. and the bundled gems are
189
+ debug, rake etc.
166
190
167
191
Uninstalling Gems
168
192
-----------------
169
193
170
194
The ` uninstall ` command removes the gems you have installed.
171
195
172
196
$ gem uninstall drip
173
- Successfully uninstalled drip-0.0.2
197
+ Successfully uninstalled drip-0.1.1
174
198
175
199
If you uninstall a dependency of a gem RubyGems will ask you for confirmation.
176
200
177
201
$ gem uninstall rbtree
178
202
179
203
You have requested to uninstall the gem:
180
- rbtree-0.4.1
204
+ rbtree-0.4.5
181
205
182
- drip-0.0.2 depends on rbtree (>= 0)
206
+ drip-0.1.1 depends on rbtree (>= 0)
183
207
If you remove this gem, these dependencies will not be met.
184
208
Continue with Uninstall? [yN] n
185
209
ERROR: While executing gem ... (Gem::DependencyRemovalException)
@@ -191,14 +215,14 @@ Viewing Documentation
191
215
You can view the documentation for your installed gems with ` ri ` :
192
216
193
217
$ ri RBTree
194
- RBTree < MultiRBTree
218
+ = RBTree < MultiRBTree
219
+
220
+ (from gem rbtree-0.4.5)
221
+ ------------------------------------------------------------------------
222
+ A sorted associative collection that cannot contain duplicate keys.
223
+ RBTree is a subclass of MultiRBTree.
224
+ ------------------------------------------------------------------------
195
225
196
- (from gem rbtree-0.4.0)
197
- -------------------------------------------
198
- A sorted associative collection that cannot
199
- contain duplicate keys. RBTree is a
200
- subclass of MultiRBTree.
201
- -------------------------------------------
202
226
203
227
Fetching and Unpacking Gems
204
228
---------------------------
@@ -211,7 +235,6 @@ If you wish to audit a gem's contents without installing it you can use the
211
235
Fetching: malice-13.gem (100%)
212
236
Downloaded malice-13
213
237
$ gem unpack malice-13.gem
214
- Fetching: malice-13.gem (100%)
215
238
Unpacked gem: '.../malice-13'
216
239
$ more malice-13/README
217
240
@@ -228,9 +251,9 @@ You can also unpack a gem you have installed, modify a few files, then use the
228
251
modified gem in place of the installed one:
229
252
230
253
$ gem unpack rake
231
- Unpacked gem: '.../rake-10.1.0 '
232
- $ vim rake-10.1.0 /lib/rake/...
233
- $ ruby -I rake-10.1.0 /lib -S rake some_rake_task
254
+ Unpacked gem: '.../13.0.6 '
255
+ $ vim 13.0.6 /lib/rake/...
256
+ $ ruby -I 13.0.6 /lib -S rake some_rake_task
234
257
[...]
235
258
236
259
The ` -I ` argument adds your unpacked rake to the ruby ` $LOAD_PATH ` which
0 commit comments