 All right, there we go. So welcome to a little talk about managing our Ruby projects with RVM I'm going to try to go very quickly. There's an awful lot of stuff in actually in RVM at this point And I just can't cover in a half an hour. So we'll see what I can get through Okay, how many people have not heard of RVM raise your hands, please? All right. Good How many people are using RVM? All right, that's that's not bad How many tried it it didn't work and they're just not using it Find me later. All right. So what is it? RVM is essentially the Ruby version manager It's a command line tool. It allows you to type RVM at the command line with various options to do all kinds of kinky things with Ruby interpreters that are not quite natural So it allows you to do several things like installing multiple in Ruby interpreters versions of them patch levels and revisions It allows you to manage sets of gems for each of these installations Now Matt's managing at the systems level Environmental level not within your application. That is the better serve for things like bundler for example, which I recommend for Managing your gems inside of your applications beautiful for virtual environments Performing operations over installed interpreters and gem sets So if I have five different rubies installed and I want to do certain action against all of them RVM will allow you to do that and there are like I said a whole bunch of other items that you can do with it and Focus gun There we go the RVM website is RVM dot begin rescue end calm I'll leave it at the last slide. You can actually Check it out At the very bottom the screen is kind of constrained But there are a lot of things that RVM manages and does and this documentation is currently maybe 50% complete So of the functionalities that RVM will provide Okay, who am I? Well real quick. I had about 10 years of development experience and I went to work for Engine Yard I now work for a company called academic management systems doing admissions softwares and such things. I Have a partner a member in a company of division by zero and with two other people Mark Joseph and Bill Chapman down right brilliant folks I have four children all under the age of five makes things very interesting sleep Yeah, no I used to hack on mongrel MIRB a bunch of open-source projects I'd love to help out when I can if I have a clue of what there's somebody's doing Currently I heard hack on RVM BDSM DBM and UPM in that order of Activity so I really am obviously is the most active project and kind of sucks most of my time bash deployment and server manager you funny people So yeah RVM originally started October 2007 and I started with a conversation with a co-worker Jim Lindley best UI guy I've ever met in my life awesome and Essentially we had a problem where we had four applications and each one of those applications had to run on different your interpreter so we were using Ruby Enterprise Edition for One of our apps actually yeah one of our apps and the other app had to be on J Ruby and the other one was on A brand new app and we decided to go with 1.9 because the performance characteristics are just phenomenal and It was a hard problem I mean essentially we said okay the week it was August 21st 2009 towards the end of the day was talking with Jim and We just had three simple requirements And it's we wanted to be able to easily install the Ruby interpreters that we were going to using for these projects And we wanted to be able to easily switch between these three rubies and have the environments basically between development staging testing CI demo and production be identical and Yeah, I had like I said I had tried it in 2007 and I failed miserably it was It was a mess nothing worked and it was an extremely hard problem, and I loved the idea I thought it was a great idea, and I just didn't have it then so I'm very glad that Jim encouraged me to and try again basically and Because now we have RVM It stands today. So basically the day a day later after much thinking the night before and a furious day of hacking Changing diapers Basically our first checking was about 300 lines of bash code bash scripting now It's somewhere like 4,000 something lines of code, but it has an awful lot of functionality to it now And the first check-in actually worked it satisfied our three initial requirements It's pretty good So why did I use bash a lot of people ask this first of all it's installed on every unique system I've ever seen It allows me to bootstrap ruby I don't even have to have a system Ruby on our deployment servers for production and everything like that I actually deploy the entire I use RVM to install the rubies to Or as each user each user is essentially the project that's running Even we run like nginx and unicorn and the entire environment is self-contained in that user's directory of a project user And so it allows me to bootstrap everything from scratch with no ruby required It also allows bash. I mean when we're programming and we're doing like all the rake tasks I mean well, you're working in a shell I mean you're either using bash or ZSA ZSA H or maybe you smell a little fishy I mean all three of those should actually work at this point in time fish need a little modification But bash by doing this in bash It allows us to directly manipulate your environment that you're working in and that's what allows me to basically Have you guys so that you can type? RVM use Mac Ruby or something like that and be able to just type ruby gem all that stuff not Mac Ruby Mac gem And everything so it's a consistent API across every single interpreter Why would the heck would you want to use this thing? Well it Once it's installed mind you Properly it provides methods for running single command Against multiple Ruby environments at the same time So what am I talking about there? Let's look at a few quick examples Installing I've say they want to install 186 go Kirk 191 and j ruby all that in one go you just do this RVM 186 191 j ruby install and it will go through in that order and install those three interpreters into your RVM directory By the way RVM is self-contained it is by default if you install as a user not as root It's located in the dot RVM directory in your home So it's usually safe to you'll blow away all your gems too So you just have to reinstall but it's safe to just blow it away and start over fresh anytime you want So that's kind of nice So using a Ruby basically say okay I want to in my current shell use 1.9 RVM use 191 that'll switch to 191 Gem sets you can use the gem set feature of RVM to basically create a system-level directory of sets of gems for specific projects So you're messing around with rails 3 and you don't want that to affect your current work Right for your work you can use RVM to just completely self-contained that you're playing around with rails 3 So you can play around with rails 3 on JRuby you can play around with rails 3 on 1.9 And all the other interpreters that it might run on all at the same time And actually all the same time literally you can out up four or five shells have a gen you put a gem set in each shell Have each shell use a different Ruby and all at the same time be running rails 3 on every single interpreter for fun And later profit So RVM tests and somebody tried to convince me to call this test easy Not a good idea. Anyways RVM 186 191 JRuby that we just installed previously tests So let's say you're using shoda, which is awesome by the way And you want to run your tests, but you want to make sure your application is actually compatible with those three rubies that you've installed because this is what you're maybe you're have a JRuby reason you have to use it and You're on 186 in your production, but you I really want to get to 1.9 because it performs much better This is this will actually go through and run like basically rake test Against each of the rubies and there's different flags. You can read in the documentation to allow you to have Jason summary output or YAML summary output or just a human readable summary output instead of the massive spewing of Stuff that you know rake test usually does However, you don't lose the massive spewing of rake test that all gets logged to your current directory You know log slash the ruby version that it was in you know error log and Test log or something like that. You could check it out RVM monitor similar concept you can actually run RVM monitor and it what it does is it watches your test directory and Some something like auto-spec done stare steroids It is so it watches your user test directory you change a test and it will actually run your test suite Or actually I think it just currently it targets the test to run whatever test you changed against all three ruby interpreters And pro gives you feedback right away if anybody starts using that. Let me know it's I did it it worked for me, but You'll see later why I'm saying that RVM benchmark, so let's say you have a little chunk of code and you're like hey, huh? This would be cool to know how this runs in the different Rubies just take that chunk of code slap it in with any required statements that are necessary right above it in a blank file and my code that RV and Run the bench RVM benchmark command against it and it will run benchmark BM BM against those three and report the output Again, that's a feature that I was playing with so if somebody's interested in help, you know, I has ideas for it. See me We'd expand it Oh, he wants to know if you can like tweak the number of times it runs and stuff like that I think the answer is yes You just export an environment variable like n or something like that, but I'd have to look at my code again to remember You can use do rake actions So basically select your three rubies and you know rake do it all Whatever you're gonna do Installing rvm. There's about three or more ways to install rvm There's actually a lot of ways to install rvm since it's just a set of shell scripts However, I definitely recommend the get way you can read it on the website Updating rvm update dash dash head. I really highly recommend that you get head on rvm often I've actually seen a few people do this and I recommend it as well. It's good Rvm is kind of a fast-moving project. So So now that's the kind of overview of what rvm is a kind of feel for what you can do with rvm Let's look at a few More involved topics and then hopefully I will show you how I could fail miserably a live coding But yeah, we can so basically the idea of the the meat of this presentation is supposed to be How you can like manage your workflows and environments and deployments with rvm? Hopefully I can get through it all rvm gem sets originally it was just this kind of this homegrown ad-hoc way of Us being able to load a list of gems into our ruby environments and it worked great for us at my company but then Kind of you know everybody started using in the community and I put a quick poll out there a lot of people responded and The it was pretty unanimous that we would make rvm gem set and its own little API And it has all kinds of things you can do with the gem sets like creating Importing exporting deleting emptying so you can read that on the docs But fundamentally what gem sets does is it exports Your in your current environment rvm will set up a gem home a gem path and a bundler path and This is actually how it facilitates Segregating or Isolating your different gem sets into their own little world so that they don't interact with other One so you can have each project be in its own Little world at the system level which is very nice The rvm development cycle is a little bit unique Haven't seen too many projects do something like this. I was kind of nervous to do it at the start and extremely fast and furious I essentially I am I showed the initial rvm after it was a week old to Jamie van dyke and He got rather excited and the next thing I know I was talking to some fellow named Peter Cooper really nice guy and I Don't know. We just kind of came out of nowhere I was on this the rvm was featured on our Ruby inside and then all of a sudden I had like an IRC channel with like tons of people in it asking all kinds of questions so From the beginning basically I just kind of threw it out there. I released it very early in its life And I released it very often Releasing early and often was actually kind of cool What allowed me to do is I had a basically an army of qa and in the army of qa is this awesome Ruby community that we live in and Unfortunately by releasing early and often and taking on oh real quick UDD user-driven development Basically, I didn't do anything unless somebody was going to use it So I had people in the IRC channel all the time saying hey, I'm trying to do this I'm can rvm do this. I'm like well, no, but let's explore a little bit and usually within a day or two. It did it So that was very cool, but at the same time I just kind of grew everything from scratch just throwing features in and Piled out a lot of technical debt after after some point After I'd say like it was it was almost like a hundred iterations Decided to step back about 90 iterations step back think okay Well, what could we do it to the internals of our VM to? It's gonna blow Hey guys Is that what that is? That's not a fire alarm is it? All right, so Yeah, I can focus So we reflected on the internals of it I said how could I make this scale better so that when we add features in the future it doesn't break things randomly and We did that well I did that I sit there and I've refactored the whole internals made the directory structures So that they made sense were separated kind of took our originally Arvium was just one massive shell script And as it was the thing got like two three thousand lines of code. I'm like, okay. That's ridiculous So I took all the different functionality. I started moving as much of it as I physically could into external callable scripts and the RVM essentially being came this like command-line wrapper around this huge set of scripts and They were actually worked well. So moving forward. I'm gonna try to keep an eye open for Places where I might be just kind of jerry-rigging the code to do what it needs to do there versus Building it improperly and hopefully we can avoid some of the speed bumps we had before one zero one zero Zero one zero after zero one zero all the internal like refactoring had been done So now it's just first things like additions like adding the bundler path came after that and It was pretty painless to add that actually so So let's just see you know, what's the manual way for managing like a Ruby project in our VM Well, you create your project directory. You can move into it. You select a Ruby You're gonna use so if you want to track one point nine point two development you gonna Basically RVM use Ruby head and it puts that in your current shell as the Ruby You can create a gem set for this project. So gem set create project a gem set use project a and now you have Ruby head selected with project a Gem set all set up and ready to go to be filled so you just start doing gem install to fill up this gem set and then if you check the Gem directory Like we can say RVM gemdar, which is basically the same thing as gem and gemdar You can see that it's got a Ruby dash head with a percent project a and for those of you that like dash get over it switch to bash or ZSH Yes, so anyways, so this is completely separated whereas if you just do RVM use one point nine point one You're going to be your gem directory is that RVM gems Ruby dash head. That's it Let's see. So this is a lot of stuff and we really want this to persist I mean you don't want to just use this once basically every time you go to this project you want this environment set up So RVM actually provides you some mechanisms to easily Do that? So all of that stuff can be condensed basically into one line used well except for the making the directory of course, but once you're in the project directory you want to set up a environment using RVM you basically just do RVM dash dash create the create is a flag that says create the gem set if it doesn't exist Otherwise it will say hey this gem set doesn't exist create it first And then dash dash RVMRC says I want you to create an RVMRC with my current with what I'm selecting here in my current directory and Use one point nine point one project days So that's going to basically do all that stuff where it sets up and uses the environment in the previous example But it also has one additional item where it Creates a project a gem set for the interpreter it creates a RVMRC file in the current working directory as long as it's not home if it's home It'll yell at you because the home and ETC RVMRC want RVM RVMRC files are actually intended for modifying RVM's behavior itself, so make sure your project's not in your home directory So what does this get us? Yeah, let's let me just show you so What I'm gonna do is Is it? Sorry Okay, so I'm gonna make this directory and then as you can see there's nothing in it and It's good so project a so currently that's a bad example So currently I have a one point nine point one Selected and you can see if you do RVM info it'll show you basically your entire environment that's set up right now in that shell And you can see that it's all Ruby 191 patch level 378 and all the different binaries and paths and such things So now if I do that line in the slide that I was showing you it says using Ruby head with Gems up project a so if I check the version now, I obviously have selected 1.9.2 dev actually all right, so If I list now if you see that directory actually have an RVMRC file that it created for me That's interesting so If I do an RVM info well now all I'm using RVM Ruby head with project a so I'm now in this environment Well, that's kind of interesting so What is this RVMRC? Well, it's just RVM use Ruby dash head project a so now if See your switch to enter probe. I don't have that installed Do I have J Ruby? Nope Yeah, no, I know I have one point nine Okay Boom so now my environment on the shell is one nine one if I now CD to Actually, I should show you the Environment so it's definitely one nine one patch level 378 No gem set or anything like that if I CD to the project a directory It says using Ruby head with gem set project a well, that's interesting So now if I do an RVM info we see just by ceding into that directory We have Ruby head percent project a So this is actually kind of neat So let's say for this project. We need rake and Rails takes a while to install Well, I know Sinatra fun with Ruby gems So this is where you go and make coffee or something Yeah, no, we don't need that. Okay All right, so if we do a gem list we see we have rack rake and Sinatra and With rack rake and Sinatra, so I want actually this to preserve I want this to be able to share this with other developers So in order to do that I'm going to do I'm going to export my gem set to Project a that gems as you can see it's literally just like the name of the gem in the dash V the version what this allows me to do is let's say I do a project B below it and Project B Currently I'm still in my old environment from project a three however, I Want project B to be let's say I must have just had so I have Ruby Enterprise Edition and Project B if I cd to this directory me I See that I now have Ruby Enterprise Edition the latest one with project B selected as my environment. I Don't have any gems other than rake installed by default Irvm gem set import Project a I think yeah project a that gems what it does is it just Basically gem installs the three gems that it was Requiring which was Sinatra rack and rake For this doesn't take too long You get the idea it installs rack Sinatra and it loads the gem set It also uses a global caching mechanism so that if you've installed gem on another gem set before it will install much faster Because it will not go over the internet to do it. It will install from the dot gem file. It was saved So that's actually a so Here we have project a project B so now if I cd to project B or a I have Ruby 1.9 point to Actually, I just did a and now I'm at Ruby Enterprise Edition So it's a very easy way to you for you to define your sets of gems define a gem set define What Ruby should be used for your project by default? I mean nothing prevents you from running things against multiple rubies And I'm almost out of time so I got it Do-do-do See here. Yeah, so again, you can run specs against multiple things I'd like to thank some people real quick. There's a lot more things. I'd like to show you, but I'm out of time So thanks to Jim Lindley bill Chapman Mark Joseph for all the encouragement ideas and everything Tyler bird this presentation you rock Tim Brown is He did the he redid the new site look and feel and everything and how it's put together He did an awesome job Curtis McHale reviewed it and made some fine adjustments to it They were actually very awesome suggestions So thank you and most of all from the Ruby community you guys just rock lots of positive energy. Please keep it that way If you guys have any questions, please save them for breaks. I'll be at the hack fest RVM on free node and This presentation can actually be found on Be in rescue and RVM be in a rescue and a competition's mwrc 2010 and The documentation is all on RVM be in rescue and calm and I use pivotal tracker I think it's just a downright awesome tool for development and tracking development of an individual or team so Definitely use it. It just rocks hardcore You could find the development tracker Link to offer this presentation and there's a link to working with rails on there for If you want to contact me or whatever, but the best place to find me is RVM on free node And if you guys try out RVM, you have any questions or whatever you hop in there ask I may be sleeping because some of you are in PST and stay up a lot later than I do but I will respond so hang around the channel and You know ask any questions remember RVM is basically features user-driven development So if you guys have an awesome idea that you think would be really useful to have an RVM You know, let me know well, I'll work with you on it. We'll try to get it. No, I will not rewrite it in Ruby. Sorry However, there's one guy that's trying to do it. He's got some really cool stuff That's about it how much time we have