I am trying to install the pg (PostreSQL) gem for Ruby. I am receiving this error:
postgres/9.2-pgdg/bin/64/pg_config
Using config values from /location/to/install/postgres/9.2-pgdg/bin/64/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... no
Your PostgreSQL is too old. Either install an older version of this gem or upgrade your database.
*** 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.
PostgreSQL version: postgres (PostgreSQL) 9.2.3
OS: solaris 10
I have also tried:
gem install pg -- --with-pgsql-lib=/location/of/install/postgres/9.2-pgdg/lib/64/ --with-pg-config=/location/of/install/postgres/9.2-pgdg/bin/64/pg_config
I have no idea why this error is occurring and I cannot find any useful info on Google.
Any help is greatly appreciated.
Lots of things can go wrong installing a database client, the gem and using it.
I generally install PostgreSQL from source, not from a distro. At that point I know I have all the source and know exactly where things got installed. That's important when installing the gem that talks to the client drivers.
I also rely on installing Ruby from source, either by directly installing it myself, or by using rbenv or RVM if it's on one of my development boxes. Then I also install the pg gem directly, using gem install pg; I've had too many bad experiences using distros when installing languages so I go old-school on it.
I wrote a little script I use on my Mac OS systems, that I've found useful for my CentOS Linux boxes:
#!/bin/sh -x
PATH=/Library/PostgreSQL/9.2/bin:$PATH
gem install pg
I adjust the PATH addition depending on where PostgreSQL got installed, and it seems to do the trick. I've used the longer, more "comprehensive" options also, but this seems to work as well.
The issue is that the installer needs to dig out installation information from the pg_config executable and being able to find pg_config does the trick.
I was going nuts with this until I realized that postgresql-devel and postgresql-libs were from 8.1.23!!!
$ yum list installed postgres*
Loaded plugins: fastestmirror, security
Installed Packages
postgresql-devel.i386 8.1.23-10.el5_10 installed
postgresql-devel.x86_64 8.1.23-10.el5_10 installed
postgresql-libs.i386 8.1.23-10.el5_10 installed
postgresql-libs.x86_64 8.1.23-10.el5_10 installed
---------------
$ sudo yum install postgresql94-libs
$ sudo yum install postgresql94-devel
$ gem install pg
Successfully installed pg-0.18.1
Installing and linking postgresql from homebrew fixed it for me:
brew install postgresql
brew unlink postgresql91
brew link --overwrite postgresql
Related
I'm installing the pg gem on mac osx 12.5 on an M1 macbook pro. Ruby bundler can't find libpq when running gem install pg:
current directory: /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.4/ext
/Users/me/.rbenv/versions/3.1.2/bin/ruby -I /Users/me/.rbenv/versions/3.1.2/lib/ruby/site_ruby/3.1.0 extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... yes
Using config values from /opt/homebrew/opt/libpq/bin/pg_config
checking for whether -Wl,-rpath,/opt/homebrew/opt/libpq/lib is accepted as LDFLAGS... yes
Using libpq from /opt/homebrew/opt/libpq/lib
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*****************************************************************************
Unable to find PostgreSQL client library.
Please install libpq or postgresql client package like so:
brew install libpq
or try again with:
gem install pg -- --with-pg-config=/path/to/pg_config
or set library paths manually with:
gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/
...
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-darwin-21/3.1.0/pg-1.4.4/mkmf.log
Here's what the mkmf.log shows:
conftest.c:16:13: error: conflicting types for 'PQconnectdb'
extern void PQconnectdb();
^
/opt/homebrew/include/postgresql#14/libpq-fe.h:285:16: note: previous declaration is here
extern PGconn *PQconnectdb(const char *conninfo);
^
conftest.c:17:27: error: too few arguments to function call, single argument 'conninfo' was not specified
int t(void) { PQconnectdb(); return 0; }
~~~~~~~~~~~ ^
/opt/homebrew/include/postgresql#14/libpq-fe.h:285:16: note: 'PQconnectdb' declared here
extern PGconn *PQconnectdb(const char *conninfo);
I've installed libpq using homebrew as suggested:
Warning: libpq 15.1 is already installed and up-to-date.
Interestingly, I also tried gem install pg -- --with-pg-include=/opt/homebrew/opt/libpq/include/libpq-fe.h/ but I couldn't find libpq.so poking around the homebrew install.
Any suggestions? Is it possible homebrew's installation of libpq leaves off a needed .so file? Is it suspect that the log file is under a x86_64-darwin-21 directory when I'm running on an M1 mac? Is error: conflicting types for 'PQconnectdb' a hint that I have an incompatible version of libpq with the pg gem?
The pg gem uses pg_config to configure itself. If the gem finds the wrong version of pg_config, it will misconfigure, resulting in the error you mentioned.
On ARM Macs, Homebrew installs itself to a different location (/opt/homebrew) than it did on Intel Macs (/usr/local). However, if you used Apple's Migration Assistant, it's possible to end up with both Homebrew instances, which can confuse things when compiling gems.
First, make sure your Ruby is arm64:
$ ruby -v
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]
It should show arm64 there near the end.
Next, see where pg_config is coming from:
$ which pg_config
/usr/local/bin/pg_config <- Intel version
/opt/homebrew/bin/pg_config <- ARM version
It'll show one of these two (or nothing). We're looking for the second line (ARM).
If nothing, then postgresql is probably not installed (or not found).
If it shows the first, then compilation is finding an Intel copy of pg_config. This was my case, after migrating from an Intel to ARM Mac.
This confusion is partly made possible because pg_config comes from the postgresql package, not libpq. So, you'll need the arm64 version of postgresql installed too.
If you install the unversioned (ie: latest) postgresql, this is hopefully all you need:
$ brew install postgresql
If you always install a specific version (as I do), then you'll also need to 'link' so that pg_config is properly made available.
$ brew install postgresql#15
$ brew link postgresql#15
Using the link command is usually safe as long as this is the only version of postgresql you have installed (within the ARM copy of Homebrew).
Hint 1: When upgrading versions of Postgres in the future, you may need to unlink the old before linking the new.
Hint 2: If you have an Intel version of Postgres still running from the old copy of Homebrew, there is a possibility you'll have to migrate your data between the two or sort out some other conflict. That's out of scope here, so just a heads up.
At this point you will hopefully see the proper pg_config:
$ which pg_config
/opt/homebrew/bin/pg_config <- ARM version
If not, also check your PATH as set by your shell. It's important that /opt/homebrew/bin is before /usr/local/bin.
$ echo $PATH
Fixing it depends on your choice of shell, so I'll skip that here.
That should hopefully do it.
Note that I didn't use --with-pg-config. While using that might allow skipping a step or two above, getting pg_config detecting properly also helps improve odds that other gems will compile properly in the future and not need ongoing workarounds.
After updating to OS X 10.9 Mavericks I tried to start a Rails 3 app, but the connection to the PG database was not working. Checking on PGAdmin III, the database is still there and it works fine.
So I tried to reinstall the pg gem:
gem uninstall pg
gem install pg
But the last command doesn't succeed, and gives the following error:
Building native extensions. This could take a while... ERROR: Error
installing pg:
ERROR: Failed to build gem native extension.
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/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.
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in
`try_do': The compiler failed to generate an executable file.
(RuntimeError) You have to install development tools first. from
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:461:in
try_link0' from
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:476:in
try_link' from extconf.rb:39:in `'
I guess the problem is related to the Xcode developer tools. I updated Xcode to the latest version, but that didn't solve the problem. Do you know how to fix it?
You're right that the problem is related to the Xcode developer tools. It's not a bad idea to make sure you have all the developer tools installed (as opposed to solely installing gcc as mentioned in the previous answer):
Open up Xcode
In the application menu item "Xcode" select Open Developer Tool > More Developer Tools...
This takes you to a site with a bunch of software. Go ahead and download and install "Command Line Tools (OS X Mavericks) for Xcode - Late October 2013".
You will now be able to properly install the gem.
For anyone else coming to this issue off of a fresh install of the Postgres 9.3.0 app on Mac OS X Mavericks (i.e. you're not using homebrew for your Postgres installation) you may notice that even though you can build the pg gem you cannot run rake because of a dylib issue:
rake aborted!
dlopen(/Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: #loader_path/../lib/libpq.5.dylib
Referenced from: /Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle
Reason: image not found - /Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle
Unfortunately this is a problem with the current release version of 9.3.0 of Postgres. Winding back to a previous version will fix it for you:
uninstall the pg gem: gem uninstall pg
delete your 9.3.0 Postgres app by dragging it to the trash and emptying the trash
install version 9.2.2.0 of the Postgres app here: http://postgres-app.s3.amazonaws.com/PostgresApp-9-2-2-0.zip
reinstall the pg gem: gem install pg
*Thanks to the comment by jhiro009 on this thread for pointing me in the right direction on this last Postgres app part of the issue although the 9.2.4.3 version that he mentioned didn't work for me.
Using homebrew fixed this for me:
gem uninstall pg
brew install apple-gcc42
gem install pg
EDIT: I also manually installed "devtools"
xcode-select --install
On OS X Mavericks
sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2
gem uninstall pg; gem install pg;
works with homebrew Postgresql (9.3.1) installation and Apple Command Line Tools installed (pg 0.17.0).
None of the previous solutions worked for me (I just upgraded to Mavericks and updated XCode). Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
None of the solutions worked for me, and I didn't want to use MacPorts. Try and download the Postgres App and put it into the Application directory.
Then, specify the location of newly downloaded pg_config, which resides inside the app:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/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/MacOS/include/'
If you are looking for just a quick fix, add the following to your database.yml file:
host: localhost
I had the exact problem, added that line, and now all is well.
I had luck following this post from the guys at New-Bamboo:
3 Quick Tips for Coding with OS X 10.9 Mavericks
After installing the xcode dev tools, the third step sorted everything out:
brew tap homebrew/versions && brew install apple-gcc42
brew link --force apple-gcc42
ln -nsf $(which gcc-4.2) /usr/bin/gcc-4.2
I had this problem the first time I tried to install pg. Through various trials and errors I found something that worked. Thankfully, my notes also worked when Mavericks broke everything.
Hope this helps:
Do not do any brewing.
download the enterpriseDB one-click installer, mount and run.
If it doesn't work, run it through the command line (unattended mode) and it will change the memory settings. Restart, run again.
Makes a user called postgres with the password you supply. Also installs pgadmin III.
run this in app directory:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-include=/Library/PostgreSQL/9.2/include/ --with-pg-lib=/Library/PostgreSQL/9.2 sudo env ARCHFLAGS='-arch i386' gem install pg/lib/
Open pgadmin3 and create a user and password for rails, then add it to config.
psql [database_name] # to check on your db. Or use pgadmin III
I just upgraded to Rails 3 and had a bit of a mess with MacPorts, gems and databases to sort out. I threw out all the gems and installed them fresh. Everything seems to be OK except for the requirement of the pg gem.
After creating a new Rails 3 project, prepared for PostgreSQL, the server would not start, complaining about the missing pg gem. Doing bundle install, it chugged along for a while and, of course, fails on the pg gem.
Installing pg (0.10.0) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.10.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/source.rb:95:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:55:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/cli.rb:225:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `send'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19
The most common suggestion I have found on forums and blogs is to (re)install the XCode developer tools. They were already there, but I reinstalled them anyway, with no better outcome than the above.
which ruby says /usr/bin/ruby, and ruby -v says ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0], if there's any clue there.
Pointers are welcome. Any missing information that would help figuring this out, I'll gladly and promptly provide!
I downloaded XCode since the DVD version is said to be broken and things went better for a while. bundle install started talking about "archflags" instead, so I did:
sudo env ARCHFLAGS="-arch i386" bundle install
and things seemed to go fine, until starting Rails barfed, saying:
/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle, 9): no suitable image found. Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle
Grappling for anything, I tried bundle install with archflags set to -arch x86_64, but it didn't go well:
*** Your PostgreSQL installation doesn't seem to have an architecture in common with the running ruby interpreter ([] vs. ["x86_64"])
I'll continue anyway, but if it fails, try setting ARCHFLAGS.
[...]
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Is libpq something I now have to supply a path to via some flags? Or am I completely out to lunch?
I encountered this error when I tried to install rails by gem on CentOS 6.3.
After googling a bit, I found a quick fix: installing the ruby-devel package.
sudo yum install ruby-devel
After that, everything worked fine.
Generally the gem bundles for Postgres want to know where pg_config is hiding so they can ask about the Postgres installation.
Use locate pg_config to see if your Mac knows where it's hiding.
I installed a copy of Postgres using mappstack, so my Mac says there's a copy at:
/Applications/mappstack-1.2-3/postgresql/bin/pg_config
and another at:
/Library/PostgreSQL/9.0/bin/pg_config
I don't remember installing the one at /Library/PostgreSQL/9.0, so it might have been preinstalled by Snow Leopard, or I did it when under the influence of too much work, possibly using the Postgres installer from EnterpriseDB.
Once you've found the location of pg_config try adding that directory to the start of your PATH and then rerun the gem install.
Or use:
export SQL_PATH=/Library/PostgreSQL/9.0
gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config
and try installing. If either of those work you're done. Otherwise...
The next thing the installers might want are access to the Postgres headers, so you look in the parent of the bin directories, and see if you can find an include directory.
After that, look in that directory for a lib directory. Once you know those locations you should have all you need to set your environment variables to let the installer complete. You'll need to read the README or INSTALL file of the installer and see what needs to be set up. You'll be configuring:
export include_dir=$SQL_PATH/include/
export lib_dir=$SQL_PATH/lib/
gem install pg -- --with-pgsql-include-dir=$include_dir --with-pgsql-lib-dir=$lib_dir
Hopefully that'll all help. I have Rails 3 and my Postgres running fine, using the mappstack Postgres and the EnterpriseDB versions, so the above info should get you there.
This worked for me on OS X 10.6.6, with PostgreSQL 9.0.1 installed from the source code:
export PATH=/usr/local/psql/bin:$PATH
export ARCHFLAGS='-arch x86_64'
gem install pg
You'll likely need to edit that PATH to match your postgres install location.
I've got postgres 1.9.0 installed via macports. OS X 10.5 PPC
This worked for me:
gem install pg -- --with-pg-lib=/opt/local/lib/postgresql90 --with-pg-include=/opt/local/include/postgresql90
Good luck!
Generally the gem bundles for Postgres want to know where pg_config is hiding . . .
Right - this could be the trick. If you just installed PostgreSQL and added it to your path, and did "bundle install" in an old shell, it won't be able to find pg_config. If that's the case, just get a new shell and try again. Otherwise, follow the steps above to find it and get it seen by bundler.
The macports install for postgresql83 works fine and plays nicely with rails right out of the box - that's another way to do it.
I just spent a good deal of time getting this to work tonight. I saw a similar error to this:
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
I tried different gem install variations:
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.1/bin/ --with-pg-lib=/Library/PostgreSQL/9.1/lib/ --with-pg-include=/Library/PostgreSQL/9.1/include/
But finally what worked for me was:
gem install pg -- --with-pg-dir=/Library/PostgreSQL/9.1/
Also, before that I updated rvm (rvm get head) and reinstalled ruby (rvm --force install 1.9.2). Not sure if this helped or not, but it might be worth trying if you still hit issues
You might want to try going with homebrew for installing postgres (brew install postgres) and Ruby Version Manager for installing and maintaining ruby and ruby gems.
It'll leave your default versions (installed with OSX) untouched and give you more flexibility. For example, you could have different rails apps using rails 2 or 3 with ruby 1.8.7 and 1.9.2 all installed on the same system without problems.
This worked for me:
sudo env ARCHFLAGS="-arch x86_64" gem install pg
All the suggestions here and around the Web were incomplete for me, until I run the following on CentOS 6.6:
wget -c ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/6.3/x86_64/updates/security/kernel-devel-2.6.32-504.1.3.el6.x86_64.rpm && sudo yum install kernel-devel-2.6.32-504.1.3.el6.x86_64.rpm
wget -c ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/6.6/x86_64/updates/security/kernel-headers-2.6.32-504.30.3.el6.x86_64.rpm && sudo yum install kernel-headers-2.6.32-504.30.3.el6.x86_64.rpm
sudo yum groupinstall "Development Tools" "Development Libraries"
sudo yum -y install gcc gcc-c++ git ruby ruby-devel rubygems libvirt-devel mysql-devel postgresql-devel openssl-devel libxml2-devel sqlite-devel libxslt-devel zlib-devel readline-devel tar make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel ruby193-ruby-doc ruby193-ruby-devel ruby193-build
curl -L get.rvm.io | bash -s stable && source $HOME/.rvm/scripts/rvm && rvm requirements
Install Postgres.app:
http://postgresapp.com/
Verify what version was installed:
$ ls /Library/PostgreSQL/
# 9.4
Export the SQL_PATH:
export SQL_PATH=/Library/PostgreSQL/9.4
Install pg:
gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config
I'm trying to start a rails project with a postgresql database but when i try to create the db with the command:
rake db:create
I'm getting the following error message:
rake aborted!
no such file to load -- pg
I'm using mac os X so postgresql is intalled in the /Library folder. I've look around for the pg file but i could not find it and i
If you are using PostgreSQL 9 downloaded from enterprisedb you need to install the pg gem in one of the following way:
If you use rvm use:
env ARCHFLAGS="-arch x86_64" \
gem install pg -- \
--with-pg-include=/Library/PostgreSQL/9.0/include/ \
--with-pg-lib=/Library/PostgreSQL/9.0/lib/
Otherwise use:
sudo env ARCHFLAGS="-arch x86_64" \
gem install pg -- \
--with-pg-include=/Library/PostgreSQL/9.0/include/ \
--with-pg-lib=/Library/PostgreSQL/9.0/lib/
If that doesn't work, we need to know which version of OSX and which version of PostgreSQL.
make sure you have the pg gem installed.
gem install pg
or
include gem pg in your Gemfile and run bundle install if using bundler
All right. Another day, another opportunities.
I found the problem! If you want to install "gem install pg" you need to have the postgres header files on your machine. After I installed Postgres 8.3 via Macports I was also able to install the pg gem. I used this command to install the pg gem:
sudo env ARCHFLAGS='-arch i386' gem install pg
I found the solution in this blog post:
http://flux88.com/blog/installing-postgresql-for-rails-on-mac-os-x/
After reading the post and all the comments, I could resolve the problem.
For me it does not work.
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby1.9 extconf.rb --with-pg-include=/Library/PostgreSQL/8.4/include/ --with-pg-lib=/Library/PostgreSQL/8.4/lib/ --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config
Using config values from /Library/PostgreSQL/8.4/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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.
Ruby + PostgreSQL = Pain in the ASS!
I not wondering why everybody uses mySQL instead of Postgres. With mySQL I never had so much trouble. It is easy to install and easy to use. With Postgres I have always just problems.
After hours of troubleshooting and googeling for shitty postgres ruby driver I am very pissed off. Tomorrow I will take a look to MongoDB and I hope it is less pain than Postgres!
good night!
The problem is you didn't install PostgreSQL properly.
User Brew to install PostgreSQL.
brew update
then install PostgreSQL.
brew install postgresql
Make sure you follow the instructions for PostgreSQL and that the version you installed matches the version you are using.
you can get the version by doing.
psql --version
PostgreSQL is worth learning and much more advanced than MYSQL. Used properly it will improve your Rails application.
This tutorial helped me learn.
The problem is you didn't install PostgreSQL properly.
User Brew to install PostgreSQL.
brew update
then install PostgreSQL.
brew install postgresql
Make sure you follow the instructions for PostgreSQL and that the version you installed matches the version you are using.
you can get the version by doing.
psql --version
PostgreSQL is worth learning and much more advanced than MYSQL. Used properly it will improve your Rails application.
This tutorial helped me learn.
http://railscasts.com/episodes/342-migrating-to-postgresql
I got ruby 1.8.7 (native compiled), rails 2.3.4, OSX 10.6.2 and also sqlite3-ruby.
The error I'm getting when accessing the rails app is
NameError: uninitialized constant SQLite3::Driver::Native::Driver::API
History:
I upgraded to snow leopard by migrating my apps with a FW-cable from my old macbook to the new one. Everything was running perfectly for months, but Yesterday I needed to install watir, which was dependant on rb-appscript, which didn't build due a "wrong architecture" error in libsqlite3.dylib. I figured the build was made on the old machine, so i wanted to rebuild sqlite3-ruby:
$ sudo gem uninstall sqlite3-ruby
$ sudo gem install sqlite3-ruby
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for fdatasync() in -lrt... no
checking for sqlite3.h... yes
checking for sqlite3_open() in -lsqlite3... 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.
It seems like the sqlite3 libs are not working properly. I've tried to install macports sqlite3 (sudo port install sqlite3) and use that instead, but with same result... so i rebuild sqlite3 from scratch.. download->configure->make->make install. After that, the gem now builds perfectly, but doesn't work in rails, giving the error in the top of this article.
I'm not really sure where to go from here because I've tried the following
Rebuild sqlite3 from newest source (http://www.sqlite.org/download.html)
Reinstalled sqlite3-ruby (sudo gem uninstall sqlite3-ruby && sudo gem install sqlite3-ruby)
Used sqlite3 from macports (sudo port install sqlite3 && sudo gem install sqlite3-ruby)
Reinstalled rails (sudo gem install rails sqlite3-ruby ) and updated environment.rb to rails 2.3.5.
No avail, I still get this error:
NameError: uninitialized constant SQLite3::Driver::Native::Driver::AP
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in const_missing'
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/driver/native/driver.rb:76:inopen'
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/database.rb:76:in `initialize'
Btw, I have Xcode installed from the Snow Leopard CD.
What can i do to solve the problem?
My problem was slightly different, and in fact non of the solutions I found on-line worked.
When trying to install sqlite3-ruby after upgrading to Snow Leopard and XCode 4.0 trial, I got the message
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite3-devel'
however sqlite3 was installed, and also re-installing did not help. I already had the troub le before with 64-bit and universal versions, but that I had cleared as well.
In fact, I could work with sqlite3.
So gem install should also tell you something along these lines:
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 for inspection.
So cd to that directory and there look for extconf.rb, mine was in ./ext/sqlite3/extconf.rb
I found that ruby was checking for the the sqlite3 library using
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
So I fired up irb and checked why this didn't work:
require 'mkmf'
find_library 'sqlite3', 'sqlite3_libversion_number'
Well, in fact this works and my ruby find the library.
So why doesn't it work from the setup?
Inspecting extconf.rb closely showed the following line:
sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
When I execute this in irb:
require 'mkmf'
sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
find_library 'sqlite3', 'sqlite3_libversion_number'
I will surprisingly not find the library anymore. In fact I do not understand how this can be, but that's what happens.
So this is the cure:
comment out the line
sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
in extconf.rb
Then from /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 I issued
sudo ruby ./setup.rb
This went through with no problems (I tried before commenting out the sqlite= line, and it did not work)
Restarted the ruby application that had the problems with sqlite.
Works fine.
Hope this will help someone.
Icecream
Thanks for the answers. Here is what i did to solve the problem:
Complete reinstall of ruby1.8.7 to /usr/local, see here: http://hivelogic.com/articles/ruby-rails-leopard
Note: readline wasn't working when recompiling ruby on my mac, so i had to build that too from scratch and make sure to add the --with-readline-dir option to configure:
./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 --prefix=/usr/local --with-readline-dir=/usr/local
Complete reinstall of sqlite3 to /usr/local
Rebuild all gems on the system with sudo gem install XXX, including sqlite3-ruby. This is only necessary with platform specific gems, but i found it to be faster just to install everything in a oneliner:
sudo gem install gem1 gem2 ... gemN --no-ri --no-rdoc
I tried to go with ruby1.9 but everything stopped working due to broken dependencies in gems and plugins, so I wouldn't recommend switching to 1.9 unless you are up for some heavy debugging and know how to restore your old system!
Finally everything is running again!
I found some guidance on this at Don Park's blog at:
http://blog.docuverse.com/2009/09/24/installing-sqlite3-ruby-gem-on-snow-leopard/
His solution points right back to Stack Overflow at the following thread:
Snow Leopard, sqlite3-ruby
The answer about the ln command seems to have solved my problem. Hope it helps you too.
If the gem isn't building it's not because you need necessarily to rebuild sqlite3 from source, but to build the gem you will require the sqlite3 developer libraries.
On most Linux/Unix systems you can install them by doing 'sudo apt-get install sqlite3-dev', however I'm not sure how it works with Macports - but make sure you have that package. You have to make sure they're in your path or pass the dir they're in when you install the gem (see the gem's output for hints as to the options for doing that).
I have sqlite3 running on my Mac just fine, both with 1.8.7 and now my updated 1.9.1 Ruby. You might want to make sure you have the XCode Developer Tools installed as well.
For those on Snow Leopard 64 and having this issue installing this macport fixed the issue for me.
sudo port install rb-sqlite3 +universal