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

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

新規登録して質問してみよう
ただいま回答率
85.48%
PostgreSQL

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

Ruby on Rails

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

Q&A

0回答

3499閲覧

pgはインストールできたが、bundle installするとエラーが起こります。

yata_

総合スコア5

PostgreSQL

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

Ruby on Rails

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

0グッド

0クリップ

投稿2020/02/02 07:36

編集2020/02/03 23:57

##pgがインストールはインストールできたが、bundle installするとエラーが起こります。

現在、以下のurlの動画を参考にrailsのアプリを制作しようとしているものです。
参考にしようとしている動画
この動画を参考にしようと進めていたところ、冒頭の3分程のところで出てくるGemfileにpgを記述してsqliteから変更するという手順を行なっていた時に起こりました。

gem 'pg', '~> 0.18.4'と記述するところまではよかったのですが、実際にbundle installをしてみると以下の様なエラーが出ます。

##bundle installの結果

Fetching pg 0.18.4

Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /Users/yatayuki/instagram-clone/vendor/bundle/ruby/2.5.0/gems/pg-0.18.4/ext

/Users/yatayuki/.rbenv/versions/2.5.0/bin/ruby -r ./siteconf20200202-93926-ptzbge.rb extconf.rb
--with-pg-config=/usr/pgsql-9.3/bin/pg_config
Using config values from /usr/pgsql-9.3/bin/pg_config
sh: /usr/pgsql-9.3/bin/pg_config: No such file or directory
Yesと判定されたところは文字数削減のため省略。

checking for rb_enc_alias()... no

checking for rb_w32_wrap_io_handle()... no
creating Makefile

urrent directory: /Users/yatayuki/instagram-clone/vendor/bundle/ruby/2.5.0/gems/pg-0.18.4/ext

make "DESTDIR=" clean

current directory: /Users/yatayuki/instagram-clone/vendor/bundle/ruby/2.5.0/gems/pg-0.18.4/ext

make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
compiling pg_binary_decoder.c
compiling pg_binary_encoder.c
compiling pg_coder.c
compiling pg_connection.c
pg_connection.c:2394:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
gettimeofday(&currtime, NULL);

^

pg_connection.c:2411:4: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]

gettimeofday(&currtime, NULL); ^

2 warnings generated.
compiling pg_copy_coder.c
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
compiling pg_type_map.c
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling util.c
linking shared-object pg_ext.bundle
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/yatayuki/instagram-clone/vendor/bundle/ruby/2.5.0/gems/pg-0.18.4 for inspection.

Results logged to /Users/yatayuki/instagram-clone/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/pg-0.18.4/gem_make.out

An error occurred while installing pg (0.18.4), and Bundler cannot continue.

Make sure that gem install pg -v '0.18.4' --source 'https://rubygems.org/' succeeds before bundling.

In Gemfile:

pg

様々なことをやってみたのですが、一日使っても解決には至らなかったので教えていただけると嬉しいです。

##やったこと
・bundle install⇨上記エラー

・bundle update⇨上記エラー

・gem install pg -v '0.18.4'⇨インストールはできるが、bundleinstallなどを行うとまた同じエラー

・brew install postgresql⇨成功現在12.0が入ってます。しかしそれ以外は変わらず...

・gem install pg --with-pg-config=/usr/pgsql-9.3/bin/p
g_config⇨ネット上でこれで解決した方がいらっしゃったので、自分のバージョンの12.0に書き換えて動作させた⇨下記のエラーが出た。

ERROR: While executing gem ... (OptionParser::InvalidOption)

invalid option: --with-pg-config=/usr/pgsql-12.0/bin/pg_config

・Gemfile.lock で指定されているgemのバージョンがyank(削除)されてしまっている可能性があるという記述をネット上で見つけたのでバージョンを0.18.2や、0.18.1,1.1.4などにGemfileを書き換えて同様にbundle installを行う⇨全く同じエラーがでる。

・bundlerをuninstallからのinstall⇨特に意味はなかった模様。

・mkmf.logを見れば何か分かるらしい⇨見てもよくわかりませんでした。以下に貼り付けておきますので、何かわかればよろしくお願いします。(どこまで貼り付ければ良いのかわからないかったので長めに貼り付けました。)


have_func: checking for rb_w32_wrap_io_handle()... -------------------- no

"clang -o conftest -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/x86_64-darwin18 -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0 -I. -I/usr/local/include -I/Users/yatayuki/.rbenv/versions/2.5.0/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -Wno-error=shorten-64-to-32 -fno-common -pipe conftest.c -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -L/usr/local/lib -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -fstack-protector -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpq -lruby.2.5.0 -lpq -lpthread -ldl -lobjc "

conftest.c:13:57: error: use of undeclared identifier 'rb_w32_wrap_io_handle'
int t(void) { void ((volatile p)()); p = (void (()()))rb_w32_wrap_io_handle; return !p; }
^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /top/
4: extern int t(void);
5: int main(int argc, char *argv)
6: {
7: if (argc > 1000000) {
8: printf("%p", &t);
9: }
10:
11: return 0;
12: }
13: int t(void) { void ((volatile p)()); p = (void (()()))rb_w32_wrap_io_handle; return !p; }
/
end */

