Hi I am beginner to ruby on rails. I have following this on my machine
nilkash#nilkash:~$ ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]
nilkash#nilkash:~$ rails -v
Rails 3.2.3
nilkash#nilkash:~$ rvm -v
rvm 1.19.6 (master) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
nilkash#nilkash:~$ rvm list
rvm rubies
=* ruby-1.9.3-p392 [ i686 ]
# => - current
# =* - current && default
# * - default
nilkash#nilkash:~$ rvm gemset list
gemsets for ruby-1.9.3-p392 (found in /home/nilkash/.rvm/gems/ruby-1.9.3-p392)
(default)
global
latest_rails_stable
=> rails3tutorial2ndEd
I also install rails version 4.0.0. But I don't know how to use different versions of rails. when i create new project it shows rails version 3.x. I want to upgrade it to version 4. How to check list of all installed rails and how to use latest one. Need Help. Thank you.
I also install rails version 4.0.0. But I don't know how to use different versions of rails. when i create new project it shows rails version 3.x. I want to upgrade it to version 4. How to check list of all installed rails and how to use latest one. Need Help. Thank you.
this is because you're still using the current gemset rails3tutorial2ndEd
You need to create a different gemset:
rvm gemset create <new_gemset_name>
then use it:
rvm gemset use <new_gemset_name>
and finally install a new rails version:
gem install rails -v <version_number>
only after doing these things will you be able to make a new project with a different rails version.
If you want to only do a quick command in different rails version you can do:
$ rails _4.0.1_ new MyRailsApp
That way you don't have some gems installed twice as you do when you use gem sets. Bundler should handle the rest so you should only need one gemset.
In your Gemfile, you will see the line gem 'rails', '3.2.3' or which version you are using. You can modify it and execute bundle again.
You can execute gem list --local on the console to check all versions of your gems installed.
In my opinion, you would better to use rvmrc to define different gemset in the different projects, it reduces chaos. see details: https://rvm.io/workflow/projects
you can create gemset with rvm gemset create <gemset name> then switch to it rvm use <ruby version>#<gemset name> and install another version of rails in this gemset
You can have a different ruby version for different gems.
I am going to give an example way to manage for ruby 2.1.10 with rails 4.1 and ruby 2.4.1 with rails 5.1.
This is a quote from rvm official website take a look.
RVM gives you compartmentalized independent ruby setups. This means
that ruby, gems and irb are all separate and self-contained - from the
system, and from each other.
You may even have separate named gemsets.
I am supposing you had already installed a different version of ruby. To list user rvm list. It will list installed ruby and currently which one be using.
if you have not installed any no problem follow this official rvm documentation.
Install 2.1.10 with rails 4.1.0
rvm use 2.1.10
gem install rails -v 4.1.0
rvm use 2.1.10#rails410 --create
rvm 2.1.10
ready and good to go for ruby 2.1.10 with rails 4.1.0
Install 2.4.1 with rails 5.1.0
rvm use 2.4.1
gem install rails -v 5.1.0
rvm use 2.4.1#rails510 --create
rvm 2.4.1
ready and good to go ruby 2.4.1 with rails 5.1.0
You have set 2 gemsets above. Just use rvm 2.1.10 for ruby 2.1.10 and rails 4.1 and rvm 2.4.1 for ruby 2.4.1 and rails 5.1.0.
Related
I need to stick with Rails 5.0.0 for now. I'm using a gemset (rails500) and ruby-2.3.3 with rvm. I told rvm to use the gemset and uninstalled the other Rails version (5.0.1) from the gemset using the command 'gem uninstall rails'. After that I used the command 'gem install rails --version=5.0.0' to make sure my desired Rails is in the gemset.
Now when I do a 'rails -v' the response is 'Rails 5.0.1'. Why isn't it 'Rails 5.0.0'? When I do a "gem list | egrep '^rails '" the response is 'rails (5.0.0)'.
Related question: how can I be sure this version of rails is not 5.0.0?
Please follow this for setting the rails version you want:
rvm has nothing to do with rails. rvm is used to manage multiple ruby installations. And each of your ruby installations can be associated with multiple gemsets. For instance, say you have ruby 1.9.3 installed and you created two gemsets for ruby 1.9.3: gemsetA and gemsetB. If you tell rvm to use ruby 1.9.3 with gemsetA, that means:
Your ruby programs will be executed by ruby 1.9.3.
Your ruby programs can require any gem in gemsetA (which then allows your program to use the methods (or classes) defined in gemsetA), but any gems in gemsetB cannot be seen by your ruby program.
Here's a concrete example:
~$ rvm list
rvm rubies
ruby-1.8.7-p370 [ i686 ]
* ruby-1.9.3-p194 [ x86_64 ]
=> ruby-2.0.0-p0 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
# * - default
~$ rvm use 1.9.3-p194
Using /Users/7stud/.rvm/gems/ruby-1.9.3-p194
.
~$ rvm gemset list (This lists only the gemsets for the current ruby version)
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
programming
rails3tutorial
rails4
~$ rvm gemset use programming
Using ruby-1.9.3-p194 with gemset programming
After I do that, my ruby programs will be executed by ruby 1.9.3 and any gems in the programming gemset can be required into my ruby program. You can use a shortcut to perform both those commands in one step:
rvm use ruby 1.9.3-p194#programming
You just combine the ruby version and the gemset with an '#' between them.
$ rails -v
Rails 4.0.0
This is because the current gemset contains the gem for rails 4.0.0. If you want to see $ rails -v output Rails 3.2.14, then you need to tell rvm to switch to a gemset that contains the rails 3.2.14 gem.
However, you can make rvm automatically switch to the proper rails version and gemset for your rails project. In your Gemfile, add a comment after the ruby version:
ruby '2.0.0'
ruby-gemset=railstutorial4_gems
Then whenever you switch to the directory containing your rails project, rvm will automatically switch the current ruby to ruby 2.0.0 and the current gemset to railstutorial4_gems. If you change directories out of your rails app, rvm will change the current ruby and the current gemset back to what they were.
I'm just a rails beginner, but here are the steps I use to create a new project, which are straight out of the railstutorial book (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book)
1)
.../rails_projects$ rvm use # --create
e.g.
.../rails_projects$ rvm use ruby-1.9.3-p194#myapp_gemset --create
2)
.../rails_projects$ gem install rails --version 3.2.14
Because the current gemset is the myapp gemset, that command installs the rails 3.2.14 gem into the myapp gemset.
3)
.../rails_projects$ rails new myapp
.../rails_projects$ cd myapp
The current gemset is still myapp_gemset.
4)
.../rails_projects/myapp$ rails -v
Rails 3.2.14
In case anyone was wondering what the heck the following two gemsets are all about:
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
rvm creates those two gemsets for every ruby version you install. After you install a ruby version, if you don't create a gemset yourself for that ruby version, and you install a gem, then the gem goes into the (default) gemset. And, if you want all your gemsets to contain a certain gem, you can switch to the global gemset and install the gem there.
Update: -------
To maintain compatibility with other ruby version managers, you can specify the ruby version and gemset name for your project in a different file rather than in the Gemfile:
$ cd ~/rails_projects/myapp
~/rails_projects/myapp$ echo 2.0.0 > .ruby-version
~/rails_projects/myapp$ echo myapp_gemset > .ruby-gemset
You'll still get the same automatic ruby version and gemset switching when you cd into your project's directory. See the rvm docs here.
The apparent answer is given by ryanjm at
https://github.com/rubygems/rubygems/issues/542
$ gem uninstall railties -v 5.0.1
is necessary after
$ gem uninstall rails -v 5.0.1
I am planning to run ruby 2.3.1 version with Rails 5 on Mac OSX.
1 I installed rbenv then install ruby version 2.3.1.
rbenv version
2.3.1 (set by /D/testProject/.ruby-version)
2 Update gem
gem update --system
Latest version currently installed. Aborting.
3 System ruby version:
ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
But when i run gem update rails, i got
ERROR: Error installing rails:
activesupport requires Ruby version >= 2.2.2.
So my question is how to make the gem update rails according to rbenv ruby version, not system version? Then i can update to Rails 5.
or
Do i have to update my system version of ruby to update to Rails5.
EDIT
I have ran rbenv local 2.3.1 (.ruby-version was created) already. But still can't update to Rails5
Thank you!
EDIT
which ruby
/usr/bin/ruby
I update my system version of ruby solved the issue.
brew install ruby
you can use this command:
$ rbenv local 2.2.2
(this will generate a .ruby-version file)
Assuming you have already updated ruby using something like
sudo gem update --system
You can then set the rvm gemset lst to use the global version(s) installed.
rvm gemset list
rvm gemset use global -save
I am trying to install Rails into a new rvm gemset.
I tried the following:
rvm gemset create rails-4.0
output: gemset created rails-4.0
Next I did:
rvm 2.0.0#rails-4.0
rvm gemset list:
gemsets for ruby-2.0.0-p0 (found in /Users/me/.rvm/gems/ruby-2.0.0-p0)
(default)
global
=> rails-4.0
rails -v
Rails is not currently installed on this system. To get the latest
version, simply type:
$ sudo gem install rails
Do the rvm commands I listed not install rails 4.0?
This command:
rvm gemset create rails-4.0
is creating basically a directory structure to hold the gems. You could have just as easily called it something other than "rails-4.0" like "foo" and it would be the same behavior.
This command:
rvm 2.0.0#rails-4.0
Switches to Ruby 2.0.0 and tells it to use the new gemset named rails-4.0. Again, that could be "foo" or whatever you called it.
Now, to get Rails 4.0.x, you'd do:
gem install rails --version=4.0
As Barrett pointed out earlier, to get a pre/beta/rc release, you can specify the whole version string, e.g. gem install rails --version=4.0.0.rc2.
Don't sudo, because you shouldn't sudo with rvm, even though it tells you to. With the "system ruby" (ruby not installed by rvm), it may be installed as root, so you need superuser (su) access (superuser do or "sudo") to do that. But, rvm has you install things as the current user, therefore you don't need to sudo.
In addition to the usage tips above, if you don't specify the gem version you won't get the beta or pre version, so to get rails 4, you need:
gem install rails --version=4.0.0.rc1
Maybe try InstallRails?
http://installrails.com/ is a guide for installing rails that deals with these issues for various Operating Systems and setups. It might prove helpful for something like this.
Other answers shows instructions for creating the gemset using default ruby version.
For creating a gemset and use it with different ruby version please follow the instructions below:
Let's say on my machine I have following ruby versions installed and 2.2.0 is the default.
=*ruby-2.2.0 [ x86_64 ]
ruby-2.2.1 [ x86_64 ]
ruby-2.2.3 [ x86_64 ]
Now I have forked a repository from Github and want to test out the repo's code with Rails 5 (edge version) and Ruby 2.2.3 (the latest stable version at the time of this writing). And I prefer using gemsets so I ran following commands:
rvm use 2.2.3#forked-repo --create
That's actually a shortcut for
rvm 2.2.3
rvm gemset create forked-repo
Next I would run following command to install bundler:
forked_repo_root$ gem install bundler
forked_repo_root$ bundle
That should install the gems used in your forked-repo in the gemset created above.
Reference: https://rvm.io/gemsets/creating
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.
I am actually reading a rails book that is written for rails 2.3.5. I want to test Rails 3 beta as well. Is it possible to have such a setup in my Mac OS leopard?
I have tried with gem list -d rails. There are many versions stored in my mac but I don't know how to use different versions of rails while creating applications using rails command
While RVM is great there's no need for it in this use-case.
Install the Rails 3 gem: gem install rails—pre
Create new project: rails project_name (this will use the latest version installed)
To create projects with a specific version: rails _2.3.5_ project_name
Yes! Try rvm. It is awesome, you can have many different versions of Ruby, and for each one you can have different versions of gems. And you can run the same tests on all those versions. Isn't that cool?!
Quick How-To:
$ rvm install ruby-1.8.7 --default
$ gem install rails -v 1.0.0
$ rvm gemset create rails238
$ rvm 1.8.7#rails238
$ gem install rails -v 2.3.8
Now,
$ rvm 1.8.7
will give you ruby 1.8.7 and rails 1.0
And,
$ rvm 1.8.7#rails238
will give you ruby 1.8.7 and rails 2.3.8
You can make 2.3.8 as default one with
$ rvm use 1.8.7#rails238 --default
BTW rvm is documented really good.
The way to do this anymore is to use RVM, the Ruby Version Manager, which isolates different Ruby environments from each other.
A coworker of mine did a blog entry on setting up Rails 3 and RVM (and Ruby 1.9), which you might find interesting.