質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Q&A

0回答

334閲覧

RailsでGemのpostgresqlがbundle installできない

tanaka_m

総合スコア1

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

0グッド

0クリップ

投稿2022/09/27 16:25

前提:

  • MacBook M1
  • Railsのver:Rails 6.0.6
  • homebrewのパス:/opt/homebrew
  • postgresqlのパス:/opt/homebrew/lib/postgresql@14
  • postgresqlの設定ファイル:opt/homebrew/bin/pg_config

質問の内容:


Ruby on Railsでアプリケーションを作成していて、
開発環境にsplite3を使用し、本番環境でpostgresqlを使用しようと思っています。
開発環境ではGemのインストールが上手くいっており、homebrewは
"/usr/local/Homebrew"にある状態で実施していました。

postgresqlを本番環境で使用するために、bundle installをするとエラーが起きたので
/opt/homebrewにインストールする流れになりました。
postgresqlはインストール出来たのですが、Gemfileが上手くいきません。

以下の詳細になりますので、ご確認お願い致します。

ソースコードとエラー内容:

Gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.6.5' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' 7gem 'rails', '~> 6.0.5', '>= 6.0.5.1' 8# Use sqlite3 as the database for Active Record 9gem 'sqlite3', '~> 1.4' 10 11gem 'pg' 12# Use Puma as the app server 13gem 'puma', '~> 4.1' 14# Use SCSS for stylesheets 15gem 'sass-rails', '>= 6' 16# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 17gem 'webpacker', '~> 4.0' 18# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 19gem 'turbolinks', '~> 5' 20# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 21gem 'jbuilder', '~> 2.7' 22# Use Redis adapter to run Action Cable in production 23# gem 'redis', '~> 4.0' 24# Use Active Model has_secure_password 25# gem 'bcrypt', '~> 3.1.7' 26gem 'annotate' 27gem 'better_errors' 28gem 'binding_of_caller' 29gem 'devise' 30gem 'faker' 31gem 'hamlit' 32gem 'aws-sdk-s3', require: false 33 34# Use Active Storage variant 35# gem 'image_processing', '~> 1.2' 36 37# Reduces boot times through caching; required in config/boot.rb 38gem 'bootsnap', '>= 1.4.2', require: false 39 40group :development, :test do 41 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 42 gem 'byebug', platforms: %i[mri mingw x64_mingw] 43 gem 'pry-byebug' 44 gem 'rubocop-rails' 45 gem 'dotenv-rails' 46end 47 48group :development do 49 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 50 gem 'listen', '~> 3.2' 51 gem 'web-console', '>= 3.3.0' 52 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 53 gem 'erb2haml' 54 gem 'haml-rails' 55 gem 'spring' 56 gem 'spring-watcher-listen', '~> 2.0.0' 57end 58 59group :test do 60 # Adds support for Capybara system testing and selenium driver 61 gem 'capybara', '>= 2.15' 62 gem 'selenium-webdriver' 63 # Easy installation and use of web drivers to run system tests with browsers 64 gem 'webdrivers' 65end 66 67# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 68gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 69

