Ruby on Rails / PostgreSQL - Library not loaded error when starting server

拜拜、爱过 提交于 2019-12-01 19:14:37
Craig Ringer

The key part of the error is:

Library not loaded: libpq.5.dylib (LoadError)

This suggests that ruby can't find libpq at runtime. To address that you should probably set the DYLD_LIBRARY_PATH environment variable to point to the lib directory of your PostgreSQL install, either globally or in a wrapper script you use to start Rails. See this superuser question for some more info.

The Pg gem can find the library during compilation and installation because the pg_config executable is on the PATH and it uses that to find libpq. It appears that it doesn't store the path for use at runtime so you have to set the runtime dynamic linker up yourself.

A simple wrapper script (in case you don't want to modify your global environment) is something like:

#!/bin/bash
export DYLD_LIBRARY_PATH=/path/to/pg/lib 
exec rails "$@"

The "$@" basically means "pass all arguments to this script through as if they were passed here directly". It preserves quoting correctly and essentially means that the rails command can't tell you didn't run it directly.

A similar stackoverflow answer proposed removing Postgres.app from your PATH, uninstalling the pg gem, and installing the pg gem again.

(I'm not taking the time to check carefully if that applies to this problem, but it solved a problem I had and I want to spread that solution around since I had trouble finding it.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!