Your Ruby version is 1.9.3, but your Gemfile specified 2.1.0

社会主义新天地 提交于 2019-11-30 18:28:03

问题


When I run

rails server

I get the error.

There is some problem loading the gemsets

$rvm list
rvm rubies
ruby-1.9.3-p484 [ i686 ]
ruby-2.0.0-p353 [ i686 ]
=* ruby-2.1.0 [ i686 ]
# => - current
# =* - current && default
#  * - default

$ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [i686-linux]

$rails -v
Your Ruby version is 1.9.3, but your Gemfile specified 2.1.0

$bundle show rails
/home/prasad/.rvm/gems/ruby-2.1.0/gems/rails-4.0.1

$bundle exec rails s
Your Ruby version is 1.9.3, but your Gemfile specified 2.1.0

bundle exec ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [i686-linux]

I did bundle install and tried to start the rails server but it gave the same error.

bashrc

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

Gemfile

source 'https://rubygems.org'
ruby '2.1.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '2.3.1'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# Use jquery as the JavaScript library
gem 'jquery-rails', '3.0.4'
gem 'haml', '4.0.4'
gem 'actionpack-page_caching', '1.0.2' #use caches_pages in rails 4
gem 'twitter'
gem 'mina'
group :production do
  gem 'dalli', '2.6.4'
  gem 'therubyracer'
end
group :test do
  gem 'watir-rails'
end
group :staging do
  gem 'rails_12factor'
end
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

UPDATE

I tried restarting my computer, but it did not fix the problem.


回答1:


The problem is your PATH environment variable, it has to match GEM_PATH and in your case it does not. To fix it run:

rvm get stable --auto-dotfiles

This will update your shell initialization files and make sure rvm is properly loaded. Then open a new terminal (close the application and open it again), and run:

rvm use 2.1.0

On both steps read all the messages printed to you. They are important and contain information about how to fix your problems. RVM detects problems and tries to fix them or warns you about them if they can not or should not be fixed automatically.




回答2:


I had a similar issue, and used @mpapis advises, fixing my $PATH and rvm loading.

But I had to run gem install bundler to update bundler and make it recognize my current ruby version again.




回答3:


I'd recommend using a .ruby-version file in the top-level directory of your project. That file would contain containing the ruby version spec'd in your Gemfile, e.g.

2.1.0

That apparently is the cross-{rbenv,rvm} way of spec'ing the version now.



来源:https://stackoverflow.com/questions/21060721/your-ruby-version-is-1-9-3-but-your-gemfile-specified-2-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!