这是对下面提到的问题的更新:
我刚刚发现根目录(即系统主目录)中有一个Gemfile和Gemfile.lock,当我创建一个新的gemset时,我相信它会使用这个Gemfile。在新创建的gemset中安装rails后,当检查rails版本或尝试创建新应用程序时,它会显示错误Your ruby version is 2.2.0, but your Gemfile specifies 2.1.5
,因为我的主目录中的Gemfile文件包含该ruby版本,如果删除该Gemfile并尝试创建新的rails应用程序,它会搜索该Gemfle。
我正在经历一段艰难的时光。我在ruby 2.2.0和rails 4.2.0中启动了一个新项目,并在我的项目文件夹中使用RVM创建了一个gemset。
-
创建宝石集。
$rvm use ruby-2.2.0@myapp --ruby-version --create
-
已安装最新轨道
$gem install rails
-
之后,我检查了rails版本,只是为了验证
$rails -v
但我收到了一个通知,上面写着CCD_ 2。我还没有我的应用程序文件夹,因为如果我尝试
$rails new .
,我会得到相同的输出
以下是RVM相关输出
- 我的RVM版本是1.26.10
-
rvm gemset list
gemsets for ruby-2.2.0 (found in /Users/samy/.rvm/gems/ruby-2.2.0) (default) global student-portal => myapp
-
全球宝石集的
gem list
bigdecimal (1.2.7, 1.2.6) bundler (1.7.13) bundler-unload (1.0.2) executable-hooks (1.3.2) gem-wrappers (1.2.7) io-console (0.4.3) json (1.8.2, 1.8.1) mini_portile (0.6.2) minitest (5.5.1, 5.4.3) nokogiri (1.6.6.2) power_assert (0.2.2) psych (2.0.12, 2.0.8) rake (10.4.2) rdoc (4.2.0) rubygems-bundler (1.4.4) rvm (1.11.3.9) test-unit (3.0.9, 3.0.8)
-
myapp gemset 的
gem list
actionmailer (4.2.0) actionpack (4.2.0) actionview (4.2.0) activejob (4.2.0) activemodel (4.2.0) activerecord (4.2.0) activesupport (4.2.0) arel (6.0.0) bigdecimal (1.2.7, 1.2.6) builder (3.2.2) bundler (1.7.13) bundler-unload (1.0.2) erubis (2.7.0) executable-hooks (1.3.2) gem-wrappers (1.2.7) globalid (0.3.2) hike (1.2.3) i18n (0.7.0) io-console (0.4.3) json (1.8.2, 1.8.1) loofah (2.0.1) mail (2.6.3) mime-types (2.4.3) mini_portile (0.6.2) minitest (5.5.1, 5.4.3) multi_json (1.10.1) nokogiri (1.6.6.2) power_assert (0.2.2) psych (2.0.12, 2.0.8) rack (1.6.0) rack-test (0.6.3) rails (4.2.0) rails-deprecated_sanitizer (1.0.3) rails-dom-testing (1.0.5) rails-html-sanitizer (1.0.1) railties (4.2.0) rake (10.4.2) rdoc (4.2.0) rubygems-bundler (1.4.4) rvm (1.11.3.9) sprockets (2.12.3) sprockets-rails (2.2.4) test-unit (3.0.9, 3.0.8) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) tzinfo (1.2.2)
-
which ruby
给出/Users/samy/.rvm/rubies/ruby-2.2.0/bin/ruby
-
which rails
给出/Users/samy/.rvm/gems/ruby-2.2.0@myapp/bin/rails
该文件包含
#!/usr/bin/env ruby_executable_hooks # # This file was generated by RubyGems. # # The application 'railties' is installed as part of a gem, and # this file is here to facilitate running it. # require 'rubygems' version = ">= 0" if ARGV.first str = ARGV.first str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding if str =~ /A_(.*)_z/ and Gem::Version.correct?($1) then version = $1 ARGV.shift end end gem 'railties', version load Gem.bin_path('railties', 'rails', version)
我尝试删除和重新安装RVM,但我没有工作。
此外,我还尝试过用不同的宝石集和ruby 2.1.5制作应用程序,但当我尝试做rails new app
时,会出现不同的错误。我得到了Could not find slop-3.6.0 in any of the sources
Run 'bundle install' to install missing gems.
,但一旦我得到bundle install
,我就不能运行rails new app
命令,因为它通知
Can't initialize a new Rails application within the directory
of another, please change to a non-Rails directory first.
如有任何帮助,我们将不胜感激。如果你需要更多的信息,我随时准备提供。
提前谢谢。干杯
我也遇到过类似的问题,使用本指南从头开始帮助很大。虽然这似乎是另一本指南,但我发现它比其他指南更系统、更详细。
Rails应用指南:安装RubyonRails·Ubuntu Linux
或者,试试Rails应用指南:更新到Rails 4.2
注:
Rails不仅仅是一颗Ruby宝石,它也是一颗复杂且快速发展的宝石生态系统使用所需的所有宝石的最新版本发展