简体   繁体   English

在本地运行Rails应用程序上的ruby-不同版本的ruby

[英]Running a ruby on rails app locally - Different versions of ruby

I'm using RVM to manage the different ruby versions I have. 我正在使用RVM管理我拥有的不同的红宝石版本。 One particular application is using an older ruby version (2.3.1), and I've noticed that, once I've changed to that version and run rails server on it, it doesn't work because I'm required to change a whole cascade of Gems or other files, such as nokogiri, to make it run. 一个特定的应用程序使用的是较旧的ruby版本(2.3.1),我注意到,一旦更改为该版本并在其上运行rails server ,它便无法工作,因为我需要更改Gems或其他文件(例如nokogiri)的整个级联,以使其运行。

Generally, from what I've read online, I should just do a simple bundle install to do all of this before running rails server . 通常,从网上阅读的内容来看,在运行rails server之前,我应该做一个简单的bundle install即可完成所有这些工作。 However, it doesn't work as there are more conflicting things in this file, specifically that the versions are hard coded into it. 但是,它不起作用,因为此文件中还有更多冲突的内容,特别是版本已被硬编码到其中。

Based on this, how can I run this app on my local server, if the above steps I've done, just doesn't work? 基于此,如果完成上述步骤,我将无法在本地服务器上运行此应用程序? I'm using Ubuntu, if that helps. 我正在使用Ubuntu,如果有帮助的话。

You're dealing with what is known as dependency issues. 您正在处理所谓的依赖性问题。 The point of Gemfile and Gemfile.lock is to insure that there will be no dependency issues for the application and bundle install will handle that. Gemfile和Gemfile.lock的要点是确保应用程序不存在依赖关系问题,并且bundle install将处理该问题。 However it is common for versions to be set in the Gemfile to lock to a specific major release version which might allow for minor version updates. 但是,通常在Gemfile中设置版本以锁定到特定的主要发行版本,这可能允许进行次要版本更新。 This will look something like: 这看起来像:

#Gemfile
gem 'rails', '4.2.10'
gem 'pg', '0.20.0'

gem 'after_party', '~> 1.10' #minor version updates will run here
gem 'kaminari', '~> 1.1'

ruby '2.3.6'

This ia a brief example. 这是一个简单的例子。 Now when you run bundle install it will make sure everything is compatible with these versions. 现在,当您运行bundle install ,它将确保所有内容都与这些版本兼容。 While running bundle update will only update the versions with ~> before the version and will upgrade only minor semantic versions as they are not supposed to have breaking changes. 在运行bundle update时,仅会在版本之前使用~>更新版本,并且仅会升级次要语义版本,因为它们不应该进行重大更改。

So, why is your app not working? 那么,为什么您的应用程序无法正常工作? Well the Gemfile should have contained a ruby version. 那么Gemfile应该已经包含了ruby版本。 RVM should determine your ruby version in .ruby-version file in base of your rails app and should match the version in Gemfile. RVM应该在Rails应用程序的基础上的.ruby-version文件中确定您的ruby版本,并且应与Gemfile中的版本匹配。 If you need to upgrade your ruby version bundler will help insure all your gems are compatible with that version and with each-other. 如果您需要升级红宝石版本捆绑程序,则将有助于确保所有宝石都与该版本以及彼此兼容。 You'll first need to upgrade your ruby version with RVM, then set it in Gemfile. 您首先需要使用RVM升级红宝石版本,然后在Gemfile中进行设置。

However, there is no guarantee that out of date gems will be compatible. 但是,不能保证过时的宝石将兼容。 That's the whole point of locking them so that you know which versions are stable at a give point in time. 这就是锁定它们的全部目的,这样您就可以知道在给定的时间点哪个版本是稳定的。 Updates / upgrades to gems have to be tested for compatibility which can sometimes be a project. 对gem的更新/升级必须经过兼容性测试,这有时可能是一个项目。

Also see Rails Bundle, gems conflicts, best way to solve it 另请参见Rails Bundle,宝石冲突,解决它的最佳方法

You can create a .rvmrc file or .ruby-version and .ruby-gemset files for isolating gems for your projects. 您可以创建.rvmrc文件或.ruby-version.ruby-gemset文件来隔离项目的gem。 Here's the official documentation on that - https://rvm.io/workflow/projects#project-file-ruby-version 这是官方文档-https://rvm.io/workflow/projects#project-file-ruby-version

you can add echo '2.3.1' > .ruby-version and echo 'newgemset' > .ruby-gemset into working folder then run 您可以将echo '2.3.1' > .ruby-versionecho 'newgemset' > .ruby-gemset到工作文件夹中,然后运行

cd ./
rvm install ruby-2.3.1
gem install bundle
bundle install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM