Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
The Gem Command6:04 with Jason Seifer
The gem command is used to manage your gem installation. In this video, we explore some of the different sub commands of ruby gems.
[SOUND] The Gem command does many things in addition to installing 0:00 Gems it can tell you what versions of the Gem are installed search for 0:06 Gems tell you about your environment and more. 0:12 Let's checkout the Gem command in a bit more depth now using workspaces. 0:16 Let's go ahead and see what the Gem command really does. 0:22 We can get a list of all the different commands inside of the Gem command by 0:26 typing gem help. 0:29 And it will show us exactly what Ruby Gems is. 0:32 What we need more is gem help commands. 0:37 And that will list all of the different Gem commands that we have to work with. 0:41 So we type that in, and we can see that we have 0:50 quite a few different things that we can do with Ruby Gems. 0:52 Now not all of them are going to apply to what we're doing in this course. 0:57 We're mainly looking at how to install and use gems. 1:01 However, if we were creating our own gems, Ruby Gems command gives us 1:05 a bunch of different options for working with them, such as build and certify. 1:10 Now the commands that we need to be cognizant of are gem check, 1:15 cleanup, environment, fetch, install, 1:22 list, outdated, pristine, and uninstall. 1:26 There's also the option to search gems as well as list gems. 1:31 So I'm gonna clear my screen here. 1:36 And if we want help on a gem command, we could say gem help and 1:39 then the name of the command. 1:44 Now, we're already kind of familiar with the install command. 1:47 If we say gem help install, it will show us different options for installation. 1:51 Now we can see there are quite a few flags that come along with install. 1:59 The most common one that we'll use is the -v flag which stands for 2:05 installing a specific version of a gem. 2:09 Another option that you'll use quite a bit is --no 2:13 document If you've been following along with this outside of work spaces, 2:18 you might have noticed that gems are being installed with documentation. 2:23 Now the documentation is another Ruby command that you can use 2:27 to get help with the gem. 2:32 Now, the kind of help that you'll get by using that, 2:36 is the same thing as looking at the documentation on a web page. 2:38 For speed, we've disabled the no document setting in work spaces. 2:43 Now we can also pass around the directory where binary files are located, 2:51 if that comes with a gem. 2:57 For the most part, we won't be using many of the different options. 3:00 In the case of a gem which you wanna install locally, as opposed to remotely. 3:05 You can use -l. 3:09 We didn't need to do that because the gem was in the same location as we were, 3:12 when we installed it. 3:16 Let's go ahead and look at the gem environment command. 3:20 This will tell you everything you need to know about Ruby Gems. 3:24 And if I scroll up here, we can see, this is our current Ruby Gems environment. 3:30 The version of Ruby Gems we're using in Workspaces is 2.2.2. 3:36 Our Ruby version is 2.1.5 and 3:40 this shows, where Gems will be installed. 3:43 For the purposes of work spaces, it's installed into the .local directory. 3:49 Don't be alarmed if this is different on your computer 3:55 if you're following along on your own computer. 3:59 And then we can see the other various options 4:03 That are occurring in our GEM environment. 4:06 Now I'm going to clear my screen here and type GEM list. 4:10 Now, the Gem list command, as you could assume from the name, 4:16 lists our installed lists. 4:20 And then, in parentheses, right after the name of the Gem, 4:23 is the version of the Gem that's currently installed. 4:28 If we go back, to the Ruby Money Gem, 4:31 we can see that there are other possible options for versions of this Gem. 4:36 So let's say we wanted to install version 6.6.0 We coud say gem 4:41 install money and then -v for version. 4:46 And the version number we want to install. 4:52 This would be useful in the case where an application that you're coding against 4:55 is built using an older version of the gem. 5:00 And the API might have changed. 5:03 Now we can see that that version of money was installed. 5:09 So if I clear my screen and then do gem list once again, 5:13 we can see that two versions now exist in our list. 5:17 If we had an old version of an gem installed, 5:22 we could use the update command to update a gem. 5:25 And we can see that this updated our rake gem to 10.4.2. 5:35 Now if we list it again, we can see that that installed the new version of rake, 5:42 and the old one is kept as well. 5:47 We could search for a gem just like on the Ruby Gems website. 5:55 And we could also install any of these that we see in the list. 6:00
You need to sign up for Treehouse in order to download course files.Sign up