ActiveRecord需要Ruby版本大于等于2.2.2。

3
我需要在rake中使用activerecord,但是当我尝试安装它时,它会显示以下信息:
activesupport-5.0.0.1 requires ruby version >= 2.2.2,
which is incompatible with the current version, ruby 1.9.3p484

我尝试使用rbenv更改ruby版本为2.2.2

rbenv versions

输出

系统 * 2.2.2 (由 /home/user/.rbenv/version 设置) 2.3.1

但是当我执行 ruby -v 命令时,它显示

ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

我也试过卸载它,但在安装rake时出现了问题。

sudo apt-get install rake

我得到了这个输出

以下额外的软件包将被安装:

libruby1.9.1 ruby ruby1.9.1

但是,我需要激活2.2.2或更高版本的ruby(ruby -v),以便安装active record并使用rake命令。


2
你运行了 rbenv global 2.2.2 吗? - Jagdeep Singh
是的,我做了,rbenv版本上有一个*,但它仍然显示1.9.3p484是活动状态。 - Strahinja90bg
2个回答

1
你搞砸了事情。
sudo apt-get install rake

这是一个系统级的 Debian 软件包,与 rbenv 无关。如果你已经卸载了系统自带的 Ruby,也应该将其一并删除。

然后执行以下操作:

rbenv global 2.2.2
gem install rake # ⇐ THIS

0

我得到了帮助并解决了这个问题。在我的情况下,我改变了gemfile.lock文件的内容。

    GEM
  remote: http://rubygems.org/
  specs:
    activemodel (5.0.0.1)
      activesupport (= 5.0.0.1)
    activerecord (5.0.0.1)
      activemodel (= 5.0.0.1)
      activesupport (= 5.0.0.1)
      arel (~> 7.0)
    activesupport (5.0.0.1)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (~> 0.7)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    arel (7.1.4)
    concurrent-ruby (1.0.2)
    i18n (0.7.0)
    minitest (5.9.1)
    mysql2 (0.4.5)
    rake (11.3.0)
    thread_safe (0.3.5)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)

PLATFORMS
  ruby

DEPENDENCIES
  activerecord
  mysql2
  rake

BUNDLED WITH
   1.13.6

针对这个问题(最重要的是activerecord版本):

GEM
  remote: http://rubygems.org/
  specs:
    activemodel (3.1.3)
      activesupport (= 3.1.3)
      builder (~> 3.0.0)
      i18n (~> 0.6)
    activerecord (3.1.3)
      activemodel (= 3.1.3)
      activesupport (= 3.1.3)
      arel (~> 2.2.1)
      tzinfo (~> 0.3.29)
    activesupport (3.1.3)
      multi_json (~> 1.0)
    arel (2.2.1)
    builder (3.0.0)
    i18n (0.6.0)
    multi_json (1.0.4)
    mysql2 (0.3.11)
    rake (0.9.2.2)
    tzinfo (0.3.31)

PLATFORMS
  ruby

DEPENDENCIES
  activerecord
  mysql2
  rake

BUNDLED WITH
   1.13.6

然后安装了activerecord和其他我需要的东西

gem install activerecord -v 3.1.3
sudo apt-get install libmysqlclient-dev
sudo apt-get install ruby1.9.1-dev
gem install activerecord-mysql2-adapter
gem uninstall mysql2
gem install mysql -v 0.3.11

而且耙子起作用了。

 rake db:migrate[]

希望这能帮助到某个人! :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接