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.
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 recently started learning Rails using Ruby 1.9.3p385, and I'm trying to develop a small project with it.
I'm using Linux so I installed Ruby using RVM.
I developed a few pages, following some tutorials. I would like to upgrade my project to use Ruby 2.0.0. What do I have to do?
I installed Ruby 2.0.0 with RVM:
rvm install 2.0.0
Everything seems OK, so I tried to use it:
rvm use 2.0.0-p247
But when I try to run my Rails server using rails server, I get the following message:
bash: rails : command not found
I've read the RVM documentation about upgrading Ruby but I don't really understand what it does; I'm afraid of breaking everything.
Does it will upgrade my project in a way it will use Ruby 2.0.0 or what should I do?
Next, I will want to upgrade also to Rails v4.
Your gemset which comes with new Ruby version is empty. Try this:
gem install bundler # this will install bundler
bundle # this will use bundler to install required gems
rails server
Did you run rvm use 2.0.0-p247 or did you use rvm use 2.0.0-p247 --default? The later will set Ruby v.2.0 as the default for your system. Failure to do that will revert your Ruby to whatever RVM's default is the next time you log into your system or open a new terminal window.
When RVM installs a new version of Ruby, it installs only the default gems. It CAN upgrade a Ruby to another version, and optionally install the existing gems as it does so, but that's not what you asked it to do: rvm install 2.0.0 only installs Ruby. At that point you have to install the other gems you need, which would include Rails.
My general practice when installing various versions of Ruby and the gems I like is to use two command-line pipes to dump my existing gems, then (re)install them. First I switch to an existing Ruby whose gems I want to duplicate, then run:
gem list | cut -f1 -d' ' > ~/gem_list
Then I switch to the newly installed one, and run this:
xargs gem install < ~/gem_list
This does a completely clean install of the gems, outside of RVM's commands.
Why? Habit. Paranoia based on some "experiences" I had in the past with RVM.
Once that's all done and I have brand-spanking-new Ruby and gems, I'll proceed with running bundler or other housekeeping chores.
when you install a new ruby version, you have to reinstall all the gems for that version. start of by installing bundler first. Then run bundle in your rails root directory. When you encounter no errors, you're good to start the rails server. Good luck!
run bundle install on the application root, you need to reinstall all your dependencies for the new version of Ruby.
I git cloned an open source software and is currently planning to contribute to it. Originally I installed ruby 1.9.3 with rvm and installed gem install rails - which fetched version 4.0 (newest version)
I installed ruby 2.0 as well with rvm and did 'gem install rails' which also fetched me version 4.0
I was planning to installed ruby 1.9.3 with rails 3.2.13 - an older version of rails
to work with different software and switch between them using rvm
So since my open source software is written in 1.9.3 and rails 3.2.13, I tried
gem uninstall rails
and removed all the rails version
but when I do
rails-v ,
it is still 4.0
I figured out from another question that there are folders associated with 4.0 that I need to remove to remove 4.0, another question suggest that I install rails 3.2.13 but when I make a new app I can just do rails 3.2.13 new app etc. I installed that under 1.9.3 when I switch to 2.00 which still has 4.0, I tried rails 3.2.13 new app and it ran which I don't think it should.
I am growing semi-frustrated with this, and I wish someone can help me while I browse even more questions.
You should create a new gemset within rvm for this. That way you can use a different version of ruby and rails than your system default. Switch to ruby version 1.9.3 in RVM and then use rvm gemset create <name-here> and then rvm gemset use <name-here> to create and use the new gemset. Switch to the directory of the project you cloned and run bundle install to install all of the necessary gems, including rails (assuming the rails version is specified in the Gemfile.)
I have already installed Ruby 1.8.7 and Rails 2.3.8 which is working fine.
Now, I need to install Rails 3.2.8 in order to install a gem and my goal build the same compatible with Rails 2.3.8 based on how it is developed.
I tried installing Rails 3.2.8 using
gem install rails -v=3.2.8 -include-dependencies
but to my surprise when I checked gem list rails, it shows only Rails 2.3.8 and I'm unable to create a new app using rails 3.2.8 test.
I'm not sure but I read that Rails > 3.0 doesn't work well with Ruby 1.8.7 and needs Ruby>1.9
Rails 3.2 is compatible with Ruby 1.8.7. What you could do is have a ruby version manager like RVM or Rbenv. I use RVM but some people prefer Rbenv as it does not mess with your shell.
Using version managers will allow you to have different versions of ruby and with RVM you can create different gemsets for each specific version.
EDIT Here's the link for the release notes for rails 3.2 http://guides.rubyonrails.org/3_2_release_notes.html
EDIT
There's a couple of commands that you can use.
rvm list
will list the versions of ruby you have installed.
To install a version of ruby you'd do something like rvm install 1.9.3 to use that version you'd do something like rvm use 1.9.3 You can even specify patch levels and switch between different versions.
Now, rvm uses a concept of gemsets, to create a gemset you can set up an .rvmrc file in your project with the following command
rvm --create ruby-1.9.3-p286#some-project
it will create a set of gems called some-project where you can install whatever gem versions you want.
Notice that command can be ran from the command line as well. That will separate all the gems per project and you can switch between gemsets as you would ruby versions. Then in whichever gemset you'd just run gem install rails and the version
Your ruby version is good enough for both rails 2 & 3.
Try to create new app like below:
rails _3.2.8_ new appname
I am following a tutorial about Ruby on Rails, and the tutorial got updated to a new version of Rails, so I can't follow it anymore because I have an older version.
I would like to start new and uninstall Ruby on Rails and any related software on my Mac OS X 10.5.8, and follow it from ground up. If anyone would be willing to help me uninstall Ruby and Ruby on Rails, it would be much appreciated.
Download RVM or RBENV and upgrade to the latest Ruby (2.3.0 at this point). Don't touch your system Ruby.
Are you uninstalling Ruby on Rails, or Ruby AND Ruby on Rails?
If you want to uninstall Ruby on Rails it should be a simple matter of using gem uninstall rails or doing gem dependency rails and then gem uninstall for each of the listed gems that Rails depends on. If you installed them system-wide, using sudo originally, you'll have to use sudo again to uninstall them.
If you want to uninstall a system-wide Ruby you installed from source, well, I'd probably leave it alone and install any new versions of Ruby using RVM. The older version won't be visible to apps unless you want them to see it or set your path to include it. RVM's version will be found first unless you do rvm system.
Actually you could simply install RVM and have it install your new versions of Ruby, then from there install new versions of Rails, without even bothering to uninstall the old stuff. RVM really is that cool.