In this video we're going to be upgrading our version of Ruby. So we're going to be installing
ruby version 3, version 3.0.0. So you can see here that this has been released about one year ago and
before this I've been using ruby 2.7.3 so 2.7.3 has been the version i've been using for most of
the applications that i build but you can see here that ruby version 3 is designed to be three times
faster than ruby version 2 so there is performance benefits that you can make use of by upgrading the
version of ruby that are using in your projects so in this video i'm going to be using ruby version
manager which is also known as rvm so we're going to be using that to install ruby version 3. and
before we jump into that if you are interested in learning how to write code in ruby make sure
to check out the courses i have available on my website so i have an intro course for programming
ruby for beginners and we cover a lot of the basics in there to get you up to speed and writing
really good code in ruby really quickly so check that out on the link in the description below
and if you're interested i also have templates of apps that i've built using ruby and rails
and many people buy these and use the code as a means of learning how to build full applications
so those are available you can access them all for 299 dollars for all of those templates
and use them as learning at your own pace so let's go back now and look at how we can install ruby
version three i'm not going to go into too much detail but there are some different benchmark
tests and things here you can look at on the ruby webpage which show the reason for the
the speed benefits or the performance benefits you can get from this version
so check that out if you want to learn more about that but let's jump into this now in the terminal
so i'm going to use rvm and the first thing i'm going to do is see what version i've got installed
just to show you so do rvm and we'll pass in the option of v for version and you can see i've got
1.29.12 installed so i think this is the very latest version i've just run the update before
this video so you can run the upgrade using the details on the rvm website and there are once
you have done this this will allow us to see all of the new versions of ruby that are available
the next thing i'm going to do here is run the rvm list known and this will give us a list of the
known versions of ruby that we can use so if you have updated the version or if you've updated your
rvm then you will be able to see that we've got this ruby version 3.0.0 so that is the latest
version that we can install using rvm so that's what i'm going to be installing in this video
so previously i've been using i think it's 2.7 point i thought it was 2.7.3 but maybe it's 2.7.2
but yeah we're going to be installing ruby version 3 in this video
so i'm going to run rvm install and then followed by the version number that we're installing so
we're installing 3.0.0 and this will take quite a few minutes probably to complete uh depending
on the speed of your computer and your internet connection and everything else but while this
is installing let's talk about why you may want to use ruby version manager or an alternative like rb
env so these version managers allow you to have different versions of ruby on your system
on your computer and it just means that if you have multiple projects and if you're working as a
ruby developer or a ruby on rails developer you're probably going to have multiple projects going on
at the same time and each of those different projects are going to have different versions
of ruby different versions of the gems that you use ruby gems and if you don't have a
version manager to control that it can get very very complicated and you can run into a lot of
problems quite quickly if you don't separate the ruby versions in that way so i like to do this by
project i create a separate gem uh sorry a gem set for each project and of course then there's going
to be multiple versions of ruby so i probably have about six or seven different ruby versions
installed on my computer and i've probably got like a maybe something like 15 or 20 different
gem sets running on my computer so you can do that based on each project and that's how i would
do it and i would recommend it um it just keeps everything keeps everything in the right place
it keeps it from becoming a problem later if you separate it out at the beginning so this is almost
finished installing now and you can see we've got the version complete so it's installed 3.0.0
Everything looks to have worked correctly here so now that we've got this installed let's run ruby
version and see what we've got so you can see we've got ruby version 3.0.0 as our default now
in this terminal shell and if i run rvm list you can see that we still have rvm
so we still have ruby 2.7.3 as the default version but at the moment we are running 3.0.0
Of course you know we've got all of these different versions and we can switch in between
them based on what projects that we're using but this just gives you an idea of you know different
versions that can be running on your system at the same time um at any at any point in time we can
just tell our vm that we want to use a different version of ruby in order to do that we can say
"rvm use 2.7.0" or 2.7.3 depending on what version of ruby that we want to run at any particular time
so let's test this out let's say "rvm use 2.7.3".
And you can see that the correct version is now loaded and once we do rvm list you
can see that both the default and the current version is 2.7.3 so it makes it very easy to
switch versions of ruby if you're using rvm so let's switch back again let's say rvm use 3.0.0
and now we can see that the current version has been switched again
so now that we have ruby version 3.0.0 running
that's our current version we can go ahead and add a gem set for that version.
So if it's a current version that's loaded and you create a gem set it will automatically assign
it to that version of ruby so we'll say rvm gem set create and we'll call this dummy app
and you can see that that has been assigned to ruby version 3.
so this just means that anything we install like any gems we install
it will be contained within that dummy app gem set
and one really nice thing about using a version manager like this and i think this only works for
rvm but it allows you to set the the version of ruby and the gem set within the folder itself or
within that directory so if you have a directory and you add a dot ruby gem set file you just
include the value or the name of that gem set inside that file and you can do the same with
the ruby version so if you have a dot ruby version file rvm will automatically read these
files and set the correct version of ruby and the correct gem set so that means that once you
use terminal and you change directory so you try to go into that directory it will automatically
change the version of ruby and the version of the gem set you know the name of the gem set for you
so that way you don't make mistakes later it will automatically load the correct versions
so that's kind of how i approach each project i set those files and it means
that everything's just handled automatically so it works quite nice for all of my projects
and if we look at the ruby website we can see that there are newer versions of ruby
that's been released so our newer versions than the one we just installed so we have
a late the latest version here is in December of 2021 so it's just a few weeks ago,
Ruby 3.1.0 but this version has not been added to rvm yet and as a result we can only get 3.0.0
so there are newer versions of ruby that have been released but if you're using rvm we can only get
3.0.0 as the latest version at the moment perhaps if you use a different approach maybe you can
update the rvm to use the latest version that they've ruled out but i've just used a stable
version that was released the for the rvm update and as a result it will just give us
3.0.0 but i think for the purpose of just getting upgraded from 2.7 up to three i think this is
more than enough at this stage but let me know what you guys think in the comments below and
hopefully this video has been helpful to you today and i will see you guys in the next one