I have tried installing the packet libpq-dev, and installing postgresql, but bundle install still fails due to gem pg. This is the error I get:
$ gem install pg -v '0.15.1'
Building native extensions. This could take a while...
/.rvm/rubies/ruby-1.9.3-
p484/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:73: warning: Insecure
world writable dir /usr/local in PATH, mode 040777
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/.rvm/rubies/ruby-1.9.3-p484/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.
What is a proper way to clean up the mess?
If you are on Mac, install Homebrew and then install Postgres using the command
brew install postgresql
Or you can download and install Postgres from here depending on which OS you are using.
There isn't any "mess" - it's a standard issue where your system does not have the required libraries to install the gem
Library
As mentioned in the comments, you first need to install PGSQL, which will create the required library files to help the gem install, after that you can use some path references to help the gem install:
gem install pg -- --with-pg-dir="C:/Program Files/installer
Related
I'm trying to "bundle" by rails app in AWS EC2 Linux server. I'm getting this error for "pg" gem. Could someone help? Can't find solution.
This gem 'pg' has version of 0.17.1.
Ruby version is ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.21.0/ext
/home/ec2-user/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20180105-17661-1wdsn6j.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:
--something something something
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.21.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.21.0 for inspection.
Results logged to /home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.21.0/gem_make.out
I had some problem same as you when i installed gem 'pg' on centos or ubuntu.
For centos, you can do this:
yum install postgresql-libs
yum install postgresql-devel
Then run gem install pg again.
On Ubuntu, I needed to run:
sudo apt-get install libpq-dev
UGH... I broke my (formerly functioning) Rails setup - under OS X Yosemite. I did so using Homebrew to update my version of Git. After getting Git where I want it, running 'rails c' gives these errors:
/Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg.rb:4:in `require': dlopen(/Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/lib/libpq.5.6.dylib (LoadError)
Referenced from: /Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle
Reason: image not found - /Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle
Seeing the reference to pg_ext, I tried to verify pieces of my postgresql installation. If I try 'gem install pg' or try to update the gem with bundler, I get this:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/grogers/.rbenv/versions/2.0.0-p353/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
*** 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.
I'm probably making my problem worse, but I went back and redid a 'brew install postgres' but still get the same error.
Any help appreciated. Thank you!
Did you also upgrade Postgresql via Homebrew? If not, what version of Postgres are you running, and how do you install it?
If you did upgrade your Postgres you'll need to rebuild the native bindings for the pg gem: gem uninstall pg && gem install pg.
I'm trying to bundle a new rails app using Postgres.
I get this error each time I try to bundle.
Errno::EACCES: Permission denied - /usr/local/var/rbenv/versions/2.0.0- p353/lib/ruby/gems/2.0.0/gems/pg-0.17.0/.gemtest
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.
When I try to install the pg gem with sudo it says:
➜ wandrr sudo gem install pg -v '0.17.0'
Password:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.0.0-p353/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.
I've read pg app's documentation and still not sure.
My zshrc file looks like this
# Customize to your needs...
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
export RBENV_ROOT=/usr/local/var/rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
I used homebrew to install rbenv and ruby-build.
I've check ruby gems is up to date aswel.
Any suggestions on how to get the pg gem to succeed?
SOLUTION FOUND
My initial problem of trying to get gem install pg to work was due to the postgres app not working right. The problem was fixed by checking the path set in my ZSHRC file.
Here's what it looks like now:
# Customize to your needs...
PATH=/Applications/Postgres93.app/Contents/MacOS/bin:$PATH
eval "$(rbenv init -)";
Note: the docs said to use
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
however the application in this instance is called Postgres93.app
I ran bundle update (so that I can install rails), but got this error:
$ bundle update
..... < other stuff ....>
Installing pg (0.14.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p374/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.
I'm new to Ruby and all this, could anyone tell me what is wrong here?
This is on OSX
Make sure ton install postgres first. I suggest you do so via homebrew, the Mac package manager.
brew install postgresql
Here is one of the many tutorials on how-to install postgres on a Mac.
EDIT
Looks like the gem can't find your postgres config, here's an answer similar to your problem:
https://stackoverflow.com/a/9669523/277370
I don't know what I've broken but I can't create any rails apps using sqlite any more.
When I try to run gem install sqlite3 or include sqlite3 in the gemfile for a rails app I get the following.
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
/Users/mark/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for sqlite3.h... *** 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.
I'm pretty new to ruby/rails etc so this makes very little sense to me.
I also ran a sudo gem update and ran into the same problem when it tried to update nokogiri.
Updating nokogiri
Fetching: nokogiri-1.5.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/mark/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for libxml/parser.h... *** 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.
Any idea/suggestions of what to try to get up and running with sqlite3 would be hugely appreciated.
Using ruby 1.9.2, OSX Lion.
Thanks, mark
The sqlite3 gem has to be compiled and link against the native sqlite3 libraries, so you'll need a C/C++ compiler and the sqlite3 development headers/libraries properly installed.
On Mac OS X, you can do this by installing the latest version of XCode. That should provide the C/C++ development tools and headers that the sqlite3 gem requires. It's a big download, but without it, you can't install the sqlite3 gem using the gem command, so make sure it's installed.
After you've installed XCode, reset your terminal and try running the "gem install sqlite3" again. It should work this time.
Try installing the sqlite3 development headers by running: port install sqlite3 +universal