LINE bot作成

gem 'dotenv-rails'
gem 'line-bot-api'

 

上記記述後、Gemファイル

#gem 'pg', '>= 0.18', '< 2.0' コメントアウトで下記エラーを回避。

 

▶bundle install

---------------------------------------------------

gem install pg -v '1.1.4' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

current directory: /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4/ext
/usr/local/rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20190828-28172-1sqgmrg.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/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=/usr/local/rvm/rubies/ruby-2.4.1/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:

/usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/pg-1.1.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/pg-1.1.4/gem_make.out

----------------------------------------------------

 

rails generate model User line_id:string

 

invoke active_record
/usr/local/rvm/gems/ruby-2.4.1/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:406:in `block (2 levels) in replace_gem': Error loading the 'postgresql' Active Record adapter. Missing a gem it depends on? pg is not part of the bundle. Add it to your Gemfile. (LoadError)
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:4:in `<main>'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/connection_specification.rb:191:in `spec'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:956:in `establish_connection'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:60:in `establish_connection'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/railtie.rb:136:in `block (2 levels) in <class:Railtie>'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in `each'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/active_record/base.rb:27:in `<main>'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/generators/named_base.rb:201:in `pluralize_table_names?'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/generators/named_base.rb:92:in `table_name'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-5.2.3/lib/rails/generators/active_record/model/model_generator.rb:22:in `create_migration_file'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:115:in `invoke'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/group.rb:277:in `block in _invoke_for_class_method'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/shell.rb:68:in `with_padding'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/group.rb:266:in `_invoke_for_class_method'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/group.rb:134:in `_invoke_from_option_orm'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/generators.rb:276:in `invoke'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/commands/generate/generate_command.rb:26:in `perform'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/local/rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
from bin/rails:4:in `<main>'

 

 

ec2-user:~/environment/line-bot (master) $ sudo service postgresql start
postgresql: unrecognized service
ec2-user:~/environment/line-bot (master) $ sudo service postgresql start
postgresql: unrecognized service
ec2-user:~/environment/line-bot (master) $ sudo yum install postgresql postgresql-server postgresql-contrib postgresql-docs
Loaded plugins: priorities, update-motd, upgrade-helper
1065 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package postgresql92.x86_64 0:9.2.24-2.66.amzn1 will be installed
--> Processing Dependency: postgresql92-libs(x86-64) = 9.2.24-2.66.amzn1 for package: postgresql92-9.2.24-2.66.amzn1.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql92-9.2.24-2.66.amzn1.x86_64
---> Package postgresql92-contrib.x86_64 0:9.2.24-2.66.amzn1 will be installed
--> Processing Dependency: libossp-uuid.so.16()(64bit) for package: postgresql92-contrib-9.2.24-2.66.amzn1.x86_64
---> Package postgresql92-docs.x86_64 0:9.2.24-2.66.amzn1 will be installed
---> Package postgresql92-server-compat.x86_64 0:9.2.24-2.66.amzn1 will be installed
--> Processing Dependency: postgresql92-server(x86-64) = 9.2.24-2.66.amzn1 for package: postgresql92-server-compat-9.2.24-2.66.amzn1.x86_64
--> Running transaction check
---> Package postgresql92-libs.x86_64 0:9.2.24-2.66.amzn1 will be installed
---> Package postgresql92-server.x86_64 0:9.2.24-2.66.amzn1 will be installed
---> Package uuid.x86_64 0:1.6.2-27.22.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================
Installing:
postgresql92 x86_64 9.2.24-2.66.amzn1 amzn-updates 4.1 M
postgresql92-contrib x86_64 9.2.24-2.66.amzn1 amzn-updates 586 k
postgresql92-docs x86_64 9.2.24-2.66.amzn1 amzn-updates 53 k
postgresql92-server-compat x86_64 9.2.24-2.66.amzn1 amzn-updates 39 k
Installing for dependencies:
postgresql92-libs x86_64 9.2.24-2.66.amzn1 amzn-updates 261 k
postgresql92-server x86_64 9.2.24-2.66.amzn1 amzn-updates 6.0 M
uuid x86_64 1.6.2-27.22.amzn1 amzn-main 58 k

Transaction Summary
==============================================================================================================================================
Install 4 Packages (+3 Dependent packages)

Total download size: 11 M
Installed size: 34 M
Is this ok [y/d/N]: y
Downloading packages:
(1/7): postgresql92-contrib-9.2.24-2.66.amzn1.x86_64.rpm | 586 kB 00:00:00
(2/7): postgresql92-9.2.24-2.66.amzn1.x86_64.rpm | 4.1 MB 00:00:00
(3/7): postgresql92-docs-9.2.24-2.66.amzn1.x86_64.rpm | 53 kB 00:00:00
(4/7): postgresql92-libs-9.2.24-2.66.amzn1.x86_64.rpm | 261 kB 00:00:00
(5/7): postgresql92-server-compat-9.2.24-2.66.amzn1.x86_64.rpm | 39 kB 00:00:00
(6/7): uuid-1.6.2-27.22.amzn1.x86_64.rpm | 58 kB 00:00:00
(7/7): postgresql92-server-9.2.24-2.66.amzn1.x86_64.rpm | 6.0 MB 00:00:00
----------------------------------------------------------------------------------------------------------------------------------------------
Total 17 MB/s | 11 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql92-libs-9.2.24-2.66.amzn1.x86_64 1/7
Installing : postgresql92-9.2.24-2.66.amzn1.x86_64 2/7
Installing : postgresql92-server-9.2.24-2.66.amzn1.x86_64 3/7
Installing : uuid-1.6.2-27.22.amzn1.x86_64 4/7
Installing : postgresql92-contrib-9.2.24-2.66.amzn1.x86_64 5/7
Installing : postgresql92-server-compat-9.2.24-2.66.amzn1.x86_64 6/7
Installing : postgresql92-docs-9.2.24-2.66.amzn1.x86_64 7/7
Verifying : postgresql92-libs-9.2.24-2.66.amzn1.x86_64 1/7
Verifying : uuid-1.6.2-27.22.amzn1.x86_64 2/7
Verifying : postgresql92-contrib-9.2.24-2.66.amzn1.x86_64 3/7
Verifying : postgresql92-server-9.2.24-2.66.amzn1.x86_64 4/7
Verifying : postgresql92-docs-9.2.24-2.66.amzn1.x86_64 5/7
Verifying : postgresql92-server-compat-9.2.24-2.66.amzn1.x86_64 6/7
Verifying : postgresql92-9.2.24-2.66.amzn1.x86_64 7/7

Installed:
postgresql92.x86_64 0:9.2.24-2.66.amzn1 postgresql92-contrib.x86_64 0:9.2.24-2.66.amzn1
postgresql92-docs.x86_64 0:9.2.24-2.66.amzn1 postgresql92-server-compat.x86_64 0:9.2.24-2.66.amzn1

Dependency Installed:
postgresql92-libs.x86_64 0:9.2.24-2.66.amzn1 postgresql92-server.x86_64 0:9.2.24-2.66.amzn1 uuid.x86_64 0:1.6.2-27.22.amzn1

Complete!
ec2-user:~/environment/line-bot (master) $ sudo service postgresql initdb && sudo service postgresql start
Initializing database: [ OK ]
Starting postgresql service: [ OK ]
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $ 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.3
Using concurrent-ruby 1.1.5
Using i18n 1.6.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.3
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.4
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.2.0
Using actionview 5.2.3
Using rack 2.0.7
Using rack-test 1.1.0
Using actionpack 5.2.3
Using nio4r 2.5.0
Using websocket-extensions 0.1.4
Using websocket-driver 0.7.1
Using actioncable 5.2.3
Using globalid 0.4.2
Using activejob 5.2.3
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.3
Using activemodel 5.2.3
Using arel 9.0.0
Using activerecord 5.2.3
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.3
Using public_suffix 3.1.1
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.3.1
Using bootsnap 1.4.4
Using bundler 2.0.2
Using byebug 11.0.1
Using regexp_parser 1.6.0
Using xpath 3.2.0
Using capybara 3.28.0
Using childprocess 1.0.1
Using chromedriver-helper 2.1.1
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.2.3
Using coffee-rails 4.2.2
Using dotenv 2.7.5
Using dotenv-rails 2.7.5
Using ffi 1.11.1
Using jbuilder 2.9.1
Using line-bot-api 1.12.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: /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4/ext
/usr/local/rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20190828-4292-1v9ki9h.rb extconf.rb --with-pg-config=/usr/pgsql-1.1.4/bin/pg_config
Using config values from /usr/pgsql-1.1.4/bin/pg_config
sh: /usr/pgsql-1.1.4/bin/pg_config: No such file or directory
sh: /usr/pgsql-1.1.4/bin/pg_config: No such file or directory
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=/usr/local/rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--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

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/pg-1.1.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/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' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
pg
ec2-user:~/environment/line-bot (master) $ sudo yum install postgresql-devel
Loaded plugins: priorities, update-motd, upgrade-helper
1065 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package postgresql92-devel.x86_64 0:9.2.24-2.66.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================
Installing:
postgresql92-devel x86_64 9.2.24-2.66.amzn1 amzn-updates 1.1 M

Transaction Summary
==============================================================================================================================================
Install 1 Package

Total download size: 1.1 M
Installed size: 3.9 M
Is this ok [y/d/N]: Y
Downloading packages:
postgresql92-devel-9.2.24-2.66.amzn1.x86_64.rpm | 1.1 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql92-devel-9.2.24-2.66.amzn1.x86_64 1/1
Verifying : postgresql92-devel-9.2.24-2.66.amzn1.x86_64 1/1

Installed:
postgresql92-devel.x86_64 0:9.2.24-2.66.amzn1

Complete!
ec2-user:~/environment/line-bot (master) $ 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.3
Using concurrent-ruby 1.1.5
Using i18n 1.6.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.3
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.4
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.2.0
Using actionview 5.2.3
Using rack 2.0.7
Using rack-test 1.1.0
Using actionpack 5.2.3
Using nio4r 2.5.0
Using websocket-extensions 0.1.4
Using websocket-driver 0.7.1
Using actioncable 5.2.3
Using globalid 0.4.2
Using activejob 5.2.3
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.3
Using activemodel 5.2.3
Using arel 9.0.0
Using activerecord 5.2.3
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.3
Using public_suffix 3.1.1
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.3.1
Using bootsnap 1.4.4
Using bundler 2.0.2
Using byebug 11.0.1
Using regexp_parser 1.6.0
Using xpath 3.2.0
Using capybara 3.28.0
Using childprocess 1.0.1
Using chromedriver-helper 2.1.1
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.2.3
Using coffee-rails 4.2.2
Using dotenv 2.7.5
Using dotenv-rails 2.7.5
Using ffi 1.11.1
Using jbuilder 2.9.1
Using line-bot-api 1.12.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: /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4/ext
/usr/local/rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20190828-4426-nggckp.rb extconf.rb --with-pg-config=/usr/pgsql-1.1.4/bin/pg_config
Using config values from /usr/pgsql-1.1.4/bin/pg_config
sh: /usr/pgsql-1.1.4/bin/pg_config: No such file or directory
sh: /usr/pgsql-1.1.4/bin/pg_config: No such file or directory
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=/usr/local/rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--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

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/pg-1.1.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/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' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
pg
ec2-user:~/environment/line-bot (master) $ sudo yum install postgresql-devel
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00:00
amzn-updates | 2.5 kB 00:00:00
1065 packages excluded due to repository priority protections
Package postgresql92-devel-9.2.24-2.66.amzn1.x86_64 already installed and latest version
Nothing to do
ec2-user:~/environment/line-bot (master) $
ec2-user:~/environment/line-bot (master) $ 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.3
Using concurrent-ruby 1.1.5
Using i18n 1.6.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.3
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.4
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.2.0
Using actionview 5.2.3
Using rack 2.0.7
Using rack-test 1.1.0
Using actionpack 5.2.3
Using nio4r 2.5.0
Using websocket-extensions 0.1.4
Using websocket-driver 0.7.1
Using actioncable 5.2.3
Using globalid 0.4.2
Using activejob 5.2.3
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.3
Using activemodel 5.2.3
Using arel 9.0.0
Using activerecord 5.2.3
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.3
Using public_suffix 3.1.1
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.3.1
Using bootsnap 1.4.4
Using bundler 2.0.2
Using byebug 11.0.1
Using regexp_parser 1.6.0
Using xpath 3.2.0
Using capybara 3.28.0
Using childprocess 1.0.1
Using chromedriver-helper 2.1.1
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.2.3
Using coffee-rails 4.2.2
Using dotenv 2.7.5
Using dotenv-rails 2.7.5
Using ffi 1.11.1
Using jbuilder 2.9.1
Using line-bot-api 1.12.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: /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4/ext
/usr/local/rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20190828-4545-1x46p01.rb extconf.rb --with-pg-config=/usr/pgsql-1.1.4/bin/pg_config
Using config values from /usr/pgsql-1.1.4/bin/pg_config
sh: /usr/pgsql-1.1.4/bin/pg_config: No such file or directory
sh: /usr/pgsql-1.1.4/bin/pg_config: No such file or directory
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=/usr/local/rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--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

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/pg-1.1.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.4.1/gems/pg-1.1.4 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.4.1/extensions/x86_64-linux/2.4.0/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' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
pg
ec2-user:~/environment/line-bot (master) $ gem install pg -v '1.1.4' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
Successfully installed pg-1.1.4
1 gem installed
ec2-user:~/environment/line-bot (master) $ 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.3
Using concurrent-ruby 1.1.5
Using i18n 1.6.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.3
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.4
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.2.0
Using actionview 5.2.3
Using rack 2.0.7
Using rack-test 1.1.0
Using actionpack 5.2.3
Using nio4r 2.5.0
Using websocket-extensions 0.1.4
Using websocket-driver 0.7.1
Using actioncable 5.2.3
Using globalid 0.4.2
Using activejob 5.2.3
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.3
Using activemodel 5.2.3
Using arel 9.0.0
Using activerecord 5.2.3
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.3
Using public_suffix 3.1.1
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.3.1
Using bootsnap 1.4.4
Using bundler 2.0.2
Using byebug 11.0.1
Using regexp_parser 1.6.0
Using xpath 3.2.0
Using capybara 3.28.0
Using childprocess 1.0.1
Using chromedriver-helper 2.1.1
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.2.3
Using coffee-rails 4.2.2
Using dotenv 2.7.5
Using dotenv-rails 2.7.5
Using ffi 1.11.1
Using jbuilder 2.9.1
Using line-bot-api 1.12.0
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.0
Using ruby_dep 1.5.0
Using listen 3.1.5
Using pg 1.1.4
Using puma 3.12.1
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.3
Using rubyzip 1.2.3
Using sass-listen 4.0.0
Using sass 3.7.4
Using tilt 2.0.9
Using sass-rails 5.1.0
Using selenium-webdriver 3.142.3
Using spring 2.1.0
Using spring-watcher-listen 2.0.1
Using turbolinks-source 5.2.0
Using turbolinks 5.2.0
Using uglifier 4.1.20
Using web-console 3.7.0
Bundle complete! 20 Gemfile dependencies, 81 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
ec2-user:~/environment/line-bot (master) $

 

※参考記事

https://qiita.com/dynamonda/items/bfb907b2251fc7c2ca38

 

ようやくinstallが成功。

どうやらcloud9でpgを指定してinstallするのは大変なようだ。

macだと挙動が異なりそう。

 

rails db:create エラーについて

https://teratail.com/questions/203776

 https://stackoverflow.com/questions/48210717/rails-postgresql-on-aws-cloud-9-role-ec2-user-does-not-exist