I have been using rvm and when I installed ruby 1.9.2, it installed ruby-1.9.2-p290 and a few days back I wasn't able to reference the older one but it asked to install ruby-1.9.2-p318.
Is it mandatory to move to the newer version or would it be possible for us to instruct rvm to use the gemset created with the older version.
What brandon said is correct also you may want to set up a default ruby version with the --default flag. This will ensure that you are using the same version every time when you start up your terminal.
rvm use ruby-1.9.2-p290 --default
You may also want to set up a .rvmrc file in the directory you are working in to ensure that other developers are using the same ruby version and patch level as you are.
touch .rvmrc && echo "rvm use ruby-1.9.2-p290" >> .rvmrc
All the RVM commands, such as rvm install and rvm use, can take a patchlevel, e.g.: rvm install ruby-1.9.2-p290. If you don't specify one, the latest available patchlevel will be used.
Related
How do I safely upgrade my ruby on rails app to use a new ruby version, using rvm?
Suppose your app is my_app and you are using ruby version a.b.c and want to go to ruby version x.y.z.
Step 0
Before starting, make sure you have the up to date version of rvm
rvm get stable
rvm reload
Step 1
First if you do not have a gemset for your current ruby version create one and make it the default. This gives you an easy way to go back if your upgrade breaks your tests. If you do not want to do this, go to step 2.
rvm gemset create my_app_abc
The switch to that gemset and install the gems into that gemset, and make it the default gemset for the directory
rvm a.b.c#my_app_abc
bundle
rvm --ruby-version use a.b.c#my_app_abc
Step 2
Now upgrade to the new ruby version and create a gemset for it.
rvm install x.y.z
rvm use x.y.z
rvm gemset create my_app_xyz
rvm x.y.z#my_app_xyz
It is considered best practice to specify the ruby version in your Gemfile so
make sure you have ruby 'x.y.z' at the top of your Gemfile. Then
gem install bundle
bundle
This is where the fun can start, you may get errors at this point and use a combination of following the error instructions or googling for help, etc to solve them. When you can bundle successfully, then run all your tests.
When your tests have all passed, then you have successfuly upgraded. If you get stuck, you can go back to your old installation, using rvm a.b.c#my_app_abc.
Once you are happy with your new installation then do
rvm --ruby-version use x.y.z#my_app_xyz
to make this the default setup for this app. This means when you change into this app from other projects, it will automatically load ruby version x.y.z and the corresponding gemset.
According to this blog, if you always precede commands by bundle exec you do not need to use gemsets. In that case, you would simply do
rvm --ruby-version use x.y.z
I'm a little confused on using Ruby Version Manager. I was just wondering how to handle ruby updates for my web apps.
For example, I start a new Rails project and I tell RVM to use a specific version of Ruby like so:
rvm use ruby-2.0.0#my-project-name --create
Then say months down the road a new version of Ruby is released. What do I do then? Do I go back in and tell RVM to use the newer version? I want to build something that is always using the latest version of Ruby.
I'm assuming people build Rails apps, but don't always update to the newest version of Ruby and Rails?
Thanks, just starting out with all this, and trying to wrap my head around it.
There are three parts in this, Ruby, Gems and Rails Project, RVM can help organize everything in this order Ruby Interpreter/Version -> Gemset -> Rails Project
First Ruby:
You can use rvm list known to list all Ruby versions available in MRI, Rubinius, JRuby and others, after that you can install any version and interpreter like:
If you use MRI then rvm install 2.1 will install the latest in the 2.1 branch (2.1.1 being the latest).
For Rubinius rvm install rbx will install the latest stable Rubinius.
For JRuby rvm install jruby will install the latest stable JRuby.
After installing the version you're going to use, you need to specify that you're going to use it, like this for Rubinius: rvm rbx.
Second Gemset:
RVM gives you the ability to define different gemsets in each installed Ruby version that allows you to install gems for a specific project. For this Rubinius version I can:
Create a gemset like rvm gemset create latestRails.
Use a gemset rvm rbx#latestRails.
Show current Ruby/gemset rvm current.
Install latest Rails version in this gemset gem install rails.
Third Rails:
To keep Rails updated, you can use Bundler with a command like bundle update to keep all the gems updated (this are updated inside the current Ruby/gemset and the Gemfile) or a list/single gem of the project, for more info see "Bundle Update Documentation".
I hope I could help you.
I have some conflicts of ruby version.
When I run ruby -v in my terminal (in osx), I get the 1.8.7 version. I tried to upgrade ruby version, installing rvm, with this command curl -L https://get.rvm.io | bash -s stable --autolibs=3 --rails. Then I tried to run rvm install ruby-1.9.3-p362, and I was told that rvm was not a found command. So I ran source /Users/host/.rvm/scripts/rvm install ruby-1.9.3-p362, this worked and when I run in my bash ruby -v, I get ruby 2.0.0. But it seems to be related to my current terminal session since when I run ruby -v in another session, I always get 1.8.7 version. How can I set on my .bash_profile (or elswhere) the right version of ruby (and of rails) ?
RVM allows to install multiple versions of ruby on a single *nix box. Each ruby version is kinda sandboxed from another one. For the first time, you will need to specify a default version of ruby. This will be needed only for the first time.
rvm use 1.9.3-p290 --default
To switch to another version, simply type:
rvm use 1.9.2
Rails is just a gem. To get the most out of RVM, create a gemset and install all gems for one ruby version within one gemset. i.e. one gemset per ruby version.
This works like :
rvm gemset create my_gem_set
Gemset 'my_gem_set' created.
rvm gemset use my_gem_set
You can also use .rvmrc file in your project directory to 'load' just the required gems for your app. There is one .rvmrc per project. You can refer rvm.io for docs on rvmrc
You should set the default ruby via rvm: https://rvm.io/rubies/default/
rvm --default use <ruby_version>
You need to enable login shell in your terminal emulator, here is example how to set it up in gnome-terminal https://rvm.io/integration/gnome-terminal/
I'm not a Ruby developer, but I need to run an application that use Ruby on rails with a lot of gems on a Mac.
Following few tutorials online I see that I need to install plenty of apps like xCode, Passenger, RVM, ecc...
Everything is ok but what about if one day I decide to uninstall everything keeping only the Ruby default installation that already exist in a Mac?
Where can I localize all the gems that I download using bundle install?
Using the Terminal and writing all these commands is a clean solution or it make my system "dirty" and slow?
Sorry for all these question, but I would like to know if there is a "best practice" to install this environment, how it work and how to uninstall it completely if I decide to do that one day.
RVM is what you need. All things could be done in command line and it will be clean and ready to be removed at any time.
Xcode is not necessary. But brew may be. If you have brew, install apple-gcc42 first. The llvm-gcc with Xcode 4.2 and later works not very well for compiling ruby.
Then install rvm. It is easy by following the steps on rvm official site. After installing it, try rvm requirements first. This command will tell you what you need to build ruby. Some libs may not are on the machine, like readline etc.
When all requirements are met, rvm install 1.9.3 will install ruby 1.9.3 on your machine and it takes several minutes. You can install any ruby version in rvm list known. And rvm list will show you local versions.
Use rvm default some_version to set default one. This will not be any conflict with system installation. And rvm use some_version will change ruby version to a specific one.
All things rvm installed will be kept in ~/.rvm/ by default, including gems.
There should be no need to uninstall rvm. But it is easy to do this by removing it directly.
RVM will provide you what you wanted. It will keep the system Ruby safe and install localized Ruby and rubygems. From rvm you can install/uninstall any version of ruby anytime and that won't affect the system ruby. When one day you wanted to remove all ruby except system one, first remove them using RVM, then then remove rvm itself.
Install RVM from here: https://rvm.io/rvm/install/
Installing RVM will install ruby a ruby. If you want, you can install other version. If you want to remove you simply run
rvm remove ruby-1.9.3-p194
you can get exact ruby version using rvm list
localized gemsets
you will need an .rvmrc file.
To create .rvmrc, enter the project directory and run the following command:
rvm --create --rvmrc ruby-1.9.3-p194#myproject
Then re-enter the directory and it will ask you to trust the .rvmrv file and you got to trust it. now if you run the bundle install it will install localized gemsets in your gemset directory (most possibly in your ~ path).
Note: please make sure ruby-1.9.3-p194 matches the name exactly that you found in rvm list
My current version of ruby is ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0] but I want to update it to the latest patch level using rvm. How can I do this?
First of all, update your RVM installation by running rvm get stable.
To make sure you're running the new RVM version, you'll then need to run rvm reload (or just open a new terminal).
Once that's done, you can ask RVM to list the ruby versions available to install by running rvm list known.
In the output you should now see:
# MRI Rubies
...
[ruby-]1.9.2[-p320]
...
The square brackets around the patch level indicate that this is currently RVM's default patch level for ruby 1.9.2.
Finally, to install the new ruby version, just run rvm install 1.9.2 - and wait for it to compile!
Upgrade ruby interpreter and keep existing gemsets:
$ rvm upgrade 1.9.2-p0 1.9.2
Are you sure you wish to upgrade from ruby-1.9.2-p0 to ruby-1.9.2-p136? (Y/n): Y
To replace with the latest stable release of 1.9.2. This avoids clutter.
Some additional helpful tips, thanks to comments (#Mauro, #James, #ACB)
$ rvm list known
# NOTE: you probably want to upgrade your rvm first, as the list of known rubies seems to be coupled to the rvm version.
$ rvm get stable
$ rvm list known #pick your ruby
First update RVM:
rvm get stable
Then update your Ruby version:
rvm upgrade 2.0.0
Choose yes for all the questions:
Are you sure you wish to upgrade from ruby-2.0.0-p195 to ruby-2.0.0-p247? (Y/n): Y
Are you sure you wish to MOVE gems from ruby-2.0.0-p195 to ruby-2.0.0-p247?
This will overwrite existing gems in ruby-2.0.0-p247 and remove them from ruby-2.0.0-p195 (Y/n): Y
Do you wish to move over aliases? (Y/n): Y
Do you wish to move over wrappers? (Y/n): Y
Do you also wish to completely remove ruby-2.0.0-p195 (inc. archive)? (Y/n): Y
If you wish to update your gems to the latest versions, you can do:
rvm all do gem update
EDIT: I just did this today for the latest version of ruby 2.0.0 (I updated from ruby-2.0.0-p195 to ruby-2.0.0-p353). After that, I was getting segmentation fault when I tried to update gems. This happens because the gems were installed for ruby-2.0.0-p195 and some of them are incompatible with p353.
Now you can go and try to find the gems that are incompatible, but the easiest solution was to remove all installed gems and install them again. I simply removed gems/ruby-2.0.0-p353 directory that was located in /usr/local/rvm. It could be somewhere else for you.
Then I ran gem install bundler and for each of my rails apps I did bundle install.
like this:
rvm update; rvm reload
rvm install ruby-1.9.2-p136
rvm --default ruby-1.9.2-p136
You can install any patch level by following the page in their wiki.
Also, each ruby is independent, so you aren't really 'upgrading and keeping the gems' but installing a new patch version and then installing the gems in that new ruby environment.
This may be were gemsets come into play, however I don't use them.
Do not forget to update your rvm too, just in case it's been awhile.
npad's answer definitely lays out the basics so I won't reiterate those steps, but there are several answers here suggesting using rvm upgrade. I know that rvm gives you the option, but it's a bit of a dangerous one.
IMO, the safer and more "rvm way" is to first rvm install the new ruby version, then use the rvm gemset copy command to copy your gemset(s) to the new ruby version, e.g. rvm gemset copy 1.9.2-p0#some-gemset 1.9.2-p290#some-gemset. Then you can easily switch your project to using the newly-copied gemset (I recommend using an .rvmrc file in your project directory) and see if your code fails. If it does, changing back to the old ruby version is just a matter of switching the gemset.
But even if you don't use gemsets (though I assume you do since you tagged rails on this question), the use of rvm upgrade can lead to unexpected failures. And if your code breaks, now you have to reinstall the old version again. Just take a bit more time and do it the clean way.
I guess its rvm install 1.9.2-head
You can see available rubies with rvm list known
This blog post should be helpful:
http://pogodan.com/blog/2011/09/06/ruby-1-9-3-for-development
essentials:
rvm get head
rvm reload
wget https://gist.github.com/raw/1008945/4edd1e1dcc1f0db52d4816843a9d1e6b60661122/ruby-1.9.2p290.patch
rvm install ruby-1.9.2-p290 --patch ruby-1.9.2p290.patch -n patched