I'm trying to install the pg gem in my project but I get the following error when I run gem install pg, or if I run bundle install:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/pg-1.1.4/ext
/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/ruby -I /home/ec2-
user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0 -r
./siteconf20191103-5491-ro2ye0.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=/home/ec2-user/.rvm/rubies/ruby-2.6.3/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:
/home/ec2-user/.rvm/gems/ruby-2.6.3/extensions/x86_64-linux/2.6.0/pg-
1.1.4/mkmf.log
extconf failed, exit code 1
As you can see, I'm using Ruby version 2.6.3 and I'm on a Windows.
I'm trying to install the pg gem so that I can connect to the database.
I'm very new to all of this, so any help would be greatly appreciated
You are missing pg_config, which means most likely the pg development package has not been installed.
apt install libpq-dev
Go to https://rubygems.org/gems/pg ruby gems site and copy the latest gem into your gemfile. For me that was something like gem 'pg', '~> 1.3.0.rc1'.
Related
Need help setting up my database application with activerecord without rails. I have followed the documentation so far and I am encountering an error in regards to installing the pg gem. This is inside of my environment.rb.
require 'bundler/setup'
Bundler.require(:default, ENV['SINATRA_ENV'])
require 'active_record'
ActiveRecord::Base.establish_connection("postgres://localhost/development")
require_all 'app'
Every time I install postgres on the CLI with sudo ARCHFLAGS="-arch x86_64" gem install pg. I get an error of:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/kenkuts/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/pg-1.1.4/ext
/Users/kenkuts/.rvm/rubies/ruby-2.5.3/bin/ruby -r ./siteconf20190206-73835-1tfhfez.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
--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/kenkuts/.rvm/rubies/ruby-2.5.3/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:
/Users/kenkuts/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0/pg-1.1.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/kenkuts/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/pg-1.1.4 for inspection.
Results logged to /Users/kenkuts/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0/pg-1.1.4/gem_make.out
Install first install postgreSQL dev package as below,
sudo apt-get install libpq-dev
or try with,
gem install pg -- --with-pg-lib=/usr/lib
referring this post
Then most common way to use active_record along with postgres is as below,
require 'active_record'
require 'pg'
ActiveRecord::Base.establish_connection(
# database schema i.e. database, encoding, username, password etc.
)
Then you can define class as below,
class Post < ActiveRecord::Base
end
I recently blew away and re-installed rvm to fix some issues.
Now, however, when I try and install ruby-debug19 I get:
$ gem install ruby-debug19
... then ...
Building native extensions. This could take a while...
ERROR: Error installing ruby-debug19:
ERROR: Failed to build gem native extension.
/Users/snowcrash/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150619-25075-s8ve57.rb extconf.rb
checking for vm_core.h... no
*** 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/snowcrash/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--with-ruby-dir
--without-ruby-dir
--with-ruby-include
--without-ruby-include=${ruby-dir}/include
--with-ruby-lib
--without-ruby-lib=${ruby-dir}/lib
/Users/snowcrash/.rvm/gems/ruby-2.2.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:39:in `create_makefile_with_core': uninitialized constant Ruby_core_source::Config (NameError)
from extconf.rb:19:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Users/snowcrash/.rvm/gems/ruby-2.2.1/gems/linecache19-0.5.12 for inspection.
Results logged to /Users/snowcrash/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/linecache19-0.5.12/gem_make.out
And the log just contains these lines.
Any suggestions?
ruby-debug19 only works on Ruby 1.9. For Ruby 2.0 and above use byebug.
gem install byebug
I've tried bundling my Rails app on my Mac at work. At home it works fine and I've managed it solve it myself previously but this time no matter what I try nothing appears to be working to resolve it.
The error I receive when running bundle/bundle install is the following:
Installing pg (0.17.0)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/notrab/.rbenv/versions/2.0.0-p0/bin/ruby 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=/Users/notrab/.rbenv/versions/2.0.0-p0/bin/ruby
--with-pg
--without-pg
--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}/
Gem files will remain installed in /Users/notrab/Sites/Integrity/vendor/bundle/gems/pg-0.17.0 for inspection.
Results logged to /Users/notrab/Sites/Integrity/vendor/bundle/gems/pg-0.17.0/ext/gem_make.out
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that gem install pg -v '0.17.0' succeeds before bundling.
I've obviously tried running
gem install pg -v '0.17.0' and it says it was successful but bundling again shows the same error.
I have also tried running
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Which is outlined in the documentation http://postgresapp.com/documentation but the same error occurs when I try to bundle.
I'm going round in circles and don't know how to resolve it.
My Gemfile looks like:
group :development, :test do
gem "better_errors"
gem 'meta_request'
gem 'binding_of_caller'
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Many thanks,
Jamie
Have you tried adding export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" to your .bash_profile?
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Unable to install pg gem on ubuntu - Can’t find the 'libpq-fe.h header
Here is the error while trying to do bundle install
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 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/bin/ruby1.8
--with-pg
--without-pg
--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-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /var/lib/gems/1.8/gems/pg-0.14.1 for inspection.
Results logged to /var/lib/gems/1.8/gems/pg-0.14.1/ext/gem_make.out
i'm using ubuntu 12.04.Can any one point what may be wrong
Looks like you need to install the dev libraries for postgres:
sudo apt-get install libpq-dev
I've xcode 3.0 installed. And I need to install sqlite3-ruby gem (for rhosync).
When I run:
sudo gem install -l sqlite3-ruby
I get following error:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for #include <sqlite3.h>
... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... no
checking for sqlite3_initialize()... no
sqlite3-ruby only supports sqlite3 versions 3.6.16+, please upgrade!
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/lib
--with-sqlite3lib
--without-sqlite3lib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1/ext/sqlite3/gem_make.out
I've checked many links (on Stack Overflow and other sites) but nothing seems to work.
Some people suggest that install Ruby Headers from Mac OS X Disk 2. But I don't have that disc. I've instead installed XCode 3.0 SDK.
What should I do?
I installed MacPorts from http://macports.org and then ran
sudo port install sqlite3
after that sqlite3-ruby installed successfully.