How do you install Rails 4.0 in an RVM gemset?

2019-01-30 12:17发布

问题:

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?

回答1:

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.



回答2:

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


回答3:

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.



回答4:

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