I have installed rails 3.0.10 and 2.3.5 in my machine. I wanna shuffle between them but I am unable to use 2.3.5. When I run a command, the system recognizes only 3.0.10.
rvm lets you easily manage multiple installs of Ruby, each with their own list of gemsets.
Edit: Based on your comment about looking into gemsets, I'll point out one of the single coolest features with rvm. Once you get your gemset setup, create a .rvmrc file in your Rails root directory. Add the following to it:
rvm 1.9.2#foo
Where "1.9.2" is whatever Ruby you're using and "foo" is the gemset name. rvm will automatically start using this set when you cd in to that directory.
Definitely use rvm, create a .rvmrc file in the root directory of each of your projects.
For rails 3 stuff, it should contain a single line: rvm 1.9.2#projectName
Replacing projectName with an identifier for your project. Then use rvm gemset create projectName
Everytime you go into that directory, you'll be using that version of ruby with that particular gemset so you won't mix up versions or ruby or gems!
Related
I am running my rails app from a virtualbox build by vagrant using puppet scripts. Every time I login to the box, I have the following problem:
When I run rvm list one of the things it lists is the following:
=* ruby-2.1.1
But when I try to run rails console, it tells me I need to install missing gems. When I run rvm use default, and then run rails console, it works. Why is the default and current setting in rvm not working--why do I have to go to the extra step of also telling rvm which ruby version to use?
Note: I do have a .ruby-version file with 2.1.1 in it. I'm using rvm version 1.25.25
Because you have to tell rvm which version to use.
In earlier version of rvm we have to define .rvmrc file which mention which ruby and gemset to use.
In recent version of rvm we have to define .ruby-version file with ruby version in it and .ruby-gemset file with the name of gemset.
If you just want a quick solution then in your rails directory make a .ruby-version file with content 2.1.1
correct syntax is:
rvm --default use ruby-2.1.1#global
This command sets ruby to selected default permanently. All new terminals will use your default Ruby. Also you don't mention anything about gemset, so I presume global would exist if you didn't mess up your setup.
This solved it:
I added rvm use --default to the machine's ~/.bashrc file.
I'm developing using multiple ruby instances and gemset for different apps. In order to switch between my ruby versions and gemsets, I use the .rvmrc file. I also use Eclipse with the radrails plugin as my development tool. Is there any way to get eclipse to switch automatically between the different gemsets and ruby version using rvm?
Go into your project directory and create a file called .rvmrc containing the line:
rvm use ruby-1.8.7-p330#testing --default
(or whatever ruby version/gemset you like)
now do
cd ..
cd -
answer "y"
and now Eclipse should use the specified ruby version
(maybe you need to restart Eclipse first).
For my different Rails folders, I would like to have rvm automatically load the correct gemset when running anything from 'bundle install' to doing my 'autotest' or rails console or server. Is this possible? Currently I have to manually do 'rvm use' which is getting a bit tedious as I am working on multiple Rails projects at the same time.
Create a .rvmrc file in your rails directory, and rvm will automatically load it. An example .rvmrc that loads Ruby 1.9.2 and a gemset named "rails3":
.rvmrc
rvm 1.9.2#rails3
You can do a lot more too, described in detail here: https://rvm.io/workflow/rvmrc/
For current versions of RVM, using two files is best practice:
.ruby-version
.ruby-gemset
http://rvm.io/workflow/projects
You can also use this in Gemfile
ruby '2.2.0'
ruby-gemset=significa
This way rvm will automatically pick the configured version
For current RVM version 1.29.1, the recommended way is
rvm --ruby-version use <ruby-version>#<gemset>
Exmaple
rvm --ruby-version use 2.4.0#rails5
cat .ruby-version # 2.4.0
cat ruby-gemset # rails5
this will generate two file .ruby-version and .ruby-version in your porject directory. This will compatible with other Ruby Versions Managers
Yaw just create two plain-text files and put into your project folder:
.ruby-gemset and .ruby-version
.ruby-gemset should contain only gemset alias name and nothing else
.ruby-version follows the same rules, put your ruby version or alias there
You can easily do that by placing an .rvmrc file at the base of your project.
I had the same problem. But, I found I had installed a ruby version globally while installing rvm.
I uninstalled that global version and everything started to work fine with .ruby-version and .ruby-gemset file in project's root directory.
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.
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.