You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby on Rails中bundle install执行失败问题求助

Fixing pg (1.1.4) Installation Failure During Bundle Install

Hey there, let's work through this frustrating pg gem issue—this is one of the most common roadblocks when setting up Ruby/Rails apps that use PostgreSQL, so we'll get you past it quickly.

The root problem here is that the pg gem needs PostgreSQL's development libraries to compile successfully. When you run gem install pg -v '1.1.4' directly, it can't find those libraries, hence the error. Here's how to fix it based on your operating system:

For Ubuntu/Debian-based Linux Distros

  • First, install the PostgreSQL development package (this gives the headers and libraries the gem needs):
    sudo apt-get update && sudo apt-get install libpq-dev
    
  • Once that's done, run the gem install command again:
    gem install pg -v '1.1.4'
    
  • If that succeeds, go ahead and run bundle install—it should work now.

For macOS

If you use Homebrew (the most common package manager for macOS):

  1. Install PostgreSQL (this includes the necessary development files):
    brew install postgresql
    
  2. If you already have PostgreSQL installed but still get the error, you might need to explicitly point the gem to your pg_config file. For Intel Macs, this is usually:
    gem install pg -v '1.1.4' -- --with-pg-config=/usr/local/bin/pg_config
    
    For M1/M2 Macs (ARM architecture), the path is often:
    gem install pg -v '1.1.4' -- --with-pg-config=/opt/homebrew/bin/pg_config
    

For Windows

Windows can be trickier, but this should work:

  1. First, install the official PostgreSQL client from the PostgreSQL website (make sure to check the option to add PostgreSQL to your system PATH during installation).
  2. Then run the gem install command, pointing it to your pg_config.exe file (adjust the path to match your PostgreSQL version—this example uses version 13):
    gem install pg -v '1.1.4' -- --with-pg-config="C:\Program Files\PostgreSQL\13\bin\pg_config.exe"
    

Alternatively, you can try installing the pre-compiled Windows gem directly:

gem install pg -v '1.1.4' --platform=x86-mingw32

Quick Troubleshooting Tips

  • If you're using a Ruby version manager like rbenv or rvm, make sure you're in the correct Ruby environment when running these commands.
  • Double-check that the pg_config path you're using actually exists on your system—if not, adjust it to match where PostgreSQL is installed.

Once you get gem install pg -v '1.1.4' to run successfully, bundle install should complete without hitting that error again.

内容的提问来源于stack exchange,提问作者mph85

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:03:33