Bundle install = Gem::Ext::BuildError: ERROR: Failed to build gem native extension

bundle install komutunu calistirdigimda cikan hata, nasil duzeltebilirim ?:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

devami boyle:

 current directory: /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9/ext
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/bin/ruby extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... yes
Using config values from /usr/bin/pg_config
Using libpq from /usr/lib/x86_64-linux-gnu
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*****************************************************************************

Unable to find PostgreSQL client library.

Please install libpq or postgresql client package like so:
  sudo apt install libpq-dev
  sudo yum install postgresql-devel
  sudo zypper in postgresql-devel
  sudo pacman -S postgresql-libs

or try again with:
  gem install pg -- --with-pg-config=/path/to/pg_config

or set library paths manually with:
  gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/

*** 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=${opt-dir}/include
        --without-opt-include
        --with-opt-lib=${opt-dir}/lib
        --without-opt-lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/kuaza/.local/share/mise/installs/ruby/3.4.4/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-gvl-unlock
        --disable-gvl-unlock
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include=${pg-dir}/include
        --without-pg-include
        --with-pg-lib=${pg-dir}/lib
        --without-pg-lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/extensions/x86_64-linux/3.4.0/pg-1.5.9/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9 for inspection.
Results logged to /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/extensions/x86_64-linux/3.4.0/pg-1.5.9/gem_make.out

  /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/ext/builder.rb:125:in 'Gem::Ext::Builder.run'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/ext/ext_conf_builder.rb:30:in
'Gem::Ext::ExtConfBuilder.build'
  /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/ext/builder.rb:206:in 'Gem::Ext::Builder#build_extension'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/ext/builder.rb:240:in 'block in
Gem::Ext::Builder#build_extensions'
  /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/ext/builder.rb:237:in 'Array#each'
  /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/ext/builder.rb:237:in 'Gem::Ext::Builder#build_extensions'
  /home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/site_ruby/3.4.0/rubygems/installer.rb:844:in 'Gem::Installer#build_extensions'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/rubygems_gem_installer.rb:111:in
'Bundler::RubyGemsGemInstaller#build_extensions'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/rubygems_gem_installer.rb:30:in
'Bundler::RubyGemsGemInstaller#install'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/source/rubygems.rb:220:in
'Bundler::Source::Rubygems#install'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/installer/gem_installer.rb:55:in
'Bundler::GemInstaller#install'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/installer/gem_installer.rb:17:in
'Bundler::GemInstaller#install_from_spec'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/installer/parallel_installer.rb:133:in
'Bundler::ParallelInstaller#do_install'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/installer/parallel_installer.rb:124:in
'block in Bundler::ParallelInstaller#worker_pool'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/worker.rb:62:in
'Bundler::Worker#apply_func'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/worker.rb:57:in 'block in
Bundler::Worker#process_queue'
  <internal:kernel>:168:in 'Kernel#loop'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/worker.rb:54:in
'Bundler::Worker#process_queue'
/home/kuaza/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.4/lib/bundler/worker.rb:90:in 'block (2 levels) in
Bundler::Worker#create_threads'

An error occurred while installing pg (1.5.9), and Bundler cannot continue.

In Gemfile:
  pg

Selçuk, paylaştığın hata detayında asıl problem yeterli PostgreSQL client kütüphanesinin ve başlık dosyalarının sisteminde bulunmaması gibi görünüyor. Özellikle şu satır önemli:

checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
...
Unable to find PostgreSQL client library.

Çözüm için yapman gerekenler:

  1. Gerekli paketi kur
    Kullandığın dağıtıma göre aşağıdaki komuttan birini çalıştırman gerekiyor. Debian/Ubuntu tabanlı bir sistemdeysen:

    sudo apt-get install libpq-dev
    

    Fedora/CentOS/RHEL için:

    sudo yum install postgresql-devel
    

    openSUSE için:

    sudo zypper in postgresql-devel
    

    Arch Linux için:

    sudo pacman -S postgresql-libs
    
  2. Kurulumdan sonra tekrar dene
    Paket yüklendikten sonra tekrar bundle install komutunu çalıştır.

  3. Sorun devam ederse
    Eğer yine hata alırsan, aşağıdaki komutla pg gem’i doğrudan yüklemeyi de deneyebilirsin:

    gem install pg -- --with-pg-config=/usr/bin/pg_config
    

    (pg_config dosyasının yolu farklıysa, uygun path’i ver.)

  4. Ek not
    Sisteminde birden fazla Ruby ortamı (örneğin rbenv, rvm, mise) ve/veya farklı kullanıcı izinleri varsa, başlık dosyalarının doğru ortamda görünür olmasına dikkat et. Özellikle Docker veya benzeri izolasyon kullanıyorsan, ilgili image içerisinde de libpq-dev yüklü olmalı.

  5. Son olarak
    Eğer hala yürümezse, /home/kuaza/.../mkmf.log dosyasındaki en güncel hata mesajlarını burada paylaşabilirsin.

Ekstra soruların veya takıldığın başka bir aşama olursa detay yazabilirsin. Kolay gelsin!

  1. adima kadar yaptim bu cikti, sonuc basarili mi?:
bundle install
Fetching gem metadata from https://rubygems.org/........
Installing pg 1.5.9 with native extensions
Bundle complete! 143 Gemfile dependencies, 259 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
5 installed gems you directly depend on are looking for funding.
  Run `bundle fund` for details

Evet, çıktıya göre kurulum başarıyla tamamlanmış görünüyor:

Bundle complete! ... gems now installed.
Installing pg 1.5.9 with native extensions
...

Artık pg gem’i ve diğer bağımlılıklar sisteme kuruldu. Yeni bir hata mesajı veya eksik uyarısı yok, yani PostgreSQL bağlantılı Ruby uygulaman çalışmaya hazır olmalı.

Şu anda başka bir hata almıyorsan veya uygulaman başlatılabiliyorsa işlem tamamdır. İyi çalışmalar!