"clang -o conftest -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/x86_64-darwin18 -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0 -I. -I/usr/local/include -I/Users/yatayuki/.rbenv/versions/2.5.0/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -Wno-error=shorten-64-to-32 -fno-common -pipe conftest.c -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -L/usr/local/lib -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -fstack-protector -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpq -lruby.2.5.0 -lpq -lpthread -ldl -lobjc "

Undefined symbols for architecture x86_64:
"_rb_w32_wrap_io_handle", referenced from:
_t in conftest-1913e3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
文字数削減のため、省略。
13: extern void rb_w32_wrap_io_handle();
14: int t(void) { rb_w32_wrap_io_handle(); return 0; }
/* end */


have_func: checking for rb_enc_alias()... -------------------- no

"clang -o conftest -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/x86_64-darwin18 -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0 -I. -I/usr/local/include -I/Users/yatayuki/.rbenv/versions/2.5.0/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -Wno-error=shorten-64-to-32 -fno-common -pipe conftest.c -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -L/usr/local/lib -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -fstack-protector -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpq -lruby.2.5.0 -lpq -lpthread -ldl -lobjc "

conftest.c:13:57: error: use of undeclared identifier 'rb_enc_alias'
int t(void) { void ((volatile p)()); p = (void (()()))rb_enc_alias; return !p; }
^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /top/
4: extern int t(void);
5: int main(int argc, char *argv)
6: {
7: if (argc > 1000000) {
8: printf("%p", &t);
9: }
10:
11: return 0;
12: }
13: int t(void) { void ((volatile p)()); p = (void (()()))rb_enc_alias; return !p; }
/
end */

"clang -o conftest -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/x86_64-darwin18 -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/yatayuki/.rbenv/versions/2.5.0/include/ruby-2.5.0 -I. -I/usr/local/include -I/Users/yatayuki/.rbenv/versions/2.5.0/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -Wno-error=shorten-64-to-32 -fno-common -pipe conftest.c -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -L/usr/local/lib -L. -L/Users/yatayuki/.rbenv/versions/2.5.0/lib -fstack-protector -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpq -lruby.2.5.0 -lpq -lpthread -ldl -lobjc "

Undefined symbols for architecture x86_64:
"_rb_enc_alias", referenced from:
_t in conftest-76f101.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /top/
4: extern int t(void);
5: int main(int argc, char *argv)
6: {
7: if (argc > 1000000) {
8: printf("%p", &t);
9: }
10:
11: return 0;
12: }
13: extern void rb_enc_alias();
14: int t(void) { rb_enc_alias(); return 0; }
/
end */


・sudo -u postgres psql⇨これをやれ的な記事を見つけたのでやってみましたが、

sudo: unknown user: postgres

sudo: unable to initialize policy plugin

と出ました

・database.ymlの書き換え⇨sqliteの場所をpgに変更しなければいけないのかと以下の様に変更しましたが特に何も変わりませんでした。(記事に書かれていた所のみを変更したので、下の方にsqliteが何個も残っているのは不明だったからです。もしこれが原因であるなら本当に申し訳ないです。)

default: &default

adapter: postgresql
host: localhost
encoding: utf8
database: psgr_db
username: postgres
password: postgres
pool: 5
timeout: 5000

development:

<<: *default
database: db/development.sqlite3

Warning: The database defined as "test" will be erased and

re-generated from your development database when you run "rake".
Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:

<<: *default
database: db/production.sqlite3

##自分の環境
Macbook2017
ruby 2.5.0
rails 5.2.4
brew
bundler

改めてよろしくお願いします。

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

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

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

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

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

winterboum

2020/02/02 10:06

mkmf.log ですが最後の方に何が悪かったかでているかと思いますので、その辺りと入れ替えてください。
yata_

2020/02/02 12:51

ご指摘ありがとうございます! こちらでいかがでしょうか? よろしくお願いします!
winterboum

2020/02/02 13:33

エラーとか何やらが見つからないとか、こうしたらどうか とかの記載があると思うのですが。
winterboum

2020/02/02 13:34

database.yml を読みに行く以前の話ですので、今は関係ありません。 bundle install が通ったらエラーになるところでした
yata_

2020/02/02 13:49

回答ありがとうございます! ではどの様にしたら良いのでしょうか? もし今ちょうど考えてくださっている途中だったらすいません...
winterboum

2020/02/02 21:51

log の肝心な所が抜けているので。。。 エラーとか何やらが見つからないとか、こうしたらどうか とかの記載があると思うのですが。そこを載せてください
yata_

2020/02/03 13:57

エラーと思われる箇所に差し替えました。 お手数おかけしますが、改めて見て頂けると嬉しいです!
winterboum

2020/02/03 17:03

なんか違うなぁ。。。 まとめみたいなところがあって、そこに助言があるとおもうのですが
yata_

2020/02/03 23:59

変更しましたが、まとめかは不安でこれでもダメな様であれば正直な所どこを見ていいのか分からないです。ファイルごと送らせていただければ早いのかもしれないですが...
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問