bundel installした時のエラー文:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/pg-1.4.3/ext /Users/username/.rbenv/versions/2.6.5/bin/ruby -I /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r ./siteconf20220928-22154-1q3ej6c.rb extconf.rb --with-pg-config\=/opt/homebrew/bin/pg_config Calling libpq with GVL unlocked Using config values from /opt/homebrew/bin/pg_config checking for whether -Wl,-rpath,/opt/homebrew/lib/postgresql@14 is accepted as LDFLAGS... yes Using libpq from /opt/homebrew/lib/postgresql@14 checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for pg_config_manual.h... yes checking for PQconnectdb() in -lpq... no checking for PQconnectdb() in -llibpq... no checking for PQconnectdb() in -lms/libpq... no Can't find the PostgreSQL client library (libpq) ***************************************************************************** Unable to find PostgreSQL client library. Please install libpq or postgresql client package like so: brew install libpq or try again with: gem install pg -- --with-pg-config=/path/to/pg_config or set library paths manually with: gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/ *** 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=/Users/username/.rbenv/versions/2.6.5/bin/$(RUBY_BASE_NAME) --with-pg --without-pg --enable-gvl-unlock --disable-gvl-unlock --enable-windows-cross --disable-windows-cross --with-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 --with-pqlib --without-pqlib --with-libpqlib --without-libpqlib --with-ms/libpqlib --without-ms/libpqlib To see why this extension failed to compile, please check the mkmf.log which can be found here: /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-21/2.6.0/pg-1.4.3/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/pg-1.4.3 for inspection. Results logged to /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-21/2.6.0/pg-1.4.3/gem_make.out /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/builder.rb:99:in `run' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/ext_conf_builder.rb:47:in `block in build' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/tempfile.rb:295:in `open' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/ext_conf_builder.rb:29:in `build' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/builder.rb:185:in `block in build_extension' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/builder.rb:181:in `build_extension' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/builder.rb:229:in `block in build_extensions' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/builder.rb:226:in `each' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/ext/builder.rb:226:in `build_extensions' /Users/username/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/installer.rb:830:in `build_extensions' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/rubygems_gem_installer.rb:28:in `install' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/source/rubygems.rb:207:in `install' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/installer/gem_installer.rb:54:in `install' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/installer/parallel_installer.rb:186:in `do_install' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/worker.rb:62:in `apply_func' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/worker.rb:57:in `block in process_queue' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/worker.rb:54:in `loop' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/worker.rb:54:in `process_queue' /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.22/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads' An error occurred while installing pg (1.4.3), and Bundler cannot continue. In Gemfile: pg username@usernamenoMacBook-Air blog-app %

bundle installした時のエラーログ:

/* begin */ 1: #include "ruby.h" 2: 3: #include <libpq-fe.h> 4: 5: /*top*/ 6: extern int t(void); 7: int main(int argc, char **argv) 8: { 9: if (argc > 1000000) { 10: int (* volatile tp)(void)=(int (*)(void))&t; 11: printf("%d", (*tp)()); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; } /* end */

libpq-fe.hに関する記事があったので、
brew install libpqは実施してみましたがこの方法でも無理でした。
なかなか解決策が見当たらないので、お忙しい中ですがご教授お願い致します。

以上、宜しくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shinoharat

2022/09/28 00:30

エラーメッセージに書いてある > or try again with: > gem install pg -- --with-pg-config=/path/to/pg_config > > or set library paths manually with: > gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/ は試しましたか?
shinoharat

2022/09/28 00:31

質問文に載っている「bundle installした時のエラーログ」というのは、 /Users/username/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-21/2.6.0/pg-1.4.3/mkmf.log のことでしょうか?
tanaka_m

2022/09/28 03:47

お忙しい中コメントありがとうございます。 ①gem install pg -- --with-pg-config=/opt/homebrew/bin/pg_config で試してみたところ、以下のエラー文が表示されました。 Wl,-rpath,/opt/homebrew/lib/postgresql@14 が LDFLAGS として受け入れられるか確認中... yes libpqを/opt/homebrew/lib/postgresql@14から使用。 libpq-fe.hをチェックする...はい libpq/libpq-fs.hをチェックしている...はい pg_config_manual.hのチェック。 lpqにおけるPQconnectdb()のチェック...no PQconnectdb()を-llibpqでチェック中...no lms/libpqにおけるPQconnectdb()のチェック... - no PostgreSQLクライアントライブラリ(libpq)が見つかりません。 ②gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/を実行しましたが、libpq-fe.hとibpq.soがなさそうです。whichコマンドで探しましたが見当たりませんでした。こちらは作成した方がいいでしょうか? ③bundle installした時のエラーログはmkmf.logで間違いありません。 ご教授お願い致します。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問