Can't install pg gem on Windows
Solution 1
The message you're getting is a clear indication that you lack something for the correct installation of that gem:
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.
There is no Windows native version of latest release of pg (0.10.0) released yesterday, but if you install 0.9.0 it should install binaries without issues.
Anyhow, if you want to install the gem, you need a build environment installed. If you're using RubyInstaller, then you need the DevKit
Installation of the gem will only require you provide additional options to gem installation (like --with-pg-dir
)
subst X: "C:\Program Files (x86)\PostgreSQL\8.3"
gem install pg -- --with-pg-dir=X:
subst X: /D
Solution 2
PsAdding for linux users.
I solved this error installing libpq-dev.
Solution 3
I fought this for two days. I do my rails command line stuff from the excellent unixy like command window provided by msysgit. I created a postgresql-path.bat file that contained
@set PATH=%PATH%;C:\Progra~1\PostgreSQL\8.3\bin
@set PATH=%PATH%;C:\Progra~1\PostgreSQL\8.3\include
@set PATH=%PATH%;C:\Progra~1\PostgreSQL\8.3
At the top of the msys.bat file I added
CALL postgresql-path.bat
As soon as I got the space out of my PATH variable for the postgreSQL directories my problems installing 'pg' went away. Hope this saves somebody the problems I had.
Solution 4
After nearly two days of trial and error (and thanks in a large part to the advice of the earlier post in this thread and elsewhere, I was able to successfully install pg 0.10.0 in Ruby 1.8.7 (for both my RubyInstaller and my InstantRails versions). In case anyone encounters this problem again, I'll summarize my final successful installation process.
First, I had to install DevKit, following their installation instructions. I had to copy (for safety) and then delete the operating_system.rb file in \Ruby187\lib\ruby\site_ruby\1.8\rubygems\defaults folder in order for the installation to run successfully.
Secondly, I installed the rake-compiler, and rdoc gems. gem install rake-compiler gem install rdoc (If you have problems with either of them, I'd recommend a liberal use of the --platform=win32 configuration option)
Once those were installed successfully, the final installation of pg itself was:
gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg={Postgres directory short name}\
e.g. gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg=C:\PostgreSQL\
The final '\' seems to be necessary for the way the installer parses directory strings. I realize my use of configuration options may be a little more than necessary, but an apparently successful install of version 0.10.0 (when I excluded the --version option) did not actually work.
Thanks again to those in this thread who helped me to this sequence.
Solution 5
"gem install pg" not working
Fetching: pg-0.17.0.gem (100%) Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension.
Try this it worked for me and I am pretty sure it will work for you as well::
#On Ubuntu
$ sudo apt-get install postgresql-client libpq5 libpq-dev
$ sudo gem install pg
This should work with "Bash on Ubuntu on Windows" as well
sNiCKY
Updated on September 03, 2021Comments
-
sNiCKY over 2 years
I've got 2 Ruby versions: 1.8.7 and 1.9.2 and PostgreSQL 8.3. I cant install pg gem on any of them. Getting this error:
C:/Development/Ruby187/bin/ruby.exe extconf.rb checking for pg_config... yes not recorded 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=C:/Development/Ruby187/bin/ruby --with-pg --without-pg --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
I know it's a common problem, but I haven't found any working solution yet... Oh, I have added C:\Program Files (x86)\PostgreSQL\8.3\bin to my PATH.
-
sNiCKY over 13 yearsI have just installed 0.9.0 without the DevKit and it's working correctly. Thanks a lot Luis!
-
Luis Lavena over 13 yearsyeah, you need "--" to tell rubygems these options are for the extension compilation process
-
Phrogz over 13 yearsEven with DevKit and the above command (substituting my own pgsql dir) I get the same error as the OP:
Can't find the 'libpq-fe.h header
. -
Phrogz over 13 yearsI was able to accomplish this by editing the
Path
environment variable to addC:\Progra~2\PostgreSQL\8.4
to the end. (~2 corresponding in my case to "Program Files (x86)"). After that,gem install pg
was able to findpg_config.exe
without issue and install 0.10.0 correctly. -
jwfearn over 13 yearsDoes anyone know if a Windows native version of 0.10.0 will ever become available? I've tried all these tricks with no luck. BTW: I like the SUBST trick for working around spaces-in-paths problems.
-
Luis Lavena over 13 years@jwfearn, I would say you need to ask the gem author about it, can't help you on that :P
-
Denis Gorbunov over 13 yearsBut there is problem number two: "in `require': 126: �� ������ ��������� ������. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/pg-0.10.1/lib/1.9/pg_ext.so (LoadError)". I test the loading DLL "pg_ext.so". Other application (Visual Studio C++ writed) loads successfull "pg_ext.so", but Ruby cannot load "pg_ext.so"....
-
David about 13 yearsjust wanted to add here that this may not work on pg > 0.10.0. I got mine working with devkit and 0.9.0
-
Luis Lavena about 13 yearsIt should work now with version 0.10.1, which solves the incorrect locating mechanism of 0.10.0
-
Daniel Rikowski about 13 yearsFor me this only worked for 0.10.0. For 0.10.1 I had to add the
bin
and thelib
directories to the search path in their 8.3 form. Then it worked without adding the--with-pg-dir
option. -
SDReyes about 13 yearsI installed the DevKit, updated my path with the routes that Sehad mentioned. and installed successfully the pg 0.9.0
-
jwfearn about 13 yearsNOTE: 0.10.x never worked for me but 0.11.x (currently in prerelease) installs OK. Use
gem install pg --prerelease
. Or stick with 0.9.x. As far as I can tell 0.10.x just never worked on Windows. -
Phantomwhale over 12 yearsThis solved my Windows installation issues (of pg v0.12.2) - thanks !
-
Kenny Evitt about 12 yearsJust the "final installation" command
gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg={Postgres directory short name}`, combined with the
substr` trick in Luis's answer, was sufficient to get this installed for myself. -
Kenny Evitt about 12 yearsIf you use a specific platform and version you'll need to update
Gemfile
to match for Bundler (bundle install
) to work. -
Jakub Strebeyko over 5 years
sudo apt-get install libpq-dev
-
Sprachprofi over 4 yearsThis helped me! I didn't get any error during the installation of pg, but after an upgrade to ruby 2.5.7 I kept getting "cannot load such file -- 2.5/pg_ext" when trying to run the server. Reinstalling pg alone didn't fix it, but telling it --with-pg-dir fixed it. THANK YOU!!!
-
CajunAsian over 3 years@JakubStrebeyko this worked for me using WSL 20.04LTS and rvm/ruby 2.7.0. Thank you!