【问题标题】:Rails and Ruby versions always conflict, and will never be able to bundle installRails 和 Ruby 版本总是冲突,永远无法捆绑安装
【发布时间】:2022-01-25 20:21:55
【问题描述】:

我 git 克隆了我自己的 repo,当我想启动时(rails s),即使我安装了 Rails,也会有安装 Rails 的请求(sudo apt install ruby​​-railties)。如果我开始安装(gem install rails),会出现Ruby版本太旧的提示:

ERROR: Error installing rails:
        There are no versions of activesupport (= 7.0.0) compatible with your Ruby & RubyGems. Maybe try installing an older version of the gem you're looking for?
        activesupport requires Ruby version >= 2.7.0. The current ruby ​​version is 2.6.6.146.

如果我切换到请求的版本(rvm 使用 2.7),当我运行 rails s 时会出现以下消息:

Could not find proper version of railties (6.1.4.1) in any of the sources
Run `bundle install` to install missing gems.

当我进行捆绑安装时,需要切换 Ruby 版本:

Your Ruby version is 2.7.2, but your Gemfile specified 2.6.6

这相当于回到起点。这个愚蠢的循环使我无法完成捆绑安装,因此无法完成 rails s。

【问题讨论】:

    标签: ruby-on-rails ruby postgresql


    【解决方案1】:

    关于 pg 错误,您需要将 'pg' gem 更改为较低版本。让我们看看您的 gemfile 中有什么。

    【讨论】:

    • gem 'pg', '~> 1.2.3'
    • 你运行的是什么版本的rails?
    • 我在查看Rails版本时收到了sudo apt install ruby-railties的消息,但是执行后会出现:E: Unable to locate package ruby-railties
    • 运行“gem install rails”
    • 然后当我重新安装包时,出现“您的 Ruby 版本为 2.7.2,但您的 Gemfile 指定为 2.6.6”的消息,
    【解决方案2】:

    在项目文件夹中设置环境。

    cd yourproject

    然后安装 Ruby、Rails 和 Bundler。


    通过 Ruby 版本管理器 (RVM) 安装 Ruby v2.7.0 https://rvm.io/

    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    
    \curl -sSL https://get.rvm.io | bash -s stable
    
    source /etc/profile.d/rvm.sh
    
    rvm install ruby 2.7.0
    rvm use 2.7.0
    rvm list
    

    安装 Rails,通过 RubyGems https://rubygems.org

    (不要使用apt install ruby-railties

    gem install rails
    rails --version
    

    (重新)安装 Bundler

    gem install bundler
    
    bundle install
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-06
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      相关资源
      最近更新 更多