How do you install Rails 4.0 in an RVM gemset? - ruby-on-rails

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

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

How do I upgrade the Ruby version of my project?

I recently started learning Rails using Ruby 1.9.3p385, and I'm trying to develop a small project with it.
I'm using Linux so I installed Ruby using RVM.
I developed a few pages, following some tutorials. I would like to upgrade my project to use Ruby 2.0.0. What do I have to do?
I installed Ruby 2.0.0 with RVM:
rvm install 2.0.0
Everything seems OK, so I tried to use it:
rvm use 2.0.0-p247
But when I try to run my Rails server using rails server, I get the following message:
bash: rails : command not found
I've read the RVM documentation about upgrading Ruby but I don't really understand what it does; I'm afraid of breaking everything.
Does it will upgrade my project in a way it will use Ruby 2.0.0 or what should I do?
Next, I will want to upgrade also to Rails v4.
Your gemset which comes with new Ruby version is empty. Try this:
gem install bundler # this will install bundler
bundle # this will use bundler to install required gems
rails server
Did you run rvm use 2.0.0-p247 or did you use rvm use 2.0.0-p247 --default? The later will set Ruby v.2.0 as the default for your system. Failure to do that will revert your Ruby to whatever RVM's default is the next time you log into your system or open a new terminal window.
When RVM installs a new version of Ruby, it installs only the default gems. It CAN upgrade a Ruby to another version, and optionally install the existing gems as it does so, but that's not what you asked it to do: rvm install 2.0.0 only installs Ruby. At that point you have to install the other gems you need, which would include Rails.
My general practice when installing various versions of Ruby and the gems I like is to use two command-line pipes to dump my existing gems, then (re)install them. First I switch to an existing Ruby whose gems I want to duplicate, then run:
gem list | cut -f1 -d' ' > ~/gem_list
Then I switch to the newly installed one, and run this:
xargs gem install < ~/gem_list
This does a completely clean install of the gems, outside of RVM's commands.
Why? Habit. Paranoia based on some "experiences" I had in the past with RVM.
Once that's all done and I have brand-spanking-new Ruby and gems, I'll proceed with running bundler or other housekeeping chores.
when you install a new ruby version, you have to reinstall all the gems for that version. start of by installing bundler first. Then run bundle in your rails root directory. When you encounter no errors, you're good to start the rails server. Good luck!
run bundle install on the application root, you need to reinstall all your dependencies for the new version of Ruby.

Ruby version conflict using rvm

I have some conflicts of ruby version.
When I run ruby -v in my terminal (in osx), I get the 1.8.7 version. I tried to upgrade ruby version, installing rvm, with this command curl -L https://get.rvm.io | bash -s stable --autolibs=3 --rails. Then I tried to run rvm install ruby-1.9.3-p362, and I was told that rvm was not a found command. So I ran source /Users/host/.rvm/scripts/rvm install ruby-1.9.3-p362, this worked and when I run in my bash ruby -v, I get ruby 2.0.0. But it seems to be related to my current terminal session since when I run ruby -v in another session, I always get 1.8.7 version. How can I set on my .bash_profile (or elswhere) the right version of ruby (and of rails) ?
RVM allows to install multiple versions of ruby on a single *nix box. Each ruby version is kinda sandboxed from another one. For the first time, you will need to specify a default version of ruby. This will be needed only for the first time.
rvm use 1.9.3-p290 --default
To switch to another version, simply type:
rvm use 1.9.2
Rails is just a gem. To get the most out of RVM, create a gemset and install all gems for one ruby version within one gemset. i.e. one gemset per ruby version.
This works like :
rvm gemset create my_gem_set
Gemset 'my_gem_set' created.
rvm gemset use my_gem_set
You can also use .rvmrc file in your project directory to 'load' just the required gems for your app. There is one .rvmrc per project. You can refer rvm.io for docs on rvmrc
You should set the default ruby via rvm: https://rvm.io/rubies/default/
rvm --default use <ruby_version>
You need to enable login shell in your terminal emulator, here is example how to set it up in gnome-terminal https://rvm.io/integration/gnome-terminal/

Get confused of some rails concepts, needs some explanations

I got confused of some Rails' concepts like: gemset, rubygems, bundler . I have following three questions:
1. After I installed the RVM tool, what are the correct steps to setup the development enviroment for creating a rails project (say rails v2.3 project)
2. What is the difference between "gem install XXX" and "bundle install"? Can I understand it in the way that "bundle install" install all gems needed in the app at once while "gem install XXX" only install the specified "XXX" gem ? Are there any other difference? Why not use bundler to install specific rails then?
3. If I want to use rails v3.0 for project_one, and use rails v2.3 for project_two. How to create the two projects with the specific rails versions? How about different ruby versions for different projects? Do I only need to specify the needed version in Gemfile or install the needed version under the project path?
RVM allows you to create different gemsets alongside different ruby versions.
You can install different versions of ruby with rvm install.
rvm install 1.8.7
rvm install 1.9.2
rvm list known will tell you the available ruby implementations you can install.
Say, you have two projects: project_one and project_two, and both of them have different gem dependencies. So you'll want to create two empty gemsets with, say, Ruby 1.9.2.
rvm gemset create 1.9.2#project_one
rvm gemset create 1.9.2#project_two
To use project_two's gemset, you can use rvm use to select the gemset.
rvm use 1.9.2#project_two
You can also add the above command into a file called .rvmrc in the root path of your rails application, which rvm will load automatically whenever you cd into the app's root directory.
If you want to use Rails 2.3.8 for project_one,
rvm use 1.9.2#project_one
gem install rails -v 2.3.8
and Rails 3.1.0 for project_two,
rvm use 1.9.2#project_two
gem install rails -v 3.1.0
The difference between gem install and bundle install is that gem install installs only the specified gem into your gemset, while bundle install installs all the gems located in your app's Gemfile.
1) If you have a rvm setup I propose add in in your app file .rvmrc
and in that file:
rvm --create ree-1.8.7-2011.03#myappname
This will alway use specify version of ruby (in that case 'ree-1.8.7-2011.03') and all gems will be installed in rvm gemset named: myappname. This file will always make sure every time you go to that folder from bash_console it will point rvm to correct environment.
2) If you have rvm setup then:
gem install XXX creates gem in specify rvm gemset or if not global rvm gemset
sudo gem install XXX will add gems to you Global gems
Like you said, you should always use Bundle install, and group gems for development,test, production.
3) This can achieve like I said in point 1) just create this file in your app

Resources