Updating Ruby 1.9.3 -> 2.0.0 without losing gems - ruby-on-rails

Have had 1.9.3p194 (RubyInstaller) with Ruby on Rails and all kinds of Gems installed on my WinXP. Now I want to update the whole setup.
Updating RoR (to 4.0.0) and gems was easy: gem update rails, gem update --system, gem update.
But how do I do that with Ruby? Is there an easy way to update the installation?
If not, and I have to install the fresh package, then how do I do it with little hassle?
I have downloaded the fresh 2.0 RubyInstaller. I have read that I shouldn't install this new Ruby version in the same directory as my old Ruby version (c:\programs\Ruby) that's why I chose a c:\programs\Ruby200 directory. During the installation I clicked on every additional setting, including the "include new directory in the PATH variable" type of choice. But now when I type ruby -v I still get 1.9.3p194 and the new directory is absent from PATH (I haven't rebooted, so maybe this has something to do with it).
So how should I really install the new version? Should I simply change the old PATH to the new one? Or should I instead only add the new one without removing the old path (so there will be some kind of advantage of having both 1.9.3 and 2.0)? Or should I simply delete both installations and install 2.0 from the start?
How do I easily transfer the gems (or the list of them, so the gem update could handle the installation/updating) from my old installation to the new one?
I am using JetBrains RubyMine 5.4 editor, and would like to know if I need to do something there as well (for both the new and the existing projects).

Like many POSIX users, I rely on rvm and bundler to manage ruby versions & gemsets. Unfortunately, rvm is not available on windows. Although I haven't tried it personally, it looks like pik is a viable windows alternative. I would recommend checking that out.
You should also definitely look into bundler if you're not already using it; since bundler is just a gem, it should be platform independent.

Related

Is there a version manager for Ruby gems?

I'm a new Rails developer. I recently took a class on Rails and now I'm trying to make sure I'm growing in my skill by self-assigning projects that push me. One thing I'm trying to do now is use Radiant CMS to build a blog site. However, I'm running into some problems downloading the Radiant gem. Here's what I did:
When I first tried gem install radiant, it installed most of the required gems but then threw a warning (which I unfortunately did not save verbatim), which was along the lines of:
railties executable will overwrite rails executable. Overwrite? Y/n
Stupidly, I chose "Y". As soon as I did I tested my rails gem by writing rails new testproject and it failed. So I then re-ran gem install rails, told it to overwrite the "railties" executable, then ran gem uninstall radiant to get rid of the core radiant gem (although I do still have railties).
Now, my Rails gem is fixed, and I can create new Rails projects without an issue. However, I reinstalled the Radiant gem, and while it installed, it fails to create a project every time I run it.
I'm pretty sure I broke something, but I'm not terribly concerned about that. What I am concerned about is the fact that it seems that the Radiant gem doesn't really coexist well with the Rails gem, which leads me to my question:
Is there any way to create separate, self-contained ruby gem environments where the current Ruby version will only use the gems in the specified environment?
In essence, I'm looking for what rbenv does, but for collections of gems rather than Ruby versions.
Currently, I have Homebrew installed and I am using rbenv as my version manager. Everything I can find so far talks about managing gems on a project-by-project basis; I'm looking for something that will manage and keep separate the gems that create the projects in the first place. So, for example, environment_a contains rails and httparty while environment_b contains radiant and railties.
I'm not above completely obliterating rbenv and all of my gems and starting from scratch, either, so that's a possibility (and an advantage of being a noob).
You should check bundler, as it does exactly what you need.
Yes: rbenv-gemset
I think that it is better than RVM because it is less invasive.
I have been using rbenv and rbenv-gemset for about 2 years and find it easy to use. It makes it easy to encapsulate the Ruby and gemset in a project, run multiple Rubies and gemsets on one machine, and move a project to another machine.
You can use ruby-build to install other versions of Ruby. There is a trick to installing the latest versions of Ruby.
You may want to have a look at How do I ensure ruby gems are installed in right place to be executed by bundler? It has some relevant (and hopefully useful) info.
Yes, there is.
I think that it's called RVM.
Just like Chris Heald said, You can check more information about it # rvm.io/gemsets/basics
I'd recommend bundler for versioning gems although both RVM and rbenv also have this functionality.
You asked: "Is there any way to create separate, self-contained ruby gem environments where the current Ruby version will only use the gems in the specified environment?"
The best way to do it with rvm is entering your project's directory and then run:
rvm use ruby-x.y.z#your_project_name --ruby-version --create
where x.y.z is your Ruby version for that project, previously installed with rvm install x.y.z
For example, to use the newest Ruby version with a project named acme you would use
rvm install 2.3.1
and then
rvm use ruby-2.3.1#acme --ruby-version --create
This command would create two files in the projects directoty: .ruby-version and .ruby-gemset.
The file .ruby-version would contain just the version number. And the file .ruby-gemset would contain only the name off the gemset, the same name of your project (acme).
It happens that rvm is smart enough to check for these files and use the gemset specified, which will be located at ~/.rvm/gems/ruby-2.3.1#acme and your gems will be located at ~/.rvm/gems/ruby-2.3.1#acme/gems.
Some points:
1) Using your project's name as the gemset name is NOT mandatory. You may use anything you like. It's kind of a standard using project's name, but not mandatory.
2) rbenv probably has a way to do the same, but I don't use rbenv and really don't know how to do that.
Hope this answer helps.

