I want to create a new Rails app. I am using rvm with ruby-2.1.2. I am usint the @global
gemset and plan to use bundler to manage gem dependencies. However, gem install rails
fails:
$ gem install rails
Fetching: concurrent-ruby-1.0.3.pre3.gem (100%)
Successfully installed concurrent-ruby-1.0.3.pre3
Fetching: minitest-5.9.0.gem (100%)
Successfully installed minitest-5.9.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: activesupport-5.0.0.gem (100%)
ERROR: Error installing rails:
activesupport requires Ruby version >= 2.2.2.
Yes, it is true I am using ruby-2.1.2 and not ruby-2.2.2, but shouldn't I still be allowed to use ruby-2.1.2? Are we not allowed to use ruby-2.1.2 anymore?
I thought maybe that ActiveSupport 5 was already installed in the @global
gemset and that ActiveSupport 5 required 2.2.2, but actually there is no ActiveSupport 5 in the @global
gemset:
$ rvm gemdir
/Users/myuser/.rvm/gems/ruby-2.1.2@global
$ cd /Users/myuser/.rvm/gems/ruby-2.1.2@global
$ cd gems
$ ls
bundler-unload-1.0.2 gem-wrappers-1.2.4 rake-10.1.0 rvm-1.11.3.9 tzinfo-1.2.2
concurrent-ruby-1.0.3.pre3 i18n-0.7.0 rdoc-4.1.0 test-unit-2.1.2.0
executable-hooks-1.3.2 minitest-5.9.0 rubygems-bundler-1.4.4 thread_safe-0.3.5
So how can I prevent this error from occurring while trying to use ruby-2.1.2?
You're allowed to use any ruby version of your will, however you can't use any ruby version with the latest version of Rails. When you do gem install rails
you're getting the latest Rails' version (Rails 5), which isn't compatible with Ruby 2.1.2 at all.
If you really want to use Ruby 2.1.2, try this: gem install rails -v 4.2.2
.
As the use of gemset, since I like this pretty organized, I never use the global. I always create a new gemset for every project. This guarantee that I can have many projects, each one with a ruby and rails version, without getting any incompatibility between the gems. This of gemset as your Ruby on Rails workspace. If you separate them by project, you will minimize the odds of oddities with gem incompatibility.
gem install rails
Above command will use latest version of rails, that is stable release of Rails 5, which require >= ruby 2.2.2.
We can use 2.1.2 with lower version of Rails. Please specify version at the time of installing rails may solve your issue, For Example:
gem install rails --version 4.2.4
or
gem install rails -v 4.2.4
Let me know if it works. Thank you.
I faced it fore CocoaPod and it fixes by the following:
Using RVM worked for me, I've followed instructions here
curl -sSL https://rvm.io/mpapis.asc | gpg --import - &&\
curl -L get.rvm.io | bash -s stable &&\
source /etc/profile.d/rvm.sh && /usr/local/rvm/bin/rvm reload &&\
/usr/local/rvm/bin/rvm requirements run &&\
/usr/local/rvm/bin/rvm install 2.2.4 &&\
/usr/local/rvm/bin/rvm use 2.2.4 --default && ruby --version
My environment was a Docker container with CentOS installed
If you're using rbenv
Please verify that rbenv is properly set up using this rbenv-doctor script:
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Rails version should be compatible with installed Ruby version. When you do gem install rails you're getting the latest Rails' version (Rails 5), which isn't compatible with Ruby 2.1.2 at all.
If you really want to use Ruby 2.1.2, try this: gem install rails -v 4.2.2. You can find ruby and rails version compatibility here and possible rails version here .
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.