selection of rails -package - ruby-on-rails

I just installed rvm, ruby 1.9.3, rails 4.0 and rails 3.0
The problem is that I have to work with an application using ruby 1.9, and do not know how to select the right package. I would also like to know how to select a particular rails from the command line
One other thing: I can use Rails 4.0 for Ruby 1.9.3?

You shouldn't install two Rails versions together, this can lead to various strange behaviours, instead use Gemsets (decribed below).
To install specified Ruby version: rvm install 1.9.3-p385 - yes, you can even specify pathlevel.
To use that Ruby: rvm use 1.9.3-p385 - or just rvm use 1.9.3 if you don't have other 1.9.3 versions.
You should also create Gemset for your app so you won't pollute your rvm's specific ruby install with gems from other projects which you will probably create later.
To do that write rvm gemset create put_name_here, you will have now new Gemset in scope of your selected rvm's Ruby install.
To use that Gemset write rvm gemset use put_name_here. - You can also do rvm use 1.9.3#put_name_here - that will select both Ruby and Gemset with one command.
Now you can do bundle and all gems will be installed to specified Gemset under chosen Ruby version.
To make your life easier you can create in root of your app two files containing:
.ruby-version
1.9.3-p385
.ruby-gemset
put_name_here
And since then rvm should automatically change Ruby version and select specified Gemset when you will enter that directory.
To list installed Rubies and created Gemsets: rvm list and rvm gemset list (that shows Gemsets under current Ruby only).
And yes, you can use Rails 4.0 with Ruby 1.9.3
Also, you should check rvm homepage, everything is well described there.

Related

Stuck on ruby -v ruby 2.0.0p648 even though 2.3.1 is installed, how do i get it to change?

I've tried everything. Every YouTube guide. Nothing simply explains how to get from point A to point B.
Homebrew
Git
RVM
and Ruby are all installed.
For some reason Rails is not.
I'm new to the whole ruby thing, and getting everything installed has been an absolute nightmare. Everything is out of date. What do I do?
Assuming you have RVM installed correctly:
1) Open Terminal.
2) Type rvm list to see which versions of Ruby you have installed.
3) Type rvm use ruby-2.3.1 if you want to use Ruby 2.3.1.
4) Type rvm gemset create Rails500 to create a gemset for Rails 5.0.0
5) Type rvm gemset use Rails500 to make Rails 5.0 your current gemset
6) Type gem install rails -v 5.0.0 to install Rails 5 to your Rails500 gemset
7) Type bundle install bring everything up to date.
Now you have Rails 5.0 running under a Rails500 gemset against Ruby 2.3.1. Remember to use ruby-2.3.1 and use gemset Rails500 whenever you start a new session in Terminal if you want to maintain multiple versions of Ruby and multiple gemsets.
To make a version of Ruby default, type the following into Terminal:
rvm --default use 2.1.1
To keep a default gemset, just rvm gemset use default and make sure you install your gems into that default gemset by use-ing it before installation.
This covers 80% of everything you'll need to know about RVM.
Also, remember to never install rbenv, because it's not compatible with RVM -- stick with one or the other.
EDIT:
It seems you're having problems with your Terminal settings as well.
1) Open Terminal
2) From the Terminal menu, select Preferences
3) Select the Command (complete path) radio button
4) Make sure the text field beneath the radio button reads /bin/bash
5) Close the Preferences dialog and restart Terminal
6) Try using Ruby 2.3.1 via RVM
If you have installed RVM,
rvm use 2.3.1
Then check gems in current gemset using,
rvm gemset list ### gives a list of gemset for ruby 2.3.1
gem list ###installed gems in current gemset
Let me know,.if it didn't work.
Assuming you have got rvm, just write:
rvm install 2.3.1
rvm use 2.3.1
Then you can install rails by gem install rails command.

How to upgrade ruby version of ruby on rails app using rvm

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

Specifically stating the Ruby version in my Rails project (RVM)

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.

Can we install two different versions of ruby and map them to respective versions of rails on the same server?

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

RVM rails 3.2 and rails 2.3

Im having trouble setting up a development environment. I need some tutorial on how to install rvm with rails 3.2 and rails 2.3.14 side by side. I tried installing rvm 1.8.7 then rails 2.3.14 and rvm 1.9.3 then rails 3.2. After finishing I can't seem to create a gemset and I tried to switch rvm 1.8.7 buy when I generate(ruby script/generate) it showed me that it was not recognized.
Ideally speaking, you would want to create your gemsets before installing the rails gems. This way the two versions are segregated. I would do something like the following:
rvm --create use 1.8.7#some-gemset-name
gem install rails -v 2.3.14
That should install and use those specific versions together. Then for the newer versions
rvm --create use 1.9.3#some-other-gemset-name
gem install rails
Then you would just need to change rubies and gemsets when you need to with rvm use version#gemset-name. Another approach is to have the ruby and gemset change with each rails project by creating a .rvmrc file in the root of your rails project. The contents of that file would be similar to the following:
rvm version#gemset-name
I would also recommend checking out the RVM Docs as this is just the tip of the iceberg when working with RVM.

Resources