1 00:00:00,760 --> 00:00:02,270 [treehouse presents] 2 00:00:03,220 --> 00:00:05,680 [Quick Tips] [How to Install Gems in Ruby on Rails] [by Jason Seifer] 3 00:00:06,140 --> 00:00:07,120 Hi, I'm Jason. 4 00:00:07,120 --> 00:00:11,250 In this treehouse quick tip, we're going to talk about how to install Ruby gems. 5 00:00:11,250 --> 00:00:15,670 A Ruby gem is a library that you can use in your Ruby applications. 6 00:00:15,670 --> 00:00:18,180 It's really easy to install a gem. 7 00:00:18,180 --> 00:00:21,630 You just need to know the name of the gem that you want to install. 8 00:00:21,630 --> 00:00:25,540 In this example, I'm going to install the Bundler gem. 9 00:00:25,540 --> 00:00:31,190 The way to install a gem is by typing the word "gem" followed by a space 10 00:00:31,190 --> 00:00:36,180 followed by the word "install" and then the name of the gem that you want to install. 11 00:00:36,180 --> 00:00:38,350 I'm going to install the Bundler gem. 12 00:00:38,350 --> 00:00:43,770 After that, press "enter" and then Ruby gems will go out, download the proper gem, 13 00:00:43,770 --> 00:00:45,550 and install it onto your system. 14 00:00:45,550 --> 00:00:50,220 If you get a message about not having the proper permissions to install a gem, 15 00:00:50,220 --> 00:00:54,060 you can use the "sudo" command to install the correct gem. 16 00:00:54,060 --> 00:01:00,430 You would use the "sudo" command on systems where your version of Ruby is installed 17 00:01:00,430 --> 00:01:06,990 globally rather than on a system like RVM or RBN where you can install gems locally 18 00:01:06,990 --> 00:01:08,210 to your own home directory. 19 00:01:08,210 --> 00:01:11,250 I'm going to install another gem called Money. 20 00:01:14,360 --> 00:01:18,480 The gem install command will also install any needed dependencies of a gem. 21 00:01:18,480 --> 00:01:24,630 For example, the Money gem requires the i18n gem and also the json gems. 22 00:01:24,630 --> 00:01:27,970 Once you install a gem, it's really easy to use. 23 00:01:27,970 --> 00:01:34,680 First, require Ruby gems, then you can also require the gem that you just installed. 24 00:01:36,660 --> 00:01:37,730 And there you go. 25 00:01:37,730 --> 00:01:42,140 There's one other way to install gems, and that would be from a gem file. 26 00:01:42,140 --> 00:01:48,450 A gem file will be in a Ruby on Rails application or actually any Ruby application 27 00:01:48,450 --> 00:01:49,590 that uses Bundler. 28 00:01:49,590 --> 00:01:54,580 You specify the gem dependencies in the gem file, and then once you do that, 29 00:01:54,580 --> 00:02:01,290 you can type the word "bundle install" and then Bundler will go through and install 30 00:02:01,290 --> 00:02:02,710 all of these gems for you. 31 00:02:09,220 --> 00:02:12,720 As you can see, it's very easy to install and use Ruby gems. 32 00:02:12,720 --> 00:02:15,480 The hardest part is finding good ones to install. 33 00:02:15,480 --> 00:02:19,780 Luckily, there are sites like RubyGems.org and GitHub for that. 34 00:02:19,780 --> 00:02:21,620 Happy coding!