I have some troubles with installing my Postgres gem. When I run:
gem install pg -v '0.19.0'
it prints:
Successfully installed pg-0.19.0
Parsing documentation for pg-0.19.0
Done installing documentation for pg after 2 seconds
1 gem installed
but when I run:
bundle install
it stops on the pg gem and prints:
An error occurred while installing pg (0.19.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.19.0'` succeeds before bundling.
The whole log is:
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
sh: /usr/pgsql-9.1/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.
gem env
outputs:
/ruby/2.3.0/rubygems/commands/environment_command.rb:154: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.0 (2015-12-25 patchlevel 0) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /.rvm/gems/ruby-2.3.0
- USER INSTALLATION DIRECTORY: /.gem/ruby/2.3.0
- RUBY EXECUTABLE: /.rvm/rubies/ruby-2.3.0/bin/ruby
- EXECUTABLE DIRECTORY: /.rvm/gems/ruby-2.3.0/bin
- SPEC CACHE DIRECTORY: /.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /.rvm/rubies/ruby-2.3.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /.rvm/gems/ruby-2.3.0
- /.rvm/gems/ruby-2.3.0@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /.rvm/gems/ruby-2.3.0/bin
- /.rvm/gems/ruby-2.3.0@global/bin
- /.rvm/rubies/ruby-2.3.0/bin
- /.rvm/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
I'm surprised that gem installed pg without it knowing where your PostgreSQL is installed.
The error messages
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
are the result of the code not being able to locate the headers, which are the result of not finding pg_config
.
The simple fix is to temporarily update your PATH with the directory containing pg_config
. You can do that easily using locate
:
locate pg_config
On my system that returns:
/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
among other things. The pg_config
you want will be in the bin
directory for whichever PostgreSQL you want to use with Ruby.
If you don't have locate
running you could also do:
find / -name pg_config -type f 2>/dev/null
and wait while find
searches your drive. (Having locate
available to you is very helpful, so if it's not running I'd suggest starting it.)
Modify your PATH with the path to pg_config
then run your commands:
PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH gem install pg && bundle install
Modify the path to pg_config for your system of course.
It might also work to remove gem install pg &&
and simply run the bundle install
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.