1

我尝试使用以下方法更新 Rails:

sudo gem install rails --version 4.0
sudo gem install rails --version 4.0.0
sudo gem install rails -v 4.0
sudo gem install activesupport -v '4.0.0'

但是,我总是遇到同样的错误:

ERROR:  Error installing activesupport:
        activesupport requires Ruby version >= 1.9.3.

系统信息:

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2]
Rails 3.2.7

可能是什么问题呢?

更新:

我发现终端的差异:

在 aptana 工作室:

> gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.6
  - RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-11
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/kai/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

> gem list
*** LOCAL GEMS ***
actionmailer (3.2.7, 3.2.6)
actionpack (3.2.7, 3.2.6)
activemodel (3.2.7, 3.2.6)
activerecord (3.2.7, 3.2.6)
activeresource (3.2.7, 3.2.6)
activesupport (3.2.7, 3.2.6)
arel (3.0.2)
atomic (1.1.12)
bcrypt-ruby (3.0.1)
builder (3.0.4, 3.0.0)
bundler (1.3.5, 1.0.0)
capistrano (2.13.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.4.0, 1.3.3)
curb (0.7.12)
daemons (1.1.0)
devise (2.1.2)
erubis (2.7.0)
eventmachine (0.12.10)
execjs (1.4.0)
flickraw (0.9.6)
highline (1.6.16)
hike (1.2.1)
i18n (0.6.4, 0.6.1, 0.6.0)
journey (1.0.4)
jquery-rails (2.1.3, 2.1.1, 2.0.2)
json (1.7.5, 1.7.4, 1.5.1)
kgio (2.7.4)
mail (2.4.4)
mime-types (1.19)
minitest (4.7.5)
msgpack (0.3.9apple)
multi_json (1.7.9, 1.3.7, 1.3.6)
net-scp (1.0.4)
net-sftp (2.0.5)
net-ssh (2.6.2)
net-ssh-gateway (1.1.0)
orm_adapter (0.4.0)
patron (0.4.11)
pg (0.10.1)
polyglot (0.3.3)
rack (1.4.1, 1.2.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.2, 0.6.1)
rails (3.2.7, 3.2.6)
railties (3.2.7, 3.2.6)
raindrops (0.10.0)
rake (10.0.3, 0.9.2.2)
rdoc (3.12)
ref (1.0.2)
ruby_protobuf (0.4.11)
rubygems-update (2.0.6)
sass (3.2.3, 3.2.1, 3.1.20)
sass-rails (3.2.5)
sinatra (1.2.0)
sprockets (2.1.3)
sqlite3 (1.3.6)
sqlite3-ruby (1.2.4)
thin (1.2.8)
thor (0.16.0, 0.15.4)
thread_safe (0.1.2)
tilt (1.3.3, 1.2.2)
treetop (1.4.12, 1.4.10)
tzinfo (0.3.37, 0.3.35, 0.3.33)
uglifier (1.2.7)
warden (1.2.1)

因此 ruby​​ 应用程序require 'activesupport'在启动时返回:

/Users/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': cannot load such file -- activesupport (LoadError)
    from /Users/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
    from /Users/kai/Documents/Aptana Studio 3 Workspace/flickr_empty_project/app/app.rb:5:in `<main>'

在 bash 中:

> gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.6
  - RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin11.4.2]
  - INSTALLATION DIRECTORY: /Users/kai/.rvm/gems/ruby-2.0.0-p247
  - RUBY EXECUTABLE: /Users/kai/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/kai/.rvm/gems/ruby-2.0.0-p247/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/kai/.rvm/gems/ruby-2.0.0-p247
     - /Users/kai/.rvm/gems/ruby-2.0.0-p247@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/


> gem list

*** LOCAL GEMS ***

actionmailer (4.0.0)
actionpack (4.0.0)
activemodel (4.0.0)
activerecord (4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
arel (4.0.0)
atomic (1.1.12)
bigdecimal (1.2.0)
builder (3.1.4)
bundler (1.3.5)
bundler-unload (1.0.1)
erubis (2.7.0)
flickraw (0.9.6)
hike (1.2.3)
i18n (0.6.4)
io-console (0.4.2)
json (1.7.7)
mail (2.5.4)
mime-types (1.23)
minitest (4.3.2)
multi_json (1.7.9)
polyglot (0.3.3)
psych (2.0.0)
rack (1.5.2)
rack-test (0.6.2)
rails (4.0.0)
railties (4.0.0)
rake (10.1.0, 0.9.6)
rdoc (4.0.0)
rubygems-bundler (1.2.2)
rvm (1.11.3.8)
sprockets (2.10.0)
sprockets-rails (2.0.0)
test-unit (2.0.0.0)
thor (0.18.1)
thread_safe (0.1.2)
tilt (1.4.1)
treetop (1.4.14)
tzinfo (0.3.37)
4

3 回答 3

2

希望本文档对您有所帮助。请看链接

Step 1:
 rvm get head (to get the latest version of rvm)

Step 2:
 rvm install 2.0.0 (to install ruby)

Step 3:
 rvm use 2.0.0

Step 4:
 rvm gemset create rails4

Step 5:
 gem install rails
于 2013-08-12T05:33:58.470 回答
1

使用安装任何 gemsudo将尝试安装或覆盖内置 Ruby 的 gem。不要尝试将 Rails 安装到 Mac 系统版本的 Ruby 中;不用管 Apple 的 Ruby,而是使用 RVM 或 rbenv 将 Ruby 的副本安装到沙箱中。

Apple 安装 Ruby 是为了自己使用,而不是为了你的。您当然可以使用它,但如果您想拥有比默认更现代的东西,请安装更新的东西。

如果您使用 RVM 或 rbenv 将 Ruby 安装到您的主目录到沙箱中供您自己使用,则在添加 gem 时您不需要使用,因为您应该拥有管理这些文件的所有权和完全权限sudo

于 2013-08-12T02:38:31.850 回答
1

Gem 似乎并不总是使用您的 shell 使用的相同路径。尝试运行gem env以查看正在使用的 RUBY VERSION 和 RUBY EXECUTABLE gem。

如果我怀疑 gem 使用的是 Mac OS X 系统默认值(1.8.x),你可以尝试强制 gem 命令的路径:

PATH=<path-to-correct-ruby>:$PATH gem env

其中path-to-correct-ruby可能类似于 ~/.rmv/rubies/default。

于 2013-08-12T02:07:03.320 回答