Ruby-on-rails 无法使用 Mavericks 在我的 Mac 上安装 PG gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19625487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:57:16  来源:igfitidea点击:

Impossible to Install PG gem on my mac with Mavericks

ruby-on-railspostgresqlgemosx-mavericks

提问by Jean

I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:

我正在尝试安装 pg gem 以便再次使用我的 rails 项目。但我收到此错误:

Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension.

/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If

building fails, please try again with --with-pg-config=/path/to/pg_config checking for libpq-fe.h... no Can't find the 'libpq-fe.h header * 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.

Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/

Gem files will remain installed in /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0 for inspection. Results logged to /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out

构建原生扩展。这可能需要一段时间... 错误:安装 pg 时出错:错误:无法构建 gem 本机扩展。

/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If

构建失败,请重试 --with-pg-config=/path/to/pg_config 检查 libpq-fe.h... 否 找不到 'libpq-fe.h 标头 * extconf.rb 失败 *由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。检查 mkmf.log 文件以获取更多详细信息。您可能需要配置选项。

提供的配置选项: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib -- without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --with-pg-config --without-pg -config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include - -with-pg-lib --without-pg-lib=${pg-dir}/

Gem 文件将保留安装在 /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0 以供检查。结果记录到 /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out

I tried everything I found on stackoverflow but I still get this error.

我尝试了在 stackoverflow 上找到的所有内容,但仍然出现此错误。

If I try to install postgresql using brew I get the following waring:

如果我尝试使用 brew 安装 postgresql,我会收到以下警告:

Warning: postgresql-9.2.4 already installed, it's just not linked

警告:postgresql-9.2.4 已经安装,只是没有链接

If I try to link

如果我尝试链接

brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4... Warning: Could not link postgresql. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7 /usr/local/share/man/man7 is not writable. You should change its permissions.

brew 链接 postgresql 链接 /usr/local/Cellar/postgresql/9.2.4... 警告:无法链接 postgresql。正在取消关联...

错误:无法符号链接文件:/usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7 /usr/local/share/man/man7 不可写。您应该更改其权限。

Help Please

请帮忙

NOTE: I already installed the command line tools for mavericks.

注意:我已经为小牛安装了命令行工具。



If I uninstall using homebrew and try to install again, I get this error:

如果我使用自制软件卸载并尝试再次安装,则会出现此错误:

==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2

################################################################## 100.0%

==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c ==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p ==> make install-world ==> Caveats

Build Notes

If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510

Create/Upgrade a Database

If this is your first install, create a database with: initdb /usr/local/var/postgres -E utf8

To migrate existing data from a previous major version (pre-9.2) of PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html

Loading Extensions

By default, Homebrew builds all available Contrib extensions. To see a list of all available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;

To load any of the extension names, navigate to the desired database and run: CREATE EXTENSION [extension name];

For instance, to load the tablefunc extension in the current database, run: CREATE EXTENSION tablefunc;

For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.2/static/sql-createextension.htmlFor more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html

Other

Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPCWhen installing the postgres gem, including ARCHFLAGS is recommended: ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To have launchd start postgresql at login: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't want/need launchctl, you can just run: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link postgresql. Unlinking... Error: The brew linkstep did not complete successfully The formula built, but is not symlinked into /usr/local You can try again using `brew link postgresql' ==> Summary /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes

==> 下载http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2

############################################### ################ 100.0%

==> 打补丁 打补丁文件 src/pl/plpython/Makefile 打补丁文件 contrib/uuid-ossp/uuid-ossp.c ==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 -- datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p ==> make install-world ==> 注意事项

构建说明

如果 PostgreSQL 9 的构建失败并且您安装了 8.x 版,您可能需要先删除以前的版本。请参阅:https:
//github.com/mxcl/homebrew/issues/issue/2510

创建/升级数据库

如果这是您的第一次安装,请使用以下命令创建数据库: initdb /usr/local/var/postgres -E utf8

要从 PostgreSQL 的先前主要版本(9.2 之前)迁移现有数据,请参阅:http:
//www.postgresql.org/docs/9.2/static/upgrading.html

加载扩展