How do I working on two apps with different Ruby/Rails versions?

I finished Michael Hartl's tutorial and created an app using Ruby 1.92 and Rails 3.2. Now I want to make my own app but I want to use the new versions of Ruby and Rails.
If I install the new versions for my new app, can I still make changes to my old app without things getting messed up or do I have to keep installing/uninstalling different Ruby and Rails versions?
You should look at using a ruby environment manager. I use rbenv, you can also specify in your gemfile which version of ruby and rails should be used for a specific application.
https://github.com/sstephenson/rbenv
You should be fine. Just make sure the proper versions are specified in your Gemfile and you will be good to go.
After installing the new version, by default new version will be used. However, already existing app will still use the version of rails they already exist as.
Bundler takes care a lot of the hard work for you in your situation.
Other notes:
Keep in mind RVM allows you to install "Gemsets". Should you have the need to use specific versions for gems you can create sets of them for use when needed.
You can also specify the version of rails when you're creating your app via rails _3.x.x_ new FooBar and you can identify what versions of rails are installed on your system via gem list --local | grep rails
If you need to negotiate local and global ruby versions, consider using rbenv.
https://github.com/sstephenson/rbenv
RVM is another popular option for ruby environment management.
https://rvm.io/
Personally, I have been more successful with rbenv.

Ruby On Rails 3.2.13 - Using Different Gemsets For Rails Applications

I currently have several Rails applications running version 3.2.13 that use Ruby 1.9.3. I plan to eventually upgrade my current applications to Rails 4.0 then upgrade Ruby to 2.0. I need to time the conversion to Ruby 2.0 carefully since from my understanding Phusion Passenger will only handle one version of Ruby without some nose bleeding solutions which I do not plan to attempt to implement at this point.
I currently use one gemset for all my Rails applications. I would like to convert my Rails applications one by one from 3.2.13 to the current version of Rails 4.0 at some point. When I have tried to update one of my applications to a newer version of Rails I was told I had to do a update rails command.
What I want to do is to be able to run some of my applications using Rails 3.2.13 and others using Rails 4.0 until I am sure they will all run properly under Rails 4.0. Once I do this I will review the differences between Ruby 1.9.3 (if any) and upgrade all of them to use Rails 2.0. At this point I understand that I would just create the gemset for 2.0.0 or whatever the latest stable version of Ruby 2 is.
I have done web searches and checked the RVM website. I understand how the gemsets are assigned to the version of Ruby you want to run. However I'm not seeing anything about using gemsets with the same version of Ruby but using different versions of Rails or other combinations of gems on the same machine for different applications. Can this be done?
Any help would be appreciated.
Take a closer look! ;)
First, create a new gemset with a name corresponding to your project
https://rvm.io/gemsets/creating/
ex: rvm gemset create project_name
Then create/edit .rvmrc file in project directory: rvm use 1.9.3#project_name
One pitfall is that if you execute following commands
cd some_project
cd ../other_project
and other_project doesn't have gemset specified you'll stay in some_project gemset. To avoid that you can create .rvmrc file with default gemset in your "projects" directory (if you have one)
Project Folder
|___Gemfile
|__.ruby-gemset
|__.ruby-version
Gemfile with all the required gems mention in your project folder
.ruby-gemset should have gem set name like sample-gemset
.ruby-version file should have specific ruby version (e.g 2.0)
rvm gemset list
it will show gem set created with sample-gemset and do the
bundle install
which will install all the specific gems for this project under sample-gemset,
same you can do for other project to create other gem set, in this way you can maintain different rails/gems and ruby version for different projects with rvm.
Your Gemfile.lock nails down which version of every gem you use - you don't need to worry about gemsets.
bundle install will always install the correct versions and your app will always use the versions in Gemfile.lock, even if there are other versions floating around

