19
respostas

Erro ao criar gem - bundle install

Quando chegou na parte do Heroku começou a dar erro. Fiz alteração para o Heroku 18 conforme orientado e atualizei a gem 'pg' com o comando bundle install e mesmo assim o erro persiste.

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle
as root will break this application for all non-root users on this machine.
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.9
Using minitest 5.14.4
Using thread_safe 0.3.6
Using tzinfo 1.2.9
Using activesupport 5.2.4.5
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.5.0
Using racc 1.5.2
Using nokogiri 1.11.2 (x86_64-linux)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.9.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.2.4.5
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 5.2.4.5
Using nio4r 2.5.7
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.3
Using actioncable 5.2.4.5
Using globalid 0.4.2
Using activejob 5.2.4.5
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.4.5
Using activemodel 5.2.4.5
Using arel 9.0.0
Using activerecord 5.2.4.5
Using mimemagic 0.3.5
Using marcel 0.3.3
Using activestorage 5.2.4.5
Using public_suffix 4.0.6
Using addressable 2.7.0
Using io-like 0.3.1
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.4.2
Using bootsnap 1.7.3
Using bundler 2.1.4
Using byebug 11.1.3
Using regexp_parser 2.1.1
Using xpath 3.2.0
Using capybara 3.35.3
Using childprocess 3.0.0
Using chromedriver-helper 2.1.1
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 1.0.0
Using thor 1.1.0
Using railties 5.2.4.5
Using coffee-rails 4.2.2
Using commonjs 0.2.7
Using ffi 1.15.0
Using jbuilder 2.11.2
Using less 2.6.0
Using sprockets 3.7.2
Using tilt 2.0.10
Using less-rails 2.8.0
Using rb-fsevent 0.10.4
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Fetching pg 1.2.3
Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/jhuana/loja/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/ext
/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf20210325-89849-79u4ys.rb 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=/usr/bin/$(RUBY_BASE_NAME)2.7
    --with-pg
    --without-pg
    --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
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

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

  /home/jhuana/loja/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/jhuana/loja/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3 for
inspection.
Results logged to
/home/jhuana/loja/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/gem_make.out

An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before
bundling.

In Gemfile:
  pg
19 respostas

Isso foi no heroku ou na sua máquina? Como está o seu Gemfile?

Isso foi no meu terminal, o Gemfile está assim:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.0'

gem 'rails-i18n', '~> 5.1'
gem 'twitter-bootstrap-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'

# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :production do
  gem 'pg'
end

Depois de alterar eu fui no terminal e rodei "sudo bundle install" e aparece aquele primeiro erro.

Seu sistema é Ubuntu ou Debian based? Tenta instalar a libdev-pq

sudo apt-get install libpq-dev

E tenta dar o bundle install novamente

Sistema Ubuntu, ok vou tentar novamente

Depois de inserir o código acima foi isso que apareceu no terminal:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle
as root will break this application for all non-root users on this machine.
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.9
Using minitest 5.14.4
Using thread_safe 0.3.6
Using tzinfo 1.2.9
Using activesupport 5.2.4.5
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.5.0
Using racc 1.5.2
Using nokogiri 1.11.2 (x86_64-linux)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.9.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.2.4.5
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 5.2.4.5
Using nio4r 2.5.7
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.3
Using actioncable 5.2.4.5
Using globalid 0.4.2
Using activejob 5.2.4.5
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.4.5
Using activemodel 5.2.4.5
Using arel 9.0.0
Using activerecord 5.2.4.5
Using mimemagic 0.3.5
Using marcel 0.3.3
Using activestorage 5.2.4.5
Using public_suffix 4.0.6
Using addressable 2.7.0
Using io-like 0.3.1
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.4.2
Using bootsnap 1.7.3
Using bundler 2.1.4
Using byebug 11.1.3
Using regexp_parser 2.1.1
Using xpath 3.2.0
Using capybara 3.35.3
Using childprocess 3.0.0
Using chromedriver-helper 2.1.1
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 1.0.0
Using thor 1.1.0
Using railties 5.2.4.5
Using coffee-rails 4.2.2
Using commonjs 0.2.7
Using ffi 1.15.0
Using jbuilder 2.11.2
Using less 2.6.0
Using sprockets 3.7.2
Using tilt 2.0.10
Using less-rails 2.8.0
Using rb-fsevent 0.10.4
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Fetching pg 1.2.3
Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/jhuana/loja/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/ext
/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf20210325-90993-8221b7.rb 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=/usr/bin/$(RUBY_BASE_NAME)2.7
    --with-pg
    --without-pg
    --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
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

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

  /home/jhuana/loja/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/jhuana/loja/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3 for
inspection.
Results logged to
/home/jhuana/loja/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/gem_make.out

An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before
bundling.

In Gemfile:
  pg

Quando você roda o bundle sem sudo dá algum problema?

Ele só aparece isso:

Your Ruby version is 3.0.0, but your Gemfile specified 2.7.0

troca no seu Gemfile a linha ruby '2.7.0' para ruby '3.0.0' e tenta rodar o bundle install

Deve ter duas instalações de Ruby diferentes conflitando, mas o bundle nós não costumamos rodar com sudo

Fiz a alteração para ruby 3.0.0 e rodei o bundle install sem o sudo e apareceu essa mensagem:

Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the
sources listed in your Gemfile. If you haven't changed sources, that means the author of
mimemagic (0.3.5) has removed it. You'll need to update your bundle to a version other than
mimemagic (0.3.5) that hasn't been removed in order to install.

Oi, Henrique, esse foi um erro descoberto ontem pelo time do Rails a gem mimemagic é uma dependência interna mas que mudar a licença para GPL, o build de várias empresas está quebrando. Se seu projeto for só pra estudo você pode fazer um bundle update mimemagic e tentar novamente

Coloquei conforme orientado e a mensagem que aparece é essa:

Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
ruby_dep-1.5.0 requires ruby version >= 2.2.5, ~> 2.2, which is incompatible with the current
version, ruby 3.0.0p0

Após realizar essas alterações não consegui mais subir o projeto no servidor. Rodando rails s aparece a seguinte mensagem:

/home/jhuana/.rvm/rubies/ruby-3.0.0/lib/ruby/site_ruby/3.0.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)
    from /home/jhuana/.rvm/rubies/ruby-3.0.0/lib/ruby/site_ruby/3.0.0/rubygems.rb:300:in `activate_bin_path'
    from /home/jhuana/.rvm/gems/ruby-3.0.0/bin/rails:23:in `<main>'
    from /home/jhuana/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `eval'
    from /home/jhuana/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `<main>'

Tenta apagar aquela linha do 'ruby' no Gemfile e rodar um bundle install

Esse último tenta fazer um bundle exec rails s ou bin/rails s

Fiz aqui como você disse e mesmo assim aparece a mensagem:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing
your bundle as root will break this application for all non-root users on this
machine.
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.9
Using minitest 5.14.4
Using thread_safe 0.3.6
Using tzinfo 1.2.9
Using activesupport 5.2.4.5
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.5.0
Using racc 1.5.2
Using nokogiri 1.11.2 (x86_64-linux)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.9.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.2.4.5
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 5.2.4.5
Using nio4r 2.5.7
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.3
Using actioncable 5.2.4.5
Using globalid 0.4.2
Using activejob 5.2.4.5
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.4.5
Using activemodel 5.2.4.5
Using arel 9.0.0
Using activerecord 5.2.4.5
Using mimemagic 0.3.5
Using marcel 0.3.3
Using activestorage 5.2.4.5
Using public_suffix 4.0.6
Using addressable 2.7.0
Using io-like 0.3.1
Using archive-zip 0.12.0
Using bindex 0.8.1
Using msgpack 1.4.2
Using bootsnap 1.7.3
Using bundler 2.1.4
Using byebug 11.1.3
Using regexp_parser 2.1.1
Using xpath 3.2.0
Using capybara 3.35.3
Using childprocess 3.0.0
Using chromedriver-helper 2.1.1
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 1.0.0
Using thor 1.1.0
Using railties 5.2.4.5
Using coffee-rails 4.2.2
Using commonjs 0.2.7
Using ffi 1.15.0
Using jbuilder 2.11.2
Using less 2.6.0
Using sprockets 3.7.2
Using tilt 2.0.10
Using less-rails 2.8.0
Using rb-fsevent 0.10.4
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Fetching pg 1.2.3
Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/jhuana/loja/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/ext
/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf20210325-115721-19g2grg.rb
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=/usr/bin/$(RUBY_BASE_NAME)2.7
    --with-pg
    --without-pg
    --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
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

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

/home/jhuana/loja/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/home/jhuana/loja/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3 for inspection.
Results logged to
/home/jhuana/loja/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/gem_make.out

An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds
before bundling.

In Gemfile:
  pg

Ao executar o bin/rails s:

Could not find gem 'pg' in rubygems repository https://rubygems.org/ or installed locally.
The source does not contain any versions of 'pg'
Run `bundle install` to install missing gems.

Você rodou o bundle install com sudo de novo hehe

A gente não roda bundle install com sudo ele até dá um aviso de não fazer isso:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.

Ah sim, eu tentei várias vezes com o sudo e sem e quando eu coloco sem o sudo aparece essa mensagem:

~/loja$ bundle install
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed in
your Gemfile. If you haven't changed sources, that means the author of mimemagic (0.3.5) has removed it. You'll
need to update your bundle to a version other than mimemagic (0.3.5) that hasn't been removed in order to install.

Tem que fazer aquele bundle update mimemagic que eu tinha falado