默认情况下,Homebrew 构建所有可用的 Contrib 扩展。要查看所有可用扩展的列表,请从 psql 命令行运行:
SELECT * FROM pg_available_extensions;

要加载任何扩展名,导航到所需的数据库并运行:CREATE EXTENSION [extension name];

例如,要在当前数据库中加载 tablefunc 扩展,请运行: CREATE EXTENSION tablefunc;

有关 CREATE EXTENSION 命令的更多信息,请参阅:http:
//www.postgresql.org/docs/9.2/static/sql-createextension.html有关扩展的更多信息,请参阅:http:
//www.postgresql.org/ docs/9.2/static/contrib.html

其他

某些机器可能需要配置共享内存:
http: //www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC安装 postgres gem 时,建议包括 ARCHFLAGS:ARCHFLAGS="-arch x86_64"宝石安装 pg

要在没有 sudo 的情况下安装 gem,请参阅 Homebrew wiki。

要在登录时启动 postgresql: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 然后现在加载 postgresql:launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 或,如果你不想要/不需要launchctl,你可以运行:pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 警告:无法链接postgresql。Unlinking... 错误:该brew link步骤未成功完成 公式已构建,但未符号链接到 /usr/local 您可以再次尝试使用 `brew link postgresql' ==> 摘要 /usr/local/Cellar/postgresql/9.2。 4:2831个文件,38M,4.9分钟建好



SOLUTION:

解决方案:

I execute this command in order to change the permission of the folder:

我执行此命令以更改文件夹的权限:

sudo chown jeanosorio /usr/local/share/man/man7

须藤 chown jeanosorio /usr/local/share/man/man7

Then

然后

brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421 symlinks created

brew 链接 postgresql 链接 /usr/local/Cellar/postgresql/9.3.1 ... 421 符号链接已创建

And finally:

最后:

sudo ARCHFLAGS="-arch x86_64" gem install pg

Fetching: pg-0.17.0.gem (100%) Building native extensions. This could take a while... Successfully installed pg-0.17.0

sudo ARCHFLAGS="-arch x86_64" gem install pg

获取:pg-0.17.0.gem (100%) 构建原生扩展。这可能需要一段时间... 成功安装 pg-0.17.0

回答by Yuri

If you want to avoid using MacPorts, you can download the Postgres Appand place it into the Application directory.

如果想避免使用MacPorts,可以下载Postgres App,放到Application目录下。

Then, specify the location of newly downloaded pg_config:

然后,指定新下载的位置pg_config

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

If you run in to missing headers problem, try specifying the includedirectory of the app:

如果您遇到缺少标题的问题,请尝试指定include应用程序的目录:

gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'

回答by Ayush Goel

Use brew to get postgresql

使用 brew 获取 postgresql

brew install postgresql

Check you have pg_config in the installed brew. I found mine in

检查已安装的 brew 中是否有 pg_config。我在

/usr/local/Cellar/postgresql/9.3.3/bin/pg_config

/usr/local/Cellar/postgresql/9.3.3/bin/pg_config

Check via :

检查通过:

$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
> /usr/local/Cellar/postgresql/9.3.3/bin/pg_config

Once done, install the pggem with

完成后,安装pggem

env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config

回答by iceui2

I wasn't able to install postgres via MacPorts. Instead, I installed Postgress.app. and called

我无法通过 MacPorts 安装 postgres。相反,我安装了Postgress.app。并叫

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config

Note: in newer versions (in 9.3 at least) the path is actually:/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

注意:在较新的版本中(至少在 9.3 中),路径实际上是:/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

回答by 2potatocakes

Here's another alternative in case you want to use the postgresql installer directly. There's a couple of hoops you gotta jump through to begin with after updating to mavericks. Here's what I did:

如果您想直接使用 postgresql 安装程序,这是另一种选择。升级到小牛队后,您必须先跳过几个环节。这是我所做的:

Install the xcode command line tools first:

首先安装xcode命令行工具:

xcode-select --install

Download and install the latest version of PostgreSQL (9.3.1), in my case I just used the graphical installer. Here's the link to the downloads page:

下载并安装最新版本的 PostgreSQL (9.3.1),就我而言,我只使用了图形安装程序。这是下载页面的链接:

http://www.enterprisedb.com/products-services-training/pgdownload#osx

Just choose all of the defaults it gives you. It my case it installed postgres to the following directory, if you installed it to a different directory, just remember the path you chose, because you'll need it shortly.

只需选择它为您提供的所有默认值。在我的情况下,它将 postgres 安装到以下目录,如果您将其安装到其他目​​录,请记住您选择的路径,因为您很快就会需要它。

/Library/PostgreSQL/9.3

If you now try and install the latest pg gem (0.17.0) you'll need to pass a couple of options on the command line. This is what I used:

如果您现在尝试安装最新的 pg gem (0.17.0),您需要在命令行上传递几个选项。这是我使用的:

ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

If you installed postgres to a different location then you'll need to fix up the path to the pg_config file.

如果您将 postgres 安装到其他位置,则需要修复 pg_config 文件的路径。

If it complains of a missing 'libpq.5.dylib' file while trying install the pg gem you'll need to create a symlink pointing to the actual location of this file. Postgres is looking for it in your /usr/local/lib/ directory so create a symlink in there and redirect it to its actual location. In my case I had to run:

如果它在尝试安装 pg gem 时抱怨缺少“libpq.5.dylib”文件,则您需要创建一个指向该文件实际位置的符号链接。Postgres 正在您的 /usr/local/lib/ 目录中寻找它,因此在那里创建一个符号链接并将其重定向到其实际位置。就我而言,我必须运行:

sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib

Once you've done that, retry installing the gem again and hopefully it will work for you the same way it did for me.

完成后,再次尝试安装 gem,希望它对你有用,就像对我一样。

回答by user2373148

If you have homebrew, just type:

如果你有自制软件,只需输入:

$ brew install postgresql

$ brew 安装 postgresql

回答by dinigo

For me, on Yosemite, I didn't need to specify pg_configpath. The following got it done.

对我来说,在优胜美地,我不需要指定pg_config路径。下面就搞定了。

brew install postgresql
sudo env ARCHFLAGS="-arch x86_64" gem install pg

Seems like architecture flag is the key.

似乎架构标志是关键。

回答by Gi0

In my case (i needed PG 0.16.0 on Mavericks), i installed postgresql via MacPorts

就我而言(我在 Mavericks 上需要 PG 0.16.0),我通过MacPorts安装了 postgresql

sudo port install postgresql90

and then

进而

gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config

For the latest version you need to deduct -v '0.16.0'

对于最新版本,您需要扣除 -v '0.16.0'

gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config

If you have Homebrew installed do not install MacPorts before you read about their coexistense

如果您安装了 Homebrew,请在阅读它们的共存之前不要安装 MacPorts

回答by Bruno Buccolo

Place the missing --with-pg-configin Bundler's config file: /Users/<your_user>/.bundle/configto make your life easier.

将缺少的内容--with-pg-config放在 Bundler 的配置文件中:/Users/<your_user>/.bundle/config让您的生活更轻松。

---
BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs

Then run bundle installagain.

然后bundle install再次运行。

回答by meck373

That works for me! (Postgres 93, mac ox 10.9.1)1. download @ http://postgresapp.com/and than

这对我行得通!(Postgres 93,mac ox 10.9.1)1。下载@ http://postgresapp.com/然后

gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

回答by Neeraj Gupta

I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64"gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

我被困在我的捆绑安装上 3 天。尝试了一切,比如添加env ARCHFLAGS="-arch x86_64"gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'

我能够看到在这个命令之后安装了 pg gem,但它仍然没有从 bundle install 安装,这很痛苦,因为我不知道除了 gem 'pg' 之外在 Gemfile 中写什么

The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_configand by default the Gemfile bundle install looks in /usr/local/bin/pg_config

最终对我有用的是发现我的 pg_config 在/Library/PostgreSQL/9.3/bin/pg_config 中,默认情况下 Gemfile 包安装在/usr/local/bin/pg_config 中

I just ran the following command and magic happened. bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

我刚刚运行了以下命令,奇迹发生了。 捆绑配置 build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config