Having multiple versions of Rails installed on OS X

OS X 10.6 has Rails 2.2.2 installed by default.
How to upgrade to Rails 2.3.8?
Since Rails 3 is out, is it possible to have multiple versions of Rails (like 2.3.8 and 3) installed on OS X?
(For example, I could be working on two Rails projects, one is Rails 2.x and the other is Rails 3.x).
Use rvm
RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems...
RVM allows users to deploy each project with its own completely self-contained and dedicated environment--from the specific version of ruby all the way down to the precise set of required gems to run the application. Having a precise set of gems also avoids the issue of version conflicts between projects, causing difficult-to-trace errors and hours of hair loss. With RVM, NO OTHER GEMS than those required are installed. This makes working with multiple complex applications where each has a long list of gem dependencies efficient. RVM allows us to easily test gem upgrades by switching to a new clean set of gems to test with while leaving our original set intact. It is flexible enough to even have a set of gems per environment or development branch--or even individual developer's taste...
I wouldn't bother with gemsets myself just do as other people have mentioned:
gem install -v=2.3.8 rails
and then to use:
rails _2.3.8_ new rails app
Note that this _versionnumber_ thing is a standard way of specifying a version of any rubygems installed executable.
Use
gem install -v=2.3.8 rails
where -v=[version number you want to install]
Then
list gem rails
In your config/environment.rb you can state which version of Rails you want to use.
To upgrade your OS version of the rails gem:
sudo gem install rails --version 2.3.8
While you're at it, you can also upgrade your OS rubygems system itself, overwriting the binary that OS X comes with. This might seem kind of hacky, but it's a stable thing that everyone does.
sudo gem install rubygems-update
sudo update_rubygems
Regarding managing rails versions in your projects, if your only needs are:
Specifying the version of rails that you want on a rails project
Specifying different versions of rails and/or other gems in each of multiple rails projects
Then rvm is overkill. The only thing you need, and what is also a complete and utter pleasure to work with, is Bundler. Bundler is like Software Update for your rails project. In fact, Rails 3 comes with Bundler by default, you just have to list the gems you need in Gemfile and it takes care of the rest. You don't need to worry about which versions of your gems are installed in the OS.
(You do however need the appropriate version of the rails gem installed in the OS in order to generate the rails project in the first place)
http://rubygems.org/
It's all you need =)

Ruby on Rails - Locomotive for version 2.3.8 -- is there such a thing?

I am looking for a piece of software that will allow me to use Ruby on Rails 2.3.8 on top of MACOSX - basically, I teach at a college where students are not able to get terminal acccess to the rails built into OSX so I am looking for a piece of software like "Locomotive" that is an app that allows students to use rails without administrator access to the computer itself.
Any one have any ideas?
We will be using Rails 2.3.8
thanks.
I encourage you to teach 3.0, but each to their own. If your materials only cover 2.3.8 then it's missing out on a lot of goodies associated with 3.0 (such as Bundler). Anyway:
My primary fear with this is that you're going to have an un-upgradable version of Rubygems if you don't have system privileges. Some gems require a Rubygems version >= 1.3.5 or even better, 1.3.6. Latest is 1.3.7. Thankfully, there's a way around it.
You can do this by installing the rvm gem:
gem install rvm --install-dir ~/.gems
RVM is "Ruby Version Manager" and does what it says on the tin: manages different versions of Ruby on your system. It'd be helpful in your case because it works without modifying the system Ruby.
This will install the gem to the user's home directory rather than the default system path. Then you'll need to run the rvm-install command which, as of this writing is:
~/.gems/rvm-1.0.14/bin/rvm-install
Your version of RVM may be different. To install a new version of Ruby which people can (ab)use run:
rvm install ruby-1.9.2-p0
1.9.2 is the latest stable version of Ruby and I highly encourage you use it rather than the older 1.8.7.
This should come with the latest Rubygems and, for bonus points, won't muddle about with the existing ruby installation on the machine (which is probably impossible if you don't have admin rights).
From this point, you'll be able to use
rvm use ruby-1.9.2-p0
to "switch" to that specific ruby. From there, you'll be able to do run gem install rails -v 2.3.8 which will install Rails somewhere in ~/.rvm. The location is not important. What is important however is that now you'll have a rails command that you can use and then you can go from there.
Good luck!

Resources