So I would like to deploy my rails app on heroku right? Wanna switch from sql3 to postgresql. Should be simple but I keep getting an error when trying to bundle with gem 'pg' in my gemfile. I used homebrew to install postgresql with all its native extensions before trying to bundle. Any ideas? I am on Mac OSX high sierra.
An error occurred while installing pg (1.1.3), and Bundler cannot
continue.
Make sure that gem install pg -v '1.1.3' --source 'https://rubygems.org/'
succeeds before bundling.
That's all I get for the error. Not helpful. I went ahead and uninstalled postrgresql that I installed locally to my machine from their website as well as with homebew. Gonna start from scratch. I haven't done this in years so any help would be appreciated!
I've run into this before where you attempt to install the PG gem, but postgres is not yet installed. Even if you install postgres after that, you'll still run into troubles (this has to do with required libraries not being available or not found). I would recommend uninstalling both, then installing Postgres first, then the PG gem. This is a common gotcha, unfortunately: Installing PG gem on OS X - failure to build native extension Also, I would recommend https://postgresapp.com/ if you continue to have trouble installing PG or having the gem not see your install properly.
After tons of research and trying everything, found an older question on stackoverflow from 2014. If you install postgresql with homebrew like I did, running the command ARCHFLAGS="-arch x86_64" gem install pg will install the gem if bundling or gem install pg don't work. Hope that helps other people who might be stuck like I was
Related
creating a new rails-app (6.0.2) with postgres, on mac, could not get it to run.
Getting this error on app start:
dyld: Symbol not found: _PQresultMemorySize
Referenced from: /Users/dev/.rvm/gems/ruby-2.5.7/gems/pg-1.2.2/lib/pg_ext.bundle
Expected in: /usr/lib/libpq.5.dylib
This seems to be similar to dyld: lazy symbol binding failed: Symbol not found: _PQresultMemorySize - Rails,
but what is to do?
My previous rails apps, on rails v6.0.1, also with the same postgres gem 'pg', '>= 0.18', '< 2.0' are running just fine
What solved my issue was to run a gem uninstall pg and after that do the bundle install
PQresultMemorySize was introduced in postgres 12, since 1.2.0 pg gem checks if it is available during extension build and uses if it is (previously it did not). Since it was available at build, and you probably have not downgraded postgres or libpq right away - it suggests some version conflict.
When installing from homebrew location would be /usr/local/lib/libpq.5.dylib, but you have /usr/lib/libpq.5.dylib
Looks like you have libpq from/and postgres >= 12 installed together with some older version.
You need to find which different postgresses/libpq you have installed and remove one of these to get rid of the conflict.
As a temporary solution - you can set pg version requirement to be exactly the same as your already working one (look into Gemfile.lock of the other app), so that already installed gem will be used (and have more correct extension or just be a version that does not try to access this new feature yet).
Okay, team — here’s what I did.
First, I ran into this issue upgrading from postgresql 12 to 13 via homebrew ... because I am an idiot and didn’t pin 12.
After fixing a bunch of issues, all seemed to be functioning (I could boot my server, I could reinstall the pg gem — all seemed to be good). I had gotten the /usr/lib/libpq.5.dylib error reinstalling pg early on ... but then it magically went away and I thought I was golden. I wasn’t. When I ran my Rails console, I ran a query and ... got the /usr/lib/libpq.5.dylib error.
What did work was:
brew services stop postgresql
brew install libpq
brew link --overwrite libpq --force
brew services start postgresql
For those of you running spring, don’t forget to spring stop (I’m not sure the order really matters, and it’s also possible stopping/restarting postgresql wasn’t necessary, but better safe than sorry).
Rebuilding the gem worked for me:
gem pristine pg
I found the following workaround. It hardcodes the path to the shared library in the pg_ext.bundle:
install_name_tool -change libpq.5.dylib /Library/PostgreSQL/12/lib/libpq.5.12.dylib pg_ext.bundle
next attempt for solution:
$ gem install pg -- --with-pg-config=/Library/PostgreSQL/12/bin/pg_config according to github-pg
Fetching: pg-1.2.2.gem (100%)
Building native extensions with: '--with-pg-config=/Library/PostgreSQL/12/bin/pg_config'
This could take a while...
Successfully installed pg-1.2.2
Parsing documentation for pg-1.2.2
Installing ri documentation for pg-1.2.2
Done installing documentation for pg after 0 seconds
1 gem installed
Gemfile:
gem 'pg', '~> 1.2.2'
same result
pg searches for /usr/lib/libpq.5.dylib, and there is a symlink, but it seems to point to the older version of postgres.
for me, it seems, that it should look for /Library/PostgreSQL/12/lib/libpq.5.dylib
how to teach the gem for looking to that dylib?
I had the same issue and the steps I did to solve this issue was:
gem uninstall pg - you might receive a message saying:
pg is not installed in GEM_HOME, try:
gem uninstall -i /Users/user_name/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0 pg
If that happens, execute the suggested path with sudo:
sudo gem uninstall -i /Users/user_name/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0 pg
if you run bundle install might result in an error saying "An error occurred while installing pg (1.2.3), and Bundler cannot continue.". Install postgres:
brew install postgresql
or
gem install pg -v '1.2.3' --source 'https://rubygems.org/
Proceed with rails command as in my case:
rails db:setup
I tried all methods of here.
But still, the same error occurs.
An error occurred while installing mysql2 (0.5.2), and Bundler cannot
continue.
Make sure that gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
succeeds before bundling.
My spec is:
MacOS Mojave 10.14.1
Ruby 2.5.3p105
Mysql 8.0.12 with Homebrew
Gemfile:
gem "rails"
gem "mysql2", "0.5.2"
Could you kindly tell me a solution?
This is a very good post. I was facing the same issue using mac. What I ended up doing was the following.
I changed the permission for the Gemfile. I used chmod 755 Gemfile.
I used sudo bundle install. This allowed me to install all the gems in the Gemfile.
I did a rake db:create and rails server.
Got things working. Hope it fixes your issue too.
I had the same issue, when setting up a new machine.
Just running
brew install mysql
fixed the failing mysql gem installation for me.
Don't know if this will help, but I had imilar problems on Mac with MySQL twice. First time I just did a complete reinstall, I made sure there were no MySQL files left in the system. I think I followed this guide. The second time I read that it's an issue with symoblic links which I managed to fix with brew prune (I see that it might have been renamed to brew cleanup now - worth to check both).
I started to develop the new RoR web app and faced weird issue.
I wanted to create new app with Postgresql. So I installed the Postgres with brew and MacOS desktop app. And type rails new test-app --database=postgresql.
At this moment, I can't install bundles because there is certain
error.
An error occurred while installing pg (1.0.0), and Bundler cannot
continue.
Make sure that `gem install pg -v '1.0.0' --source
'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
pg
run bundle exec spring binstub --all
Could not find gem 'pg (< 2.0, >= 0.18)' in any of the gem sources
listed in your Gemfile.
Run `bundle install` to install missing gems.
So I can't start new app.
Is this an issue that is occurring because of the mismatch between ruby and postgres version?
And how can I create new app with postgres?
I am currently using Mac OS high Sierra, postgres 10.5, rails 5.2.1
Try to skip running Bundler: rails new test-app --database=postgresql --skip-bundle
Once you've generated your app, you'll still have to troubleshoot why pg ins't installing. The PG gem should install just fine as long as the database is there and your system can build the gem's native extensions, so my first guess is either Postgres isn't installed or it can't be found in your environment.
Either way, this does answer your question. Skip the bundle and voila - Rails will generate a new clean app for you.
I've posted some comments, but i already seen that it seems to be an error when installing postgresql via brew. It's not common, but it happens sometimes.
Here's a quick fix:
brew install libpqxx
Make sure to run also
brew update
and restart your PostgreSQL server via:
brew services restart postgresql
Also make sure to clean up brew:
brew cleanup
If the error is still there, post your Gemfile and your database.yml file as well.
Greetings!
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!
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