環境
- CentOS 7.2
- Rails 5.1.6.1
railsでpostgreSQLを使おうとした時に以下のようなエラーが出たので色々試してみる。
$ rails new myproject -d postgresql
exist
identical README.md
identical Rakefile
identical config.ru
identical .gitignore
identical Gemfile
run git init from "."
Reinitialized existing Git repository in /home/vagrant/dotinstall/heroku/mymemo/.git/
exist app
identical app/assets/config/manifest.js
identical app/assets/javascripts/application.js
identical app/assets/javascripts/cable.js
identical app/assets/stylesheets/application.css
identical app/channels/application_cable/channel.rb
identical app/channels/application_cable/connection.rb
identical app/controllers/application_controller.rb
identical app/helpers/application_helper.rb
identical app/jobs/application_job.rb
identical app/mailers/application_mailer.rb
identical app/models/application_record.rb
identical app/views/layouts/application.html.erb
identical app/views/layouts/mailer.html.erb
identical app/views/layouts/mailer.text.erb
identical app/assets/images/.keep
exist app/assets/javascripts/channels
identical app/assets/javascripts/channels/.keep
identical app/controllers/concerns/.keep
identical app/models/concerns/.keep
exist bin
identical bin/bundle
identical bin/rails
identical bin/rake
identical bin/setup
identical bin/update
identical bin/yarn
exist config
identical config/routes.rb
identical config/application.rb
identical config/environment.rb
conflict config/secrets.yml
Overwrite /home/vagrant/dotinstall/heroku/mymemo/config/secrets.yml? (enter "h" for help) [Ynaqdhm] Y
force config/secrets.yml
identical config/cable.yml
identical config/puma.rb
identical config/spring.rb
exist config/environments
identical config/environments/development.rb
identical config/environments/production.rb
identical config/environments/test.rb
exist config/initializers
identical config/initializers/application_controller_renderer.rb
identical config/initializers/assets.rb
identical config/initializers/backtrace_silencers.rb
identical config/initializers/cookies_serializer.rb
create config/initializers/cors.rb
identical config/initializers/filter_parameter_logging.rb
identical config/initializers/inflections.rb
identical config/initializers/mime_types.rb
create config/initializers/new_framework_defaults_5_1.rb
identical config/initializers/wrap_parameters.rb
exist config/locales
identical config/locales/en.yml
identical config/boot.rb
identical config/database.yml
exist db
identical db/seeds.rb
exist lib
exist lib/tasks
identical lib/tasks/.keep
exist lib/assets
identical lib/assets/.keep
exist log
identical log/.keep
exist public
identical public/404.html
identical public/422.html
identical public/500.html
identical public/apple-touch-icon-precomposed.png
identical public/apple-touch-icon.png
identical public/favicon.ico
identical public/robots.txt
exist test/fixtures
identical test/fixtures/.keep
exist test/fixtures/files
identical test/fixtures/files/.keep
exist test/controllers
identical test/controllers/.keep
exist test/mailers
identical test/mailers/.keep
exist test/models
identical test/models/.keep
exist test/helpers
identical test/helpers/.keep
exist test/integration
identical test/integration/.keep
identical test/test_helper.rb
exist test/system
identical test/system/.keep
identical test/application_system_test_case.rb
exist tmp
identical tmp/.keep
exist tmp/cache
exist tmp/cache/assets
exist vendor
identical vendor/.keep
identical package.json
remove config/initializers/cors.rb
remove config/initializers/new_framework_defaults_5_1.rb
run bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.....
Using rake 12.3.2
Using concurrent-ruby 1.1.4
Using i18n 1.5.3
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.1.6.1
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.1
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.0.4
Using actionview 5.1.6.1
Using rack 2.0.6
Using rack-test 1.1.0
Using actionpack 5.1.6.1
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.6.5
Using actioncable 5.1.6.1
Using globalid 0.4.2
Using activejob 5.1.6.1
Using mini_mime 1.0.1
Using mail 2.7.1
Using actionmailer 5.1.6.1
Using activemodel 5.1.6.1
Using arel 8.0.0
Using activerecord 5.1.6.1
Using public_suffix 3.0.3
Using addressable 2.6.0
Using bindex 0.5.0
Using bundler 1.16.1
Using byebug 10.0.2
Using xpath 3.2.0
Using capybara 2.18.0
Using ffi 1.10.0
Using childprocess 0.9.0
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.2
Using thor 0.20.3
Using railties 5.1.6.1
Using coffee-rails 4.2.2
Using multi_json 1.13.1
Using jbuilder 2.8.0
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.0
Using ruby_dep 1.5.0
Using listen 3.1.5
Fetching pg 1.1.4
Installing pg 1.1.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/pg-1.1.4/ext
/home/vagrant/.rbenv/versions/2.5.0/bin/ruby -r
./siteconf20190128-12909-bowbr2.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/vagrant/.rbenv/versions/2.5.0/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
/home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.1.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/pg-1.1.4 for
inspection.
Results logged to
/home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.1.4/gem_make.out
An error occurred while installing pg (1.1.4), and Bundler cannot
continue.
Make sure that `gem install pg -v '1.1.4'` succeeds before bundling.
In Gemfile:
pg
run bundle exec spring binstub --all
Could not find gem 'rails (>= 5.1.6.1, ~> 5.1.6)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
解決策
$ sudo yum install postgresql-devel
どうやらpostgresql本体は入っていたが、develが入っていなかったようです。