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.
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
PsAdding for linux users.
I solved this error installing libpq-dev.
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.
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.
"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
First install ruby DevKit
On Windows XP and from MSysGIT bash terminal just do the following
based on my installation path
subst X: "D:/Program Files/PostgreSQL/9.0"
gem install pg -- --with-pg=X:
My gem pg-0.10.1 got installed successfully.
This may seem like a no brainer, but I had this same error with a slight twist. After getting the build to find the headers, it immediately failed and claimed to be unable to find libpq. I finally deduced that I was trying to build against a 64-bit postgres install with a 32-bit ruby. Installing the 32-bit postgres resulted in an instant-fix. Just thought I'd add this in case anyone else with the same error stumbles across this thread.
The message "Can't find the 'libpq-fe.h header" means that installer can't find the header
Check that your Postgre installation contains development tools ("include" folder). Install postgre development tools in case of absence.
Check location of pg_config.exe. You need run installation like
gem install pg -- --with-pg-config="C:/PROGRA~2/POSTGR~1/8.3/bin/pg_config.exe".
Note that you need to use short folder names.
To build a native extension for pg gem you need a ruby DevKit (http://rubyinstaller.org/downloads/)
I meet another problem:
D:\app1>rake test
(in D:/app1)
rake aborted!
no such file to load -- 1.9/pg_ext
In this case you need manually copy copy content of
C:\Ruby\192\lib\ruby\gems\1.9.1\gems\pg-0.10.0\lib\
to
C:\Ruby\192\lib\ruby\gems\1.9.1\gems\pg-0.10.0\lib\1.9
Thanks Luis! pg 0.9.0 installed just fine.
For the latest version (0.10.0) you need the devkit and this command "gem install pg -- --with pg-dir=path/to/your/postgresql/dir"
When I leave the additional "--" away, it gets me an error:
"gem install pg --with-pg-dir=C:/postgresql/9.0"
I had the same problem.
You most likely have a perl installation in your path before PostgreSQL. The most common perl installation for Windows has an executable name pg_config in its bin which causes conflicts.
pg v0.10.0 installs just fine with rubyinstaller + devkit as long as you specify paths without spaces (e.g. C:/PROGRA~) -- otherwise nmake chokes.
Windows 7, PostgreSQL 8.4, Ruby 1.9.2:
subst X:\ "C:\Program Files\PostgreSQL\8.4"
gem install pg -- --with-pg=X:/
This installed it successfully.
Other easy way, on windows
Install postgresql ODBC.
Copy libpq.dll from the pgqlODBC lib directory
Paste it into PostGreSQL lib directory
Run this command (adapt the PostGreSQL path in this command, according to yours) :
gem install pg -- --with-pg-config="C:\Dev\Databases\PostgreSQL\9.0\bin\pg_config.exe"
install postgresql per pacman:
ridk exec pacman -S mingw-w64-x86_64-postgresql
then do
bundle install
I had the same problem.
The following worked for me. Hope this helps to you.
Versions:
Windows 10 version 10.0.19043.1165.
PostgreSQL Server 13.
Ruby DevKit 3.0.2-1 (x64).
Administrator prompt: C:\Ruby30-x64> subst X: "C:\Program Files\PostgreSQL\13\bin"
Administrator prompt: C:\Ruby30-x64> gem install pg -- --with-pg-dir=X: --with-pg-include="c:\Program Files\PostgreSQL\13\include" --with-pg-lib="C:\Program Files\PostgreSQL\13\lib"
I ran into the same problem. I wanted to access a postgres database using dbi and had to install Pg.
It took me a day to successfully compile the module with instructions similar to the other posts of this thread. But the second time I had to do it, I found another solution: using ODBC.
Install the ODBC driver for postgresql (http://www.postgresql.org/ftp/odbc/versions/)
Configure the data source (http://www.xtuple.org/SettingUpPostgresAndOdbc)
Install the ruby dbi and odbc gems
gem install dbi
gem install ruby-odbc
gem install dbd-odbc
Connect to postgres
require 'dbi'
dbh = DBI.connect('dbi:ODBC:DSN_NAME', 'USER', 'PASS')
This worked for me using ruby 1.9.1 on Windows XP 32 bit.
Also, this doesn't change anything in your code except the DBI.connect line, if you were already using DBI.
PostgreSQL 9.0:
gem install pg --platform=mswin32 --version=0.9.0 -- '--with-pg="C:\Progra~1\PostgreSQL\"'
note the single-tick encapsulation. (~1 signifies "Program Files", change to ~2 if PostgreSQL is in Program Files (x86) on Win64)
As of version 0.13.0 of the pg gem, you should be able to install it using something like the following:
subst X: "C:\Program Files\PostgreSQL\9.0"
gem install pg -- -- with-pg=X:
subst X: /D
Then you can successfully run bundle install and see the following line in the output:
Using pg (0.13.0)
instead of the errors.
I got it:
AND THE MAGIC TRICK :
is that you do not have this installed -- > postgres-devel
so go get it :
install postgresql-devel
Thats all... than just gem install pg and there it goes.
Related
I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:
Building native extensions. This could take a while... ERROR: Error
installing pg: ERROR: Failed to build gem native extension.
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0
for inspection. Results logged to
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out
I tried everything I found on stackoverflow but I still get this error.
If I try to install postgresql using brew I get the following waring:
Warning: postgresql-9.2.4 already installed, it's just not linked
If I try to link
brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4...
Warning: Could not link postgresql. Unlinking...
Error: Could not symlink file:
/usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7
/usr/local/share/man/man7 is not writable. You should change its
permissions.
Help Please
NOTE: I already installed the command line tools for mavericks.
If I uninstall using homebrew and try to install again, I get this error:
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
################################################################## 100.0%
==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p
==> make install-world
==> Caveats
Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x
installed, you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
Create/Upgrade a Database
If this is your first install, create a database with: initdb
/usr/local/var/postgres -E utf8
To migrate existing data from a previous major version (pre-9.2) of
PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html
Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a
list of all available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database
and run: CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database,
run: CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For
more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html
Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't
want/need launchctl, you can just run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link
postgresql. Unlinking... Error: The brew link step did not complete
successfully The formula built, but is not symlinked into /usr/local
You can try again using `brew link postgresql'
==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes
SOLUTION:
I execute this command in order to change the permission of the folder:
sudo chown jeanosorio /usr/local/share/man/man7
Then
brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421
symlinks created
And finally:
sudo ARCHFLAGS="-arch x86_64" gem install pg
Fetching: pg-0.17.0.gem (100%) Building native extensions. This could
take a while... Successfully installed pg-0.17.0
If you want to avoid using MacPorts, you can download the Postgres App and place it into the Application directory.
Then, specify the location of newly downloaded pg_config:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
If you run in to missing headers problem, try specifying the include directory of the app:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'
Use brew to get postgresql
brew install postgresql
Check you have pg_config in the installed brew. I found mine in
/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Check via :
$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
> /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Once done, install the pg gem with
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
I wasn't able to install postgres via MacPorts. Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Note: in newer versions (in 9.3 at least) the path is actually: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
If you have homebrew, just type:
$ brew install postgresql
For me, on Yosemite, I didn't need to specify pg_config path. The following got it done.
brew install postgresql
sudo env ARCHFLAGS="-arch x86_64" gem install pg
Seems like architecture flag is the key.
Here's another alternative in case you want to use the postgresql installer directly. There's a couple of hoops you gotta jump through to begin with after updating to mavericks. Here's what I did:
Install the xcode command line tools first:
xcode-select --install
Download and install the latest version of PostgreSQL (9.3.1), in my case I just used the graphical installer. Here's the link to the downloads page:
http://www.enterprisedb.com/products-services-training/pgdownload#osx
Just choose all of the defaults it gives you. It my case it installed postgres to the following directory, if you installed it to a different directory, just remember the path you chose, because you'll need it shortly.
/Library/PostgreSQL/9.3
If you now try and install the latest pg gem (0.17.0) you'll need to pass a couple of options on the command line. This is what I used:
ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
If you installed postgres to a different location then you'll need to fix up the path to the pg_config file.
If it complains of a missing 'libpq.5.dylib' file while trying install the pg gem you'll need to create a symlink pointing to the actual location of this file. Postgres is looking for it in your /usr/local/lib/ directory so create a symlink in there and redirect it to its actual location. In my case I had to run:
sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib
Once you've done that, retry installing the gem again and hopefully it will work for you the same way it did for me.
In my case (i needed PG 0.16.0 on Mavericks), i installed postgresql via MacPorts
sudo port install postgresql90
and then
gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
For the latest version you need to deduct -v '0.16.0'
gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
If you have Homebrew installed do not install MacPorts before you read about their coexistense
Place the missing --with-pg-config in Bundler's config file: /Users/<your_user>/.bundle/config to make your life easier.
---
BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs
Then run bundle install again.
That works for me! (Postgres 93, mac ox 10.9.1)1. download # http://postgresapp.com/ and than
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'
The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config
I just ran the following command and magic happened.
bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case it didn't work if you don't specify the arch flags, OS X 10.10.3 and postersApp 9.4
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- \--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
The easiest way for me to resolve this was to use Postgres.app and set up my env vars so gem install pg just works (instead of requiring the --with-pg-config flag).
Using Homebrew Cask,
brew cask install postgres
echo 'export PG_HOME=/Applications/Postgres.app/Contents/Versions/latest' >> ~/.bash_profile
echo 'export PATH="$PATH:$PG_HOME/bin"' >> ~/.bash_profile
source ~/.bash_profile
# now it just works
gem install pg
This is what it worked for me:
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case, I uninstalled the version installed via homebrew and switched to Postgres.app (v9.3.4.2 at the time of writing).
It only seemed to work when prepending the environment architecture flags and specifying the path to pg_config. Your milage might vary, so this answer could help with variations on pg_config's location.
Here is the final, complete command that worked for me:
env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
I had installed postgres using homebrew on mac. Used below command to find the location
which postgres
/usr/local/opt/postgresql#12/bin/postgres
Installed gem using below command. In the above path just replace the postgres with pg_config since command requires path for pg_config.
gem install pg -- --with-pg-config=/usr/local/opt/postgresql#12/bin/pg_config
I was getting the same error when running bundle install regarding the pg gem (using Mac OS X Mavericks). After hours of researching, I found the solution. I installed postgres using homebrew
brew install postgres
After installing that, I created a new rails app using postgres. I ran
bundle install
to no avail (got same error as the question). I used
which psql
to figure out where my postgres was installed, it returned
/usr/local/bin/psql
before running bundle install again, I had to change the global path to build.pg by running the following
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
then I ran bundle install again and voila! I used the postgres where brew installed it.
On OS X Mavericks with latest Postgres App do the following with sudo privileges
env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
What worked for me on 10.9.3 with Xcode 5.1.1 was the following:
brew update
brew install postgresql
gem install pg -v '0.17.1'
I needed pg 0.17.1
For me, the error message looked like this:
Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
As the error message shows, it's trying to execute the command/script "pg_config". So just add it to the path from wherever your Postgres installation is. In my case, I did:
export PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH
then
bundle
That's it.
For any lost soul outthere still having this issue with no resolution and have a brew installed ruby and postgres. Here's the following steps to make sure of:
Make sure your version of ruby wasn't installed with the --universal flag.
This was the hardest thing to figure out, I had --universal which was the final root of the problem.
Make sure you have initialized postgresql properly with initdb and createdb commands (look elsewhere for steps to do this).
Make sure Xcode (Optional) and command line tools is installed; on the terminal:
xcode-select --install
sudo xcodebuild -license (if Xcode installed) or open the application and accept the license agreement.
Reboot Computer
which ruby, which gem and which postgres should show /usr/local/bin/ruby, /usr/local/bin/gem and /usr/local/bin/postgres respectfully.
On the terminal run:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
or
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Making sure all these steps are satisfied I was able to solve the following errors:
ruby.h header error
developer tools installed first error
First of all find pg_config location
sudo find / -name "pg_config" -print
The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)
Then try installing something like below
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
if this does not work then try to check in what way you installed postgresql
brew/mac port/setup
then you have to try relevant option to the same.
Thank you.
Ram
I was with the same problem, this was the solution I've found.
If you run brew doctor, it will tell you that probably you have installed something without brew that have changed the permissions on some folders, and so, you need to change permissions back to you on that folder.
Inside /usr/local/share/man, what you can do is the following:
sudo chown [yourusername] man7
And then:
brew link postgres
Hope it helps!
Similarly, after installing Mavericks 'bundle update' was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just 'brew uninstall postgresql', then 'brew install postgresql'. After which I was immediately able to successfully run 'bundle update'
Postgres 9.4:
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/Versions/9.4/bin/pg_config
sudo su
then
ARCHFLAGS="-arch x86_64" gem install pg -v '0.18'
worked on 10.10.2
If after trying everything here it still won't install, try opening Xcode and accepting the license agreement.
I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:
Building native extensions. This could take a while... ERROR: Error
installing pg: ERROR: Failed to build gem native extension.
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0
for inspection. Results logged to
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out
I tried everything I found on stackoverflow but I still get this error.
If I try to install postgresql using brew I get the following waring:
Warning: postgresql-9.2.4 already installed, it's just not linked
If I try to link
brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4...
Warning: Could not link postgresql. Unlinking...
Error: Could not symlink file:
/usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7
/usr/local/share/man/man7 is not writable. You should change its
permissions.
Help Please
NOTE: I already installed the command line tools for mavericks.
If I uninstall using homebrew and try to install again, I get this error:
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
################################################################## 100.0%
==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p
==> make install-world
==> Caveats
Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x
installed, you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
Create/Upgrade a Database
If this is your first install, create a database with: initdb
/usr/local/var/postgres -E utf8
To migrate existing data from a previous major version (pre-9.2) of
PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html
Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a
list of all available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database
and run: CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database,
run: CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For
more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html
Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't
want/need launchctl, you can just run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link
postgresql. Unlinking... Error: The brew link step did not complete
successfully The formula built, but is not symlinked into /usr/local
You can try again using `brew link postgresql'
==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes
SOLUTION:
I execute this command in order to change the permission of the folder:
sudo chown jeanosorio /usr/local/share/man/man7
Then
brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421
symlinks created
And finally:
sudo ARCHFLAGS="-arch x86_64" gem install pg
Fetching: pg-0.17.0.gem (100%) Building native extensions. This could
take a while... Successfully installed pg-0.17.0
If you want to avoid using MacPorts, you can download the Postgres App and place it into the Application directory.
Then, specify the location of newly downloaded pg_config:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
If you run in to missing headers problem, try specifying the include directory of the app:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'
Use brew to get postgresql
brew install postgresql
Check you have pg_config in the installed brew. I found mine in
/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Check via :
$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
> /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Once done, install the pg gem with
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
I wasn't able to install postgres via MacPorts. Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Note: in newer versions (in 9.3 at least) the path is actually: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
If you have homebrew, just type:
$ brew install postgresql
For me, on Yosemite, I didn't need to specify pg_config path. The following got it done.
brew install postgresql
sudo env ARCHFLAGS="-arch x86_64" gem install pg
Seems like architecture flag is the key.
Here's another alternative in case you want to use the postgresql installer directly. There's a couple of hoops you gotta jump through to begin with after updating to mavericks. Here's what I did:
Install the xcode command line tools first:
xcode-select --install
Download and install the latest version of PostgreSQL (9.3.1), in my case I just used the graphical installer. Here's the link to the downloads page:
http://www.enterprisedb.com/products-services-training/pgdownload#osx
Just choose all of the defaults it gives you. It my case it installed postgres to the following directory, if you installed it to a different directory, just remember the path you chose, because you'll need it shortly.
/Library/PostgreSQL/9.3
If you now try and install the latest pg gem (0.17.0) you'll need to pass a couple of options on the command line. This is what I used:
ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
If you installed postgres to a different location then you'll need to fix up the path to the pg_config file.
If it complains of a missing 'libpq.5.dylib' file while trying install the pg gem you'll need to create a symlink pointing to the actual location of this file. Postgres is looking for it in your /usr/local/lib/ directory so create a symlink in there and redirect it to its actual location. In my case I had to run:
sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib
Once you've done that, retry installing the gem again and hopefully it will work for you the same way it did for me.
In my case (i needed PG 0.16.0 on Mavericks), i installed postgresql via MacPorts
sudo port install postgresql90
and then
gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
For the latest version you need to deduct -v '0.16.0'
gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
If you have Homebrew installed do not install MacPorts before you read about their coexistense
Place the missing --with-pg-config in Bundler's config file: /Users/<your_user>/.bundle/config to make your life easier.
---
BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs
Then run bundle install again.
That works for me! (Postgres 93, mac ox 10.9.1)1. download # http://postgresapp.com/ and than
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'
The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config
I just ran the following command and magic happened.
bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case it didn't work if you don't specify the arch flags, OS X 10.10.3 and postersApp 9.4
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- \--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
The easiest way for me to resolve this was to use Postgres.app and set up my env vars so gem install pg just works (instead of requiring the --with-pg-config flag).
Using Homebrew Cask,
brew cask install postgres
echo 'export PG_HOME=/Applications/Postgres.app/Contents/Versions/latest' >> ~/.bash_profile
echo 'export PATH="$PATH:$PG_HOME/bin"' >> ~/.bash_profile
source ~/.bash_profile
# now it just works
gem install pg
This is what it worked for me:
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case, I uninstalled the version installed via homebrew and switched to Postgres.app (v9.3.4.2 at the time of writing).
It only seemed to work when prepending the environment architecture flags and specifying the path to pg_config. Your milage might vary, so this answer could help with variations on pg_config's location.
Here is the final, complete command that worked for me:
env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
I had installed postgres using homebrew on mac. Used below command to find the location
which postgres
/usr/local/opt/postgresql#12/bin/postgres
Installed gem using below command. In the above path just replace the postgres with pg_config since command requires path for pg_config.
gem install pg -- --with-pg-config=/usr/local/opt/postgresql#12/bin/pg_config
I was getting the same error when running bundle install regarding the pg gem (using Mac OS X Mavericks). After hours of researching, I found the solution. I installed postgres using homebrew
brew install postgres
After installing that, I created a new rails app using postgres. I ran
bundle install
to no avail (got same error as the question). I used
which psql
to figure out where my postgres was installed, it returned
/usr/local/bin/psql
before running bundle install again, I had to change the global path to build.pg by running the following
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
then I ran bundle install again and voila! I used the postgres where brew installed it.
On OS X Mavericks with latest Postgres App do the following with sudo privileges
env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
What worked for me on 10.9.3 with Xcode 5.1.1 was the following:
brew update
brew install postgresql
gem install pg -v '0.17.1'
I needed pg 0.17.1
For me, the error message looked like this:
Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
As the error message shows, it's trying to execute the command/script "pg_config". So just add it to the path from wherever your Postgres installation is. In my case, I did:
export PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH
then
bundle
That's it.
For any lost soul outthere still having this issue with no resolution and have a brew installed ruby and postgres. Here's the following steps to make sure of:
Make sure your version of ruby wasn't installed with the --universal flag.
This was the hardest thing to figure out, I had --universal which was the final root of the problem.
Make sure you have initialized postgresql properly with initdb and createdb commands (look elsewhere for steps to do this).
Make sure Xcode (Optional) and command line tools is installed; on the terminal:
xcode-select --install
sudo xcodebuild -license (if Xcode installed) or open the application and accept the license agreement.
Reboot Computer
which ruby, which gem and which postgres should show /usr/local/bin/ruby, /usr/local/bin/gem and /usr/local/bin/postgres respectfully.
On the terminal run:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
or
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Making sure all these steps are satisfied I was able to solve the following errors:
ruby.h header error
developer tools installed first error
First of all find pg_config location
sudo find / -name "pg_config" -print
The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)
Then try installing something like below
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
if this does not work then try to check in what way you installed postgresql
brew/mac port/setup
then you have to try relevant option to the same.
Thank you.
Ram
I was with the same problem, this was the solution I've found.
If you run brew doctor, it will tell you that probably you have installed something without brew that have changed the permissions on some folders, and so, you need to change permissions back to you on that folder.
Inside /usr/local/share/man, what you can do is the following:
sudo chown [yourusername] man7
And then:
brew link postgres
Hope it helps!
Similarly, after installing Mavericks 'bundle update' was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just 'brew uninstall postgresql', then 'brew install postgresql'. After which I was immediately able to successfully run 'bundle update'
Postgres 9.4:
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/Versions/9.4/bin/pg_config
sudo su
then
ARCHFLAGS="-arch x86_64" gem install pg -v '0.18'
worked on 10.10.2
If after trying everything here it still won't install, try opening Xcode and accepting the license agreement.
I've seen very similar problems in other SO questions (e.g. No source for ruby-1.9.2-p321 provided with debugger-ruby_core_source gem) as well as through a Google search, but none of those have helped so far.
I'm using OSX Mavericks (first time mac user) and rbenv (first time using that too). I've git cloned a Rails project which I've previously ran on another laptop (Ubuntu & rvm) fine.
rbenv version: 2.0.0-p451 (which I manually installed)
When I try to bundle install, I get the following:
...
Using debugger-ruby_core_source (1.3.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/macuser/.rbenv/versions/2.0.0-p451/bin/ruby extconf.rb
checking for rb_method_entry_t.called_id in method.h... no
checking for rb_control_frame_t.method_id in method.h... no
checking for rb_method_entry_t.called_id in method.h... no
checking for rb_control_frame_t.method_id in method.h... no
Makefile creation failed
**************************************************************************
No source for ruby-2.0.0-p451 provided with debugger-ruby_core_source gem.
**************************************************************************
*** 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/macuser/.rbenv/versions/2.0.0-p451/bin/ruby
--with-ruby-dir
--without-ruby-dir
--with-ruby-include=${ruby-dir}/include
--with-ruby-lib
--without-ruby-lib=${ruby-dir}/
Gem files will remain installed in /Users/macuser/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/debugger-1.6.5 for inspection.
Results logged to /Users/macuser/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/debugger-1.6.5/ext/ruby_debug/gem_make.out
An error occurred while installing debugger (1.6.5), and Bundler cannot continue.
Make sure that `gem install debugger -v '1.6.5'` succeeds before bundling.
So I then tried running gem install debugger -v '1.6.5', which throws basically the same error as above.
From searching around, here's some things I've unsuccessfully tried:
rake add_source
bundle update debugger
Resetting gemfile.lock
gem install debugger-ruby_core_source
and probably some others too... but nothing seems to work.
Update: Switched my rbenv local environment to ruby 2.1.0 and it worked. Didn't fix the underlying problem, but this is fine I guess
Try install debugger without specifying a version and then run bundle install again.
I had the same error, and it just worked, don't ask me why:
$ gem install debugger
$ bundle install
I ran into what I believe was the same problem while trying to install dubugger with ruby 2.0.0-p598.
The gem debugger-ruby_core_source is a dependency of debugger and provides header files for specific versions of ruby that seem to be used while installing debugger. Look in debugger-ruby_core_source/lib/debugger/ruby_core_source/ to see which versions are supported—the header files are not provided for all ruby versions. In my case, they were not provided for version 2.0.0-p598.
Looking at the README for debugger-ruby_core_source, there is a rake task for adding the required files for ruby versions.
From the command line within the gem's directory, I ran
$ rake add_source VERSION=2.0.0-p598
When I ran this task the first time, I received an error and was required to install the archive-tar-minitar gem before running the rake task again.
After the rake task added the header files for my version, I was able to successfully install and run debugger.
I am posting here because absolutely nothing worked. The only solution that fixed the problem for me:
Even though we are installing debugger, the error is in installing a requirement, debugger-ruby_core_source.
If you look at the error that is exactly where it raises the issue.
No source for ruby-2.0.0-p451 provided with debugger-ruby_core_source gem.
It is actually quite easy to fix this error. Just run the below command, installing the dependencies, and retry:
gem install debugger-ruby_core_source
Credit for this solution to: FIXED gem install debugger -v ’1.6.2′ No source for ruby
The problem is that your Gemfile.lock lists an old debugger-ruby_core_source gem. That gem needs to know about your specific ruby version, to get the header files correctly, and if the version your bundle install is too old, it won't work.
The correct solution is to update your Gemfile.lock with a new version, by running
bundle update debugger-ruby_core_source
#delba's and #superuseroi's answers basically coming down to using gem to install the debugger-ruby_core_source gem directly from the source - which will pull the latest version, but fixing your bundle will be easier and will also persist in your source control (at least until you next upgrade your Ruby).
Also see this article about common Ruby gem issues
Debugger needs source of the Ruby to work.
So just reinstall the Ruby with source (not bin).
For example:
rvm reinstall 2.0.0 --disable-binary
Thanks all.
rvm list
rvm ruby-2.0.0-p451
Tried bundle install, got errors about not being able to install into non-bare repository, suggesting I remove cache directory; which I did:
rm -rf /usr/local/rvm/gems/ruby-2.0.0-p451/cache/
tried to
rvm gemsest use [my_gemset_name]
and got the same errors.
ended up using:
rvm gemset use default
and bundle install worked.
there seems to be a problem with the compatibility of ruby version and debugger gem of rails.
Running the below command worked for me:
rvm ruby-2.0.0-p481
If it doesn't work type
rvm list
will get a list of ruby version.
Select an older ruby version, which might work.
To solve this problem, you need reinstall rails' source code. This command will fix the problem:
$ rvm reinstall 2.0.0 --disable-binary
Then, the command $ bundle install will work.
Reference: https://pfonseca.com/error-to-install-debugger-s-gem
Use byebug gem instead of fix my problem very well.
I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:
Building native extensions. This could take a while... ERROR: Error
installing pg: ERROR: Failed to build gem native extension.
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0
for inspection. Results logged to
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out
I tried everything I found on stackoverflow but I still get this error.
If I try to install postgresql using brew I get the following waring:
Warning: postgresql-9.2.4 already installed, it's just not linked
If I try to link
brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4...
Warning: Could not link postgresql. Unlinking...
Error: Could not symlink file:
/usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7
/usr/local/share/man/man7 is not writable. You should change its
permissions.
Help Please
NOTE: I already installed the command line tools for mavericks.
If I uninstall using homebrew and try to install again, I get this error:
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
################################################################## 100.0%
==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p
==> make install-world
==> Caveats
Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x
installed, you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
Create/Upgrade a Database
If this is your first install, create a database with: initdb
/usr/local/var/postgres -E utf8
To migrate existing data from a previous major version (pre-9.2) of
PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html
Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a
list of all available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database
and run: CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database,
run: CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For
more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html
Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't
want/need launchctl, you can just run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link
postgresql. Unlinking... Error: The brew link step did not complete
successfully The formula built, but is not symlinked into /usr/local
You can try again using `brew link postgresql'
==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes
SOLUTION:
I execute this command in order to change the permission of the folder:
sudo chown jeanosorio /usr/local/share/man/man7
Then
brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421
symlinks created
And finally:
sudo ARCHFLAGS="-arch x86_64" gem install pg
Fetching: pg-0.17.0.gem (100%) Building native extensions. This could
take a while... Successfully installed pg-0.17.0
If you want to avoid using MacPorts, you can download the Postgres App and place it into the Application directory.
Then, specify the location of newly downloaded pg_config:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
If you run in to missing headers problem, try specifying the include directory of the app:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'
Use brew to get postgresql
brew install postgresql
Check you have pg_config in the installed brew. I found mine in
/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Check via :
$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
> /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Once done, install the pg gem with
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
I wasn't able to install postgres via MacPorts. Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Note: in newer versions (in 9.3 at least) the path is actually: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
If you have homebrew, just type:
$ brew install postgresql
For me, on Yosemite, I didn't need to specify pg_config path. The following got it done.
brew install postgresql
sudo env ARCHFLAGS="-arch x86_64" gem install pg
Seems like architecture flag is the key.
Here's another alternative in case you want to use the postgresql installer directly. There's a couple of hoops you gotta jump through to begin with after updating to mavericks. Here's what I did:
Install the xcode command line tools first:
xcode-select --install
Download and install the latest version of PostgreSQL (9.3.1), in my case I just used the graphical installer. Here's the link to the downloads page:
http://www.enterprisedb.com/products-services-training/pgdownload#osx
Just choose all of the defaults it gives you. It my case it installed postgres to the following directory, if you installed it to a different directory, just remember the path you chose, because you'll need it shortly.
/Library/PostgreSQL/9.3
If you now try and install the latest pg gem (0.17.0) you'll need to pass a couple of options on the command line. This is what I used:
ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
If you installed postgres to a different location then you'll need to fix up the path to the pg_config file.
If it complains of a missing 'libpq.5.dylib' file while trying install the pg gem you'll need to create a symlink pointing to the actual location of this file. Postgres is looking for it in your /usr/local/lib/ directory so create a symlink in there and redirect it to its actual location. In my case I had to run:
sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib
Once you've done that, retry installing the gem again and hopefully it will work for you the same way it did for me.
In my case (i needed PG 0.16.0 on Mavericks), i installed postgresql via MacPorts
sudo port install postgresql90
and then
gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
For the latest version you need to deduct -v '0.16.0'
gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
If you have Homebrew installed do not install MacPorts before you read about their coexistense
Place the missing --with-pg-config in Bundler's config file: /Users/<your_user>/.bundle/config to make your life easier.
---
BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs
Then run bundle install again.
That works for me! (Postgres 93, mac ox 10.9.1)1. download # http://postgresapp.com/ and than
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'
The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config
I just ran the following command and magic happened.
bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case it didn't work if you don't specify the arch flags, OS X 10.10.3 and postersApp 9.4
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- \--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
The easiest way for me to resolve this was to use Postgres.app and set up my env vars so gem install pg just works (instead of requiring the --with-pg-config flag).
Using Homebrew Cask,
brew cask install postgres
echo 'export PG_HOME=/Applications/Postgres.app/Contents/Versions/latest' >> ~/.bash_profile
echo 'export PATH="$PATH:$PG_HOME/bin"' >> ~/.bash_profile
source ~/.bash_profile
# now it just works
gem install pg
This is what it worked for me:
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case, I uninstalled the version installed via homebrew and switched to Postgres.app (v9.3.4.2 at the time of writing).
It only seemed to work when prepending the environment architecture flags and specifying the path to pg_config. Your milage might vary, so this answer could help with variations on pg_config's location.
Here is the final, complete command that worked for me:
env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
I had installed postgres using homebrew on mac. Used below command to find the location
which postgres
/usr/local/opt/postgresql#12/bin/postgres
Installed gem using below command. In the above path just replace the postgres with pg_config since command requires path for pg_config.
gem install pg -- --with-pg-config=/usr/local/opt/postgresql#12/bin/pg_config
I was getting the same error when running bundle install regarding the pg gem (using Mac OS X Mavericks). After hours of researching, I found the solution. I installed postgres using homebrew
brew install postgres
After installing that, I created a new rails app using postgres. I ran
bundle install
to no avail (got same error as the question). I used
which psql
to figure out where my postgres was installed, it returned
/usr/local/bin/psql
before running bundle install again, I had to change the global path to build.pg by running the following
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
then I ran bundle install again and voila! I used the postgres where brew installed it.
On OS X Mavericks with latest Postgres App do the following with sudo privileges
env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
What worked for me on 10.9.3 with Xcode 5.1.1 was the following:
brew update
brew install postgresql
gem install pg -v '0.17.1'
I needed pg 0.17.1
For me, the error message looked like this:
Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
As the error message shows, it's trying to execute the command/script "pg_config". So just add it to the path from wherever your Postgres installation is. In my case, I did:
export PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH
then
bundle
That's it.
For any lost soul outthere still having this issue with no resolution and have a brew installed ruby and postgres. Here's the following steps to make sure of:
Make sure your version of ruby wasn't installed with the --universal flag.
This was the hardest thing to figure out, I had --universal which was the final root of the problem.
Make sure you have initialized postgresql properly with initdb and createdb commands (look elsewhere for steps to do this).
Make sure Xcode (Optional) and command line tools is installed; on the terminal:
xcode-select --install
sudo xcodebuild -license (if Xcode installed) or open the application and accept the license agreement.
Reboot Computer
which ruby, which gem and which postgres should show /usr/local/bin/ruby, /usr/local/bin/gem and /usr/local/bin/postgres respectfully.
On the terminal run:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
or
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Making sure all these steps are satisfied I was able to solve the following errors:
ruby.h header error
developer tools installed first error
First of all find pg_config location
sudo find / -name "pg_config" -print
The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)
Then try installing something like below
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
if this does not work then try to check in what way you installed postgresql
brew/mac port/setup
then you have to try relevant option to the same.
Thank you.
Ram
I was with the same problem, this was the solution I've found.
If you run brew doctor, it will tell you that probably you have installed something without brew that have changed the permissions on some folders, and so, you need to change permissions back to you on that folder.
Inside /usr/local/share/man, what you can do is the following:
sudo chown [yourusername] man7
And then:
brew link postgres
Hope it helps!
Similarly, after installing Mavericks 'bundle update' was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just 'brew uninstall postgresql', then 'brew install postgresql'. After which I was immediately able to successfully run 'bundle update'
Postgres 9.4:
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/Versions/9.4/bin/pg_config
sudo su
then
ARCHFLAGS="-arch x86_64" gem install pg -v '0.18'
worked on 10.10.2
If after trying everything here it still won't install, try opening Xcode and accepting the license agreement.
I am getting the following error message while installing, let me know if I need to post more details.
I followed instructions from the following location:
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
I am using ruby 1.9.2p136 (2010-12-25) [i386-mingw32].
Here is what I get:
E:\work_desk\trunk>gem install mysql2 -v 0.2.4
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby192/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for main() in -llibmysql... 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=C:/Ruby192/bin/ruby
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-libmysqllib
--without-libmysqllib
Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.
2.4 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.4/ext/mysql2/ge
m_make.out
The specific version of mysql2 gem you're trying to install (0.2.4) not only lacks binaries for Windows, but have issues on Windows.
Please install mysql2 gem without indicating the version:
gem install mysql2
Which will install latest version (0.2.6 at the time of my posting this) and also provides binaries for Windows which skip the compilation step.
If you still want to force the compilation (because your version of MySQL differs from the one used to generate the binary gem, you will need to install RubyInstaller's DevKit from RubyInstaller website:
http://rubyinstaller.org/downloads
And follow the DevKit installation instructions from our wiki (that is linked from the download page)
You will need to provide the path to both headers and libraries during the gem installation process, and adjust the MySQL installation location from the following instructions:
subst X: "C:\Program Files (x86)\MySQL\MySQL Server 5.1"
gem install mysql2 --platform=ruby -- --with-mysql-dir=X: --with-mysql-lib=X:\lib\opt
subst X: /D
The above command uses subst to avoid issues with path with spaces, which you should avoid always.
Hope this helps.
After searching around for a way to make it work, I finally got it installed with the following on the command prompt:
gem install mysql2 -v 0.2.6
With the following results:
Fetching: mysql2-0.2.6-x86-mingw32.gem (100%)
Successfully installed mysql2-0.2.6-x86-minw32
1 gem installed
Installing ri documentation for mysql2-0.2.6-x86-mingw32...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6-x86-mingw32...
Enclosing class/module 'mMysql2' for class Client not known
Try it. It should work.
If still not able to install mysql2 gem on windows7 or not very clear on the steps to follow, then please go through this post which will help you in step-by-step installation -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
And for mysql_api.so error (C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so), copy "libmySQL.dll" file from C:\Program Files\MySQL\MySQL Server 5.1\bin to C:\Ruby192\bin
Path of installation may vary, for details refer to this post - http://rorguide.blogspot.com/2011/03/getting-error-specified-module-could.html.
Hope, this will help you in sorting out your issues.
Start with RailsInstaller.
This is assuming you are running the mysql server locally (local development), and your Ruby is compiled 32-bit. (Check ruby -v. x64 || i386.)
Download the mysql-community-web-installer. In the top right select 32-bit. You pretty much just need the Server. The Workbench is handy also.
The gem command needs a path without spaces, so use subst:
subst X: "C:\Program Files (x86)\MySQL\MySQL Server 5.6"
gem install mysql2 -v=0.3.13 --platform=ruby -- --with-mysql-dir=X:
You will need libmysql.dll in the PATH -- the easiest thing is just to copy it to Ruby's bin directory:
copy "C:\Program Files (x86)\MySQL\MySQL Server 5.6\lib\libmysql.dll" "C:\RailsInstaller\Ruby2.0.0\bin"
NOTES
Don't do this from PowerShell! (DevKit has trouble changing path info in powershell.)
Make sure all libraries are 32-bit, since RailsInstaller's ruby etc. are all compiled 32-bit and need to link to 32-bit libraries.
If you don't want a server locally, just install the C Connector, and do these instructions with that directory and libmysql.dll. Don't mix and match -- make sure the .dll matches the version you compiled the gem against.
From this:
checking for main() in -llibmysql... no
it looks like you haven't installed the MySQL drivers and apps. If so, were they allowed to install into their default locations? At a minimum you'll want the client software if the server is running on a different machine.
install 32 bit mysql connector/c get it at here
copy libmysql.dll from the directory that you install the connector/c to the %installed ruby directory%/bin/
then reinstall the gem again.
I've tried the solution of #Mrk Fldig but it didn't work...
So what solved the problem was:
Downloaded the lastest MySQL Installer for windows 7 32 bits
Installed the gem with the following command: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/"'
One pitfall to be aware of is that I changed the backslashes (\) to normal slashes (/). I've tried the same procedure with backslashes and it didn't work.
The installer already includes the C connectors for MySQL at MySQL Connector C 6.1 6.1.2 directory. Therefore, passing only the --with-mysql-dir parameter without the --with-mysql-lib or --with-mysql-include parameters, makes the gem to look at the same directory for the lib and include directories