无法在Rails中安装pg gem(使用PostgreSQL 9.6)

Fail to install pg gem in Rails (using PostgreSQL 9.6)

嗨,有人可以帮帮我! 欣赏它很多!

我有一些问题捆绑安装,因为终端说我无法安装gem pg v 0.20.0
当我尝试安装gem pg时会发生此错误。 我目前正在使用PostgreSQL 9.6我已经尝试了类似问题中的所有解决方案,但没有任何作用,包括尝试重新配置pg。

198-195:Review minhvu$ gem install pg -- --with-pg-config=/usr/pgsql-9.6/bin/pg_config
Building native extensions with: '--with-pg-config=/usr/pgsql-9.6/bin/pg_config'
This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

current directory: /Users/minhvu/.rvm/gems/ruby-2.3.0/gems/pg-0.20.0/ext
/Users/minhvu/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20170313-7016-1if947v.rb extconf.rb --with-pg-config=/usr/pgsql-9.6/bin/pg_config
Using config values from /usr/pgsql-9.6/bin/pg_config
sh: /usr/pgsql-9.6/bin/pg_config: No such file or directory
sh: /usr/pgsql-9.6/bin/pg_config: No such file or directory
* 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
--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/minhvu/.rvm/rubies/ruby-2.3.0/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
/Users/minhvu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/mkmf.rb:456:in try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/minhvu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/mkmf.rb:541:in
try_link0'
from /Users/minhvu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/mkmf.rb:556:in try_link'
from extconf.rb:40:in
'

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

/Users/minhvu/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-16/2.3.0/pg-0.20.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/minhvu/.rvm/gems/ruby-2.3.0/gems/pg-0.20.0 for inspection.
Results logged to /Users/minhvu/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-16/2.3.0/pg-0.20.0/gem_make.out


在我看来,你正在尝试安装pg gem,但首先你应该在你的系统中安装PostgreSQL。 根据您拥有的系统,您应该按照本文中的说明进行操作。 我在下面的帖子中引用上瘾的上瘾用户的答案

Rails错误安装PG

Steps to install

  • Install PostgreSQL and its libraries
  • 1
        sudo apt-GET install postgresql postgresql-contrib libpq-dev
  • After the installation create a user for postgresql
  • 1
        sudo -u postgres createuser --superuser $USER

    or

    1
        sudo -u postgres createuser pgs_root
  • Set user password for the postgresql user
  • 1
        sudo -u postgres psql postgres ( FOR psql prompt) postgres=# \passsword FOR ex.-      postgres=# \passsword pgs_root
  • Configure the postgresql.conf file to make PostgreSQL listen to localhost or listen on an external IP or something, change this line to either the IP or 'localhost'
  • 1
         gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost