bundle install --without production 可以修复错误,但为什么呢? (确保 `gem install pg -v '0.18.1'` 在捆绑前成功)
bundle install --without production remediates error, but why? ( Make sure that `gem install pg -v '0.18.1'` succeeds before bundling)
在 Rails 框架上创建 Ruby 之后(推送到 master 和 Heroku 之前)和 运行:bundle install,我有时遇到以下错误:
An error occurred while installing pg (0.18.2), and Bundler cannot continue
Make sure that gem install pg -v '0.18.2'
succeeds before bundling.
以下命令完全解决了这个问题:bundle install --without production。
为什么上述命令可以解决问题?据我了解,该命令绕过生产环境 gem 进行部署;那么,我的理解是否正确,为什么一定是这样呢?谢谢!
这是我的 gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
gem 'bootstrap-sass'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
回答此问题 "why" 部分的最佳资源似乎由 Michael Hartl's Ruby on Rails Tutorial 解释:
"Heroku uses the PostgreSQL database...which means that we need to add the pg gem in the production environment to allow Rails to talk to Postgres...Generally speaking, it's a good idea for the development and production environments to match each other as closely as possible, which includes using the same database, however we'll use SQLite locally and PostgreSQL in production."
所以,基本上看来问题是维护两种不同环境(生产和开发(本地))之间的约定,更具体地说,是数据库类型(Postgres vs SQLite), 这就是为什么需要 bundle install --without production
:
"To prepare the system for deployment to production, we run bundle install with a special flag to prevent the local installation of any production gems (which in this case consist of ph and rails_12factor)...Because the only gems added are restricted to a production environment, right now this command doesn't actually install any additional local gems, but it's needed to update Gemfile.lock with the pg and rails_12factor gems."
如果 Heroku 部署的补救措施 bundle install --without production
是 bundle install
的可接受替代方案,那就太糟糕了,不可能是真的;如果是这样,我是否可以修改其他设置或文件以达到与常规 bundle install
相同的结果?谢谢!
在 Rails 框架上创建 Ruby 之后(推送到 master 和 Heroku 之前)和 运行:bundle install,我有时遇到以下错误:
An error occurred while installing pg (0.18.2), and Bundler cannot continue Make sure that
gem install pg -v '0.18.2'
succeeds before bundling.
以下命令完全解决了这个问题:bundle install --without production。
为什么上述命令可以解决问题?据我了解,该命令绕过生产环境 gem 进行部署;那么,我的理解是否正确,为什么一定是这样呢?谢谢!
这是我的 gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
gem 'bootstrap-sass'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
回答此问题 "why" 部分的最佳资源似乎由 Michael Hartl's Ruby on Rails Tutorial 解释:
"Heroku uses the PostgreSQL database...which means that we need to add the pg gem in the production environment to allow Rails to talk to Postgres...Generally speaking, it's a good idea for the development and production environments to match each other as closely as possible, which includes using the same database, however we'll use SQLite locally and PostgreSQL in production."
所以,基本上看来问题是维护两种不同环境(生产和开发(本地))之间的约定,更具体地说,是数据库类型(Postgres vs SQLite), 这就是为什么需要 bundle install --without production
:
"To prepare the system for deployment to production, we run bundle install with a special flag to prevent the local installation of any production gems (which in this case consist of ph and rails_12factor)...Because the only gems added are restricted to a production environment, right now this command doesn't actually install any additional local gems, but it's needed to update Gemfile.lock with the pg and rails_12factor gems."
如果 Heroku 部署的补救措施 bundle install --without production
是 bundle install
的可接受替代方案,那就太糟糕了,不可能是真的;如果是这样,我是否可以修改其他设置或文件以达到与常规 bundle install
相同的结果?谢谢!