I need to install gem pg on snow leopard because I am running rake on rails codebase. I am not using postgres.
This is the error I am getting.
$ sudo gem install pg
Password:
Sorry, try again.
Password:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
looked at various blogs from google search but none of them work.
You may have to specify your CPU architecture. First, run the following to see which architecture you're running on:
(Note: Replace '/usr/bin/ruby' with whatever 'which ruby' returns).
$ lipo -detailed_info /usr/bin/ruby
In there, you should see something about your architecture (look for 'i386' or 'x86_64')
If that doesn't work, try the following:
$ irb
['foo'].pack('p').size
The result will be '8' if Ruby is running as 64-bit, or '4' if it's running in 32-bit.
Then, when you go to install the Postgres gem, specify the appropriate architecture:
$ sudo env ARCHFLAGS="-arch i386" gem install pg
Or,
$ sudo env ARCHFLAGS="-arch x86_64" gem install pg
If you're running Snow Leopard with a 64-bit CPU, then you're probably running the 64-bit version. But still be sure to double-check your architecture, otherwise it probably won't work. ;)
You probably need to actually build and install Postgres before you can build a Ruby adaptor for it.
If you aren't using Postgres, you shouldn't need to install the driver - you only need the driver for the database you are using.
Related
When I run a bundle on a rails project I seem to be getting the following:
Installing pg 0.17.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r
./siteconf20151024-43303-t81fnp.rb extconf.rb checking for
pg_config... yes Using config values from /usr/local/bin/pg_config An
error occurred while installing pg (0.17.1), and Bundler cannot
continue. Make sure that gem install pg -v '0.17.1' succeeds before
bundling.
I have visited the following SO questions:
An error occurred while installing pg (0.17.1), and Bundler cannot continue
Installing pg -v 0.17.1
Installing PG gem on OS X - failure to build native extension.
Additionally to this I've tried executing the following:
gem install pg
env ARCHFLAGS="-arch x86_64" gem install pg
gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.4.5/bin/pg_config
And I keep getting:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
FYI I have rbenv installed too. Also tried a rbenv rehash also and executed the above commands and have had no luck. I've also tried uninstalling and reinstalling Postgres and get the same. To also be on the safe side i've also ran:
brew update
brew uinstall posgresql > brew install postgresql
updated Xcode
Info:
Mac OSx Yosemite 10.10.5
Postgres v9.4.5
rbenv v0.4.0
rbenv global => 2.0.0-p247
I don't know Mac, but I've had this problem on Windows.
--
The issue is here:
Failed to build gem native extension
When you install a gem, many of the advanced ones actually compile / "build" through the extconf.rb file. I've forgotten the significance of this, but it basically allows the gem to run natively on the OS environment you're using.
In short, the error occurs because your OS does not have access to the "developer headers" the gem requires to compile.
The most common instance of this problem is with the mysql2 gem on Windows, but happens for others too.
--
What you need is to download PGSQL on your system before attempting to install the gem.
After installing PGSQL, you may need to reference the developer headers with some "switches", but it does not appear to be the case in this instance:
Installing PG gem on OS X - failure to build native extension
Install Xcode command line tools (Apple Developer site)
brew uninstall postgresql
brew install postgresql
ARCHFLAGS="-arch x86_64" gem install pg
Maybe this won't work? I don't know... I know that in Windows, you have to install the binaries before expecting the gem to work.
Greetings I hope I can help. May I ask how you created your rails project? Did you simply use:
rails new *appname*
If so maybe try creating a new rails app like so:
rails new *appname* -d postgresql
And before you create your database and run migrations/seed, you should go into "config/database.yml" and change the username and password to the postgreSQL user that you've hopefully setup after installing postgreSQL on your machine.
Good Luck!
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
It seems many others have had problems installing the pg gem. None of the solutions posed for others have worked for me.
I have tried to install the pg gem and postgres.app. The pg gem won't install. The first error I get is:
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that gem install pg -v '0.17.0' succeeds before bundling.
The installation advice about pointing my gem install to the config for pg fails with the following error message (which many others on this forum have encountered):
Failed to build native extensions... Results logged to /Users/melanie/.rvm/gems/ruby-1.9.3-p448/gems/pg-0.17.0/ext/gem_make.out
I don't know how to find or access this log file to search for further clues.
I also get an error message (command not found) when I try using the sudo apt-get install command. I've scoured this forum for the last 6 hours, trying each piece of advice to get pg working with my rails project.
I can't find advice about how to change a path, or specifically, what change is required. My which pg_config returns a file source. I've used that with a command to install pg using that config. It fails.
There are so many people that have had trouble with this. Many answers suggest homebrew. I've had to remove that because it threw up other issues.
Same error for me and I didn't experience it until I downloaded OS X 10.9 (Mavericks). Sigh, another OS upgrade headache.
Here's how I fixed it (with homebrew):
Install another build of Xcode Tools (typing brew update in the terminal will prompt you to update the Xcode build tools)
brew update
brew install postgresql
After that gem install pg worked for me.
If you are using Ubuntu try to install following lib file
sudo apt-get install libpq-dev
and then
gem install pg
worked for me.
I am using OS X Mavericks (version 10.9)
and when I run the above I got the following message: If builds of PostgreSQL 9 are failing and you have version 8.x installed.
So I run the following command:
ARCHFLAGS="-arch x86_64" gem install pg
and this worked for me, I hope this helps someone :)
Ok I also had this problem (psql is v 9.3.0 and ruby is v 2.1.2) and the solution that worked for me was setting the bundle config settings first:
bundle config build.pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
This answer finally helped me figure it out: https://stackoverflow.com/a/9235107/3546680
I tried everything for hours but the following finally fixed it (I'm on OS X 10.9.4):
Install Xcode command line tools (Apple Developer site)
brew uninstall postgresql
brew install postgresql
ARCHFLAGS="-arch x86_64" gem install pg
easy step
brew install postgresql
gem install pg -v 'your version'
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.
I believe the “correct” answer would be to first configure PATH correctly for Postgres.app by adding the following to ~/.profile (.zshrc or ~/.zprofile if using ZSH):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
Then open a new tab or window in terminal and install the pg gem with:
ARCHFLAGS="-arch x86_64" gem install pg
Documented here:
https://postgresapp.com/documentation/cli-tools.html
https://postgresapp.com/documentation/configuration-ruby.html
On OSX with Postgres installed in /Applications, I simply run the following command (change 0.20 & 9.4 according to your version)
gem install pg -v '0.20' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
You should have :
Building native extensions with:
'--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config'
This could take a while... Successfully installed pg-0.20.
running brew update and then brew install postgresql worked for me, I was able to run the pg gem file no problem after that.
I spent a day on this and here's how I got it fixed:
I found that global value of build.pg was set to: /opt/local/lib/postgresql91/bin/pg_config
and that was not where postgres was installed.
I fixed it with replacing the value of build.pg to:
bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.4.4/bin/pg_config
which is where my postgresql installation is.
Try:
gem install pg -- --with-pg-config=`which pg_config`
Solved!
I found some lack of library for PostgreSQL on the system.
Only two steps solved it:
brew install postgresql
Then run
gem install pg
For those who are not interested to use brew.
Download PostgreSQL application.
Follow the macOS default instruction to install it.
It is advisable to run PostgreSQl.
Run gem install pg -- --with-pg-config=/path/to/postgress/in/your/applications/folder/`
For example, in my machine it is
/Applications/Postgres.app/Contents/Versions/12/bin/pg_config
i got same problem and i solved
gem update --system 3.0.6
I've installed PostgreSQL using Brew (having previously tried to install using the standalone installer found on the PostgreSQL website), but am receiving the following error message when I try to bundle install:
Errno::EACCES: Permission denied - /Users/xxxxx/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/.gemtest An error occurred while installing pg (0.14.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.
I've found various potential solutions on Stackoverflow, none of which appear to fix the issue.
psql --version returns: 9.2.1
which psql returns: /usr/local/bin/psql
Anyone recognise this error, and/or have any further ideas as to how to fix it?
Failing that, I suppose I could stick with SQLite locally, and use PostgreSQL in the production environment. I assume I would need to manually make the following changes to the database.yml file (I'm about to deploy for the very first time):
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
username: myapp
password:
And, in my gemfile, include the following (note that running bundle install returns the same error, but because I'm assuming there won't be any errors with the PostgreSQL installation on the production server, I think it should still work?):
group :production do
gem 'pg'
end
EDIT: Scratch that, Webrick won't run at all if gem 'pg' is included in the gemfile.
EDIT 2: Also, when I try to run rvmsudo gem install pg, I get this:
ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file
collect2: ld returned 1 exit status
make: *** [pg_ext.bundle] Error 1
** EDIT 3: ** Admitting defeat.
Hi folks,
Firstly, thanks for all your help.
Unfortunately, after two days, I'm going to have to admit defeat.
No matter which method I try, and whether I use the EnterpriseDB version or Homebrew-installed version of PostgreSQL, I simply cannot install the pg gem. I've tried all of the following:
install gem pg
sudo install gem pg
rvmsudo install gem pg
sudo env PATH=/library/PostgreSQL/9.2/bin:$PATH gem install pg (when using the EnterpriseDB installer)
rvmsudo env PATH=/library/PostgreSQL/9.2/bin:$PATH gem install pg (ditto)
rvmsudo env PATH=/library/PostgreSQL/9.2/bin:$PATH ARCHFLAGS="-arch x86_54" gem install
Whichever of the above methods I choose returns the following error:
ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file
Whenever I try to install the gem via a bundle install, I get the following error:
Errno::EACCES: Permission denied - /Users/xxx/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/.gemtest
An error occurred while installing pg (0.14.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.
I can't afford to spend more time on this, so I've bit the bullet and will probably use MySQL instead.
Thanks again,
Graeme
FINAL EDIT - Fixed! See my answer below for how I did it, as it may help others **
YES!!!!
Sorry, but I think I might leap into the air. I think I may have got it to work.
In case anyone else runs into this problem, here's what I did to get the gem to install on Snow Leopard (the process may be different for Lion):
1) Make sure you uninstall any old versions of PostgreSQL - both EnterpriseDB & Homebrew versions. For EnterpriseDB, see this Stackoverflow question/answer, and for Homebrew, simply do brew uninstall postgresql --force.
2) Do a brew install postgresql to get the Homebrew installation.
3) Now, the problem (as Chris Travers pointed out in an earlier comment - Thanks Chris!) appears to be due to OpenSSL. It seems my version (which I guess was Snow Leopard's default version, as I'd never heard of it til today) was an older version, so I had to use Homebrew to install a more up-to-date version (I also used MacPorts to uninstall the old version - not sure it's appropriate having MacPorts and Homebrew installed on the same computer, but...):
Macports: sudo port uninstall openssl
Homebrew: brew install openssl
This should update OpenSSL to the latest 64-bit version (I think?).
4) Following on from another Stackoverflow post, I did the following:
sudo gem install pg -- --with-ldflags='-L/usr/local/Cellar/openssl/0.9.8s'
Success! That seemed to work. I've still to set up a new Rails project to check everything installed OK, but bundle install causes no problems when gem 'pg' is included in my Gemfile, so fingers crossed :-)
Hope this helps others.
It looks to me like you are missing something regarding OpenSSL (whether a header file or otherwise) on your installation. I would double check the installation there. Failing that I would suggest looking into disabling SSL support on this gem however you do that. I looked over the source and it looks like it compiles against libpq which may already be able to link to OpenSSL anyway so that may not be an issue.
Here's what worked for me:
1) installing postgres gem from my console
brew install postgres
sudo env ARCHFLAGS="-arch x86_64" gem install pg
2) Then afterwards in my GemFile so I could continue to use sqlite for dev:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I'm having an issue installing the memcached ruby gem on my Mac Pro machine with OS X Snow Leopard (10.6.4).
Memcache is installed and working fine and for most projects I use the memcache-client gem without issue, but this current project I need to use the memcached gem instead.
Installing the gem with env ARCHFLAGS='-arch x86_64' gem install memcached or just via the normal gem install memcached both give the same error when trying to run the application:
(in /src/mojotech/projectr)
dlopen(/Users/cpjolicoeur/.rvm/gems/ruby-1.8.7-p174/gems/memcached-0.19.7/lib/rlibmemcached.bundle, 9): no suitable image found.
Did find: /Users/cpjolicoeur/.rvm/gems/ruby-1.8.7-p174/gems/memcached-0.19.7/lib/rlibmemcached.bundle: mach-o, but wrong architecture - /Users/cpjolicoeur/.rvm/gems/ruby-1.8.7-p174/gems/memcached-0.19.7/lib/rlibmemcached.bundle
However, running file on the rlibmemcached.bundle gives the correct arch?
cpjolicoeur#~/.rvm/gems/ruby-1.8.7-p174/gems/memcached-0.19.7/lib $ file rlibmemcached.bundle
rlibmemcached.bundle: Mach-O 64-bit bundle x86_64
I'm not sure what the problem is, or how to properly install the memcached gem for my system.
I was seeing the same exact error message on Snow Leopard, Ruby 1.9.1, and the memcached gem. I scoured the net for hours for an answer. Everyone suggested this solution, which did not change the error message:
# Did Not Work
sudo gem uninstall
sudo env ARCHFLAGS='-arch x86_64' gem install memcached
I also tried doing 'rake clean' and re-running extconf.rb on the gem. Same error.
Finally, I went through every past version of the memcached gem until I found one that worked with my system.
# This Worked!
sudo gem uninstall memcached
sudo gem install --version 0.17.1 memcached --no-ri --no-rdoc
Version 0.17.1 of the gem is the only version that works for me. I'm an iPhone developer, so have the latest version of XCode installed, and this might explain why my system is different.
This is a late answer, but hopefully useful for someone who runs across the same issue. (With Ruby 1.9.2 on Snow Leopard.)
Install the Perl modules Pod::Simple, Pod::Man, Pod::Checker (via cpan is easiest).
Download the latest version of libmemcached from http://download.tangent.org/ (was libmemcached-0.44.tar.gz as of this post)
Do the configure/make/install dance by hand in Terminal:
tar -xzvf libmemcached-0.44.tar.gz
cd libmemcached-0.44
./configure
make
sudo make install
After this, sudo gem install memcached worked, and the Rails 3 app in question ran fine.