简体   繁体   中英

How do you install Rails 4.0 in an RVM gemset?

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, eg 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.

除了上面的使用技巧之外,如果你没有指定gem版本,你就不会获得测试版或预版本,所以要获得rails 4,你需要:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM