Do I really need the #rails3 when creating a gemset? - ruby-on-rails

I'm confused, what does the #rails3 do when creating a new gemset?
I want to run both rails2.1.1 and rails3 applications, and switch between the two.
I create a rvm for 1.9.2 and 1.8.7
And inside 1.9.2 I created 2 gemsets, and installed rails 2.1.1 in one gemset, and rails3 in another gemset.
Am I doing this right?
I'm reading others use the #rails3 in the gemset creation process, and it helps isolate things?? Can someone explain this as I don't get it.
Should I delete the gemsets and start over? or is it higher up that I have to delete?

There are rubies and gemsets. 1.9.2 and 1.8.7 are your rubies. Each ruby version can have many gemsets (each gemset is tied to one ruby install on your rvm). Personally, I have created a new gemset for each new project to help isolate the gems needed for that project from any other project.

rails is a gem, so it is usually recommended to isolate it and all the gems it depend on into a gemset.
otherwise, you can also use
rails _2.1.1_ -v
to invoke rails 2.1.1, although the usual recommendation is to create separate gemsets. You can see a lot of info of the gems by rvm info, and rvm list gemsets. Each gemset is a separate folder and keep things isolated from each other quite well.

Related

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

RVM per project gemsets

I'm having difficulty understanding RVM per project gemsets. I've installed RVM and the 1.9.2 and 1.8.7 rubies, as per http://beginrescueend.com/interpreters/ruby/ , and when I want to start a new project, I've been
cd ~/Code
rvm use 1.9.2
rvm gemset create test1
rvm gemset use test1
gem install rails
But this takes a long time! (installing rails). I then rails new test1; cd test1
I'm really unsure with the correct workflow. If I'm making a new app to test in, I don't want to have to wait for rails to install.
It seems from http://beginrescueend.com/gemsets/basics/ that I can create a rails gemset, but then how do I create a per project gemset?
Edit:
If I'm going to using multiple ruby/rails versions, should I create a gemset, say 1.9.2#rails313, then rails new blah, put 1.9.2#rails313 in blah/.rvmrc , and if I need to later on, create a blah gemset?
A gemset is just a container you can use to keep gems separate from each other.
The Big Idea: creating a gemset per project allows you to change gems (and gem versions) for one project without breaking all your other projects. Each project need only worry about its own gems. This is a Good Idea, and the wait time for installing large gems like Rails is usually worth it.
That said, if you're going to use the same version of Rails across all your projects and want to save time, you can install rails (and maybe rake as well) in the 'global' gemset - these gems are available in all gemsets for that version of ruby.
Assuming you already have a test1 gemset:
$ rvm gemset use global
$ gem install rails
$ gem install rake
$ rvm gemset use test1
$ rails test1
Once I wrote a simple blog post on how to use RVM with gem sets, this might be helpful to you.
UPDATE: As the link above is dead, I believe it is in another location here.

Questions regarding RVM

I am exploring the world of Ruby and RVM. I am going through a lot of documentation and trying out RVM, but I am a bit confused about the entire work flow. I am writing down the workflow as I understand it. Can someone please take a look and see if this understanding is correct?
I am using a Mac.
RVM is essentially a script that allows us to manage Ruby environments for development purposes.
RVM allows switching between different versions of Ruby with rvm use 1.9.2.
To use a particular gemset with the current Ruby version, we need to create a gemset using
rvm --create gemset rails235
Install the gem using gem install rails -v=2.3.5
Q: What happens if I did gem install rails -v=2.3.5 prior to creating a gemset? Will there be two copies of the same Rails installed under RVM's Ruby 1.9.2?
Q: What happens if I install 2.3.5 and 3.1.0 prior to creating gemsets and then create a gemset for each version?
Q: where does rvmrc come into picture in the whole story?
Any other information that helps me get this straight is extremely helpful.
#Kiran, this is in reference to your comment above. When you install a different version of ruby with rvm, it'll add to this list:
$ rvm list
rvm rubies
=> ruby-1.9.2-p290 [ i386 ]
On my system, I've only got one version running (for now). This helps too
$ rvm gemset list
gemsets for ruby-1.9.2-p290 (found in /Users/mike/.rvm/gems/ruby-1.9.2-p290)
global
=> mg_diaspora
rails3
railscasts
ruby
sorcery
The practice is to install common gems into your global gemset and create/use sets for everything else. I tend to keep pry and others in the global gemset. As Mike K. said, you'd never do #2; if you did do such a thing, I would imagine global having priority.
#3 .rvmrc
You can do things like this in the file:
rvm use 1.9.2#rails3 --create
This will ensure whenever you 'cd' into the directory, it'll switch to 1.9.2 and it's 'rails3' gemset; the following attribute ensures the gemset will be created if it doesn't already exist.
Update
Ex: if I say rvm use 1.9.2#rails3 --create how does this pick the version of rails3.1.0 gem
Because by the time this rails3 gemset is created I already have 2 versions of rails gems?
That's easy - when you run bundle install it creates a Gemfile.lock; this essentially 'locks' the gems that your application is set to use. You've never require two different versions of rails in a single Gemfile anyways - that's just ridiculous =)
1) Rvm automatically creates an #global gemset per interpeter so if you did what you state in the first question you'd have a 2.3.5 in the global gemset.
2) I'm not sure why you would do this.
3) rvmrc is just where you can specify environment info like bashrc, i use it to specify my default architecture for instance. It gets read when rvm gets sourced in your profile.
Basically global is a mix-in for all other gemsets under a specific interpreter. So, if you put rake and say bundler into the global gemset, and then create and enable your own gemset under that specific ruby, it will have both the gems you install in that gemset AND global.
You will see it as a single gemset though. Also, if you attempt to delete a gem that is in global while still in, say, mygemset you will not be able to delete it. This is to protect other gemsets from having gems mixed in from global that they rely on from being removed. You would have to either explicitly change to global or execute something like
rvm 1.9.2-p290#global exec gem uninstall rake -v='0.9.2'
Also, bear in mind that there is a significant difference between 'default' and 'global'. The 'default' gemset is not really a gemset perse. This is selected when you do something like
rvm use 1.9.2
Notice you did not select a gemset in the above command. This is where default lives and plays. When no gemset is selected, default becomes active and global totally disappears. To load default, you would modify $rvm_path/gemsets/default.gems as these are the list of gems to be installed into each interpreter's 'default' set. The other file there is 'global.gems'. This is used as you would surmise; to load a default set of gems whenever you install a new interpreter under RVM into the global gemset, which is shared by all other gemsets for that Ruby, but not for 'default'.
Please see https://rvm.beginrescueend.com/gemsets/basics/ for more information.

Rails 3.03 and Rails 2.38 -- can they work together?

Is there a way to install a Rails 2.3.10 app if I have Rails 3.0.3 installed on my machine?
for example i'd like to start my server with ruby script/server instead of rails server.
thx
Two main ways:
Bundler: you can create a Gemfile and use bundler to silo the gems for each of your installations. The drawback to this one is that you'll probably have to use "bundle exec command" whenever you want to run a command for the version of rails you're using, such as spec or cucumber
RVM: using RVM you can use not only different versions of Ruby, but also separate gemsets within a version of Ruby. I personally use this method most of the time, creating a gemset called "rails3" and "rails2" (or sometimes I use a gemset for the application) with the relevant gem versions in it. You can have as many gemsets as you want and switch between them. Stick a .rvmrc file in the root of your application, and rvm will switch the version of ruby and your gemset for you automatically.

Guidance in setting up some RVM environments

So I want to create environments for rails 3 and rails 2.1.1
How do I do this?
Where do I look for the various versions of rails?
I get an error when I try:
rvm 1.9.2-head
ruby ruby-1.9.2-head is not installed.
I just followed what I read on: http://rvm.beginrescueend.com/gemsets/creating/
Yes, gemsets are ideal for this. I use gemsets for this too.
First you have to create the gemset:
rvm gemset create your-project-name
then use the gemset:
rvm gemset use your-project-name
When you do this, all your gems are unreachable, you can get them back by using rvm gemset use, which will return to the default gemset (unnamed).
Inside your gemset, you will have to reinstall all needed gems. If you are using bundler, it is as simple as
bundle install
The advantage of using gemsets is that your gems are cleanly seperated. For instance, i ran into trouble with spec/rspec scripts when using both rails2 and rails3 together. With gemsets i no longer have any problems. Using an .rvmrc file per project, even the selection of the correct gemset is automatic, and i can configure my project in rubymine to use the correct gemset too. Awesome :)
Rvm is for different versions of Ruby not rails. You can potentially have every version of rails installed on one version of ruby. The application itself will in it's Gemfile or config specify what version of rails you are using.

Resources