Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rails 7 and postgres 15

Kevin Causey asked in Databases

I've got Postgres15 installed via Homebrew, and it's running.
When I build a new Rails 7 app with: "rails new testapppg -d postgres" I can't get it to install pg (1.4.6)

I see errors like "Unable to find PostgreSQL client library.

I'm sure it's related to some type of path issue.

I can build a Rails 7 app with the default sqlite database and it works fine.

Thoughts on how to get Postgres15 configured so I can successfully get the pg gem installed?

Reply

Hey try installing the pg gem: gem install pg
I believe it is necessary for the connection. All the best

Reply

okay, before anyone attempts to answer this, I just found the tutorial here about installing ruby and rails... will follow it.

P.S. I've been coding rails forever and have apps running in 3.x for 10+ years. Now I'm setting up a new M2 machine to do Rails 7 work. Funny how this configuration stuff gets set up and forgotten rather quickly...

Reply

I continue to get errors with asdf loading ruby 3.3. Do I need to scrub off rvm completely? use an older version of ruby?

Reply

run

brew install libpq

does this solve your issue. not sure if it is still needed on the newer versions of macos

Reply

I appear to have libpq 15.2 installed. I'm wondering if I have issues with rvm being installed still on this machine.

Any one have comments as to whether killing rvm is a good thing? I've been developing in Rails since 2.3.8, and have rvm managing versions across multiple projects. Because of this issue, I'm now maintaining an older machine with the intact rvm install (and multiple projects, from Rails 3 to Rails 5).

I want to start of with some Rails 7 stuff, so I have a new M2 machine, just can't see to get postgres happy.

Reply

Okay, starting over.

I've ripped out rvm and old setups on this M2 Mac running 13.2.1
I've ripped out home-brew and reinstalled clean

ruby -v gives (which I believe is the default installed ruby):
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]

which ruby gives:
/usr/bin/ruby

"asdf plugin add ruby" and "asdf plugin add nodejs" appear to work correctly

"asdf install ruby 3.2.2" gives this:
To follow progress, use 'tail -f /var/folders/l1/xdqq3b4s3w1gwvf2mtr861nh0000gn/T/ruby-build.20230417203505.37998.log' or pass --verbose
Downloading openssl-3.1.0.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/aaa925ad9828745c4cad9d9efeb273deca820f2cdcf2c3ac7d7c1212b7c497b4
Installing openssl-3.1.0...
Installed openssl-3.1.0 to /Users/jiblethead/.asdf/installs/ruby/3.2.2

Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew

BUILD FAILED (macOS 13.2.1 using ruby-build 20230330)

Inspect or clean up the working tree at /var/folders/l1/xdqq3b4s3w1gwvf2mtr861nh0000gn/T/ruby-build.20230417203505.37998.ytrKZQ
Results logged to /var/folders/l1/xdqq3b4s3w1gwvf2mtr861nh0000gn/T/ruby-build.20230417203505.37998.log

Last 10 log lines:
linking shared-object socket.bundle
compiling ossl_x509name.c
compiling ossl_x509req.c
compiling ossl_x509revoked.c
compiling ossl_x509store.c
installing default openssl libraries
linking shared-object openssl.bundle
1 warning generated.
linking shared-object ripper.bundle
make: *** [build-ext] Error 2

thoughts? I'm getting tired of it, ready to get coding in Rails 7...

Reply

Here's the deal: If you build a M2 machine with a timemachine backup of a non-Apple Silicon machine, your homebrew will be installed in the wrong place. All subsequent actions get foiled along the way.

Start over by scrubbing the existing Homebrew, then installing it into "/opt/homebrew"

You can then install postgresql@15 with homebrew. Update your path with:

export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"

then:

gem install pg -- --with-pg-config=/opt/homebrew/opt/postgresql@15/bin/pg_config

then the usual steps to create a new app, designating the database "-d postgresql"

running "rake db:create" and "rails server" gives you a clean Rails 7.0.4.3 app using Ruby 3.2.2 on an M2 Mac running Ventura 13.2.1

Hope this saves some time for someone...

Reply

I have issue with postgres 15 and fortunately I find this post. Thank you for your sharing.

Reply

Configure the Rails Application. Create the Application. Add the PostgreSQL username and password. Create the new application databases.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.