Rails 3.1 - Pushing to Heroku - Errors installing postgres adapter? - postgresql

I just upgraded to Rails 3.1 and the first app i've tried to deploy to Heroku has encountered a problem relating to Postgres adapter. I'm able to push the app to heroku but then when i try to migrate the database i get the following error:
heroku rake db:migrate
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter`
(pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
when I try their suggested install i get:
ERROR: Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository
ERROR: Possible alternatives: activerecord-postgis-adapter, activerecord-jdbcpostgresql-adapter, activerecord-postgresql-cursors, activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter
which already seems weird... so what exact gem should I install to get this thing working if not what they say I should install??
When I try installing gem pg i get:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/jerometufte/.rvm/rubies/ruby-1.9.2-p180/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
...
I'm using SQLite3 currently. Any help greatly appreciated, this is baffling me.

Option 1:
Add pg to your Gemfile but skip trying to install it locally.
$ cat Gemfile
...
group :production do
# gems specifically for Heroku go here
gem "pg"
end
# Skip attempting to install the pg gem
$ bundle install --without production
Option 2 (Debian/Ubuntu):
Add pg to your Gemfile but first install the prerequisites.
$ cat Gemfile
...
group :production do
# gems specifically for Heroku go here
gem "pg"
end
# Install the pg gem's dependencies first
$ sudo apt-get install libpq-dev
# Then install the pg gem along with all the other gems
$ bundle install

You definitely need pg in the Gemfile for Heroku.
About the error you're getting locally: make sure you have postgres installed, run gem install pq -- --with-pg-config=[path to wherever your pg-config binary is], then bundle install.
Alternatively, if your local database is working fine (either because you're using sqlite or postgres-pr), you could put the gem 'pg' line in your Gemfile in a group called production, then bundle install --without production locally.

More up-to-date info: It had something to do with a different version of pg gem locally.
I already had pg in a production group (I run sqllite locally), but Heroku was still puking.
The problem went away for my new Rails 3.1 app when I:
rm Gemfile.lock
touch Gemfile
bundle install
git add .
git commit -am "wiped Gemfile.lock re-ran bundle install"
git push heroku master
worked like a charm when I then ran heroku run rake db:migrate

Related

Rails v6.0.0 push to Heroku fails - Rake & Bundler error msgs

This is my first attempt to push a Rails v6.0.0 app to Heroku. The error msgs are:
Could not detect rake tasks
ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
Activating bundler (2.0.1) failed:
Could not find 'bundler' (2.0.1) required by your /tmp/build_94b6a9e04d812c465a5480f59429532e/Gemfile.lock.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.1`
Checked in 'GEM_PATH=vendor/bundle/ruby/2.5.0', execute `gem env` for more information
To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
I can run 'bundle exec rake -P', no problem.
I have verified that bundler 2.0.1 is installed, no problem.
Suggestions?
A similar bugreport on the bundler repo mentions that bundler 2.0.1 conflicts with heroku. I've copied the following fix instructions from that comment:
gem install bundler -v 2.0.2
bundle update --bundler
commit & push Gemfile.lock changes in your repo
deploy with git push heroku master

pg gem install fails, cannot find libpq-fe.h header

Whenever I run bundle install on my VPS (CentOS Linux release 7.0.1406 (Core)) I get an error when installing the pg gem.
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.
I can install pg standalone with: gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config and the issue is resolved.
So I added a capistrano taskto create a ./bundle/config for the deploy with the build.pg key set with the path to pg_config on my VPS. In the Capistrano config/deploy.rb this is invoked before bundler:install.
desc "Create bundle config"
task :prepare_bundle_config do
on roles(:app) do
within release_path do
execute :bundle, 'config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config --local'
end
end
end
I have the necessary packages installed:
postgresql94-server.x86_64
postgresql94-devel.x86_64
postgresql94-libs.x86_64
libpqxx.x86_64
libpqxx-devel.x86_64
Here are the capistrano* gems I have installed
bundle list | grep capistrano
* capistrano (3.3.5)
* capistrano-bundler (1.1.4)
* capistrano-rails (1.1.2)
* capistrano-rbenv (2.0.3)
* capistrano-stats (1.1.1)
What am I missing here to successfully install pg with bundler? Please leave a comment if you need any additional information and I will update this post.
The postgres binaries are not in the path. Symlink them in to a directory in your path and you should be good: ln -s /usr/pgsql-9.4/bin/p* /usr/local/bin.
Did you build postgres or install it from yum?
Just posting the solution for PostgreSQL 11. If someone lands here.
sudo yum install epel-release
sudo yum install postgresql11-llvmjit
sudo yum install postgresql11-devel postgresql11-libs
Then run
gem install pg -v '1.2.3' -- --with-pg-config=/usr/pgsql-11/bin/pg_config
Thats it
I find that if I compile pgsql with source code, and PATH ENV not configed with pgsql/bin, this happends. You can have a try with this.
Alternatively, if you're using a Mac
brew link postgresql
Or in my case
brew link postgresql#12

Bundle install is throwing error when installing coffee-script-source -v '1.6.3'

I'm using Ruby 2.0.0 and Rails 4 but I'm getting an error with coffee-script when I generate new rails project
Installing coffee-script-source (1.6.3)
Errno::EACCES: Permission denied - /usr/local/rvm/gems/ruby-2.0.0-p247/build_info/coffee-script-source-1.6.3.info
An error occurred while installing coffee-script-source (1.6.3), and Bundler cannot continue.
Make sure that gem install coffee-script-source -v '1.6.3' succeeds before bundling.
I just ran into the same problem. Run
sudo bundle update
inside your new site directory. Ruby will then have no trouble installing whatever packages it needs to.
I has the same issue and came across your post when I googled it. I had to run:
sudo gem install turbolinks -v '1.3.0'
sudo gem install uglifier -v '2.2.1'
sudo gem install multi_json -v '1.8.2'
before I could get the bundle install to complete. However, if you are reading the rails tutorial (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-rubygems), it says not to worry if that stage fails, as the railsgem file is updated and you manually run:
bundle update
bundle install
Hope this is of some help.
do once: sudo rails new demo
and then for other projects just rails new project_name

Deploy to Heroku Error

I am failing to deploy my first app to Heroku. An error occurred while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that **gem install sqlite3 -v '1.3.6**' succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Heroku push rejected, failed to compile Ruby/rails app
After the I modified the Gemfile and installed sqlite3 1.3.6 by using the command:
user$ gem install sqlite3 1.3.6
I got:
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.6
ERROR: Could not find a valid gem ',' (>= 0) in any repository
ERROR: Could not find a valid gem '~>1.3.6' (>= 0) in any repository
1 gem installed
Installing ri documentation for sqlite3-1.3.6...
Installing RDoc documentation for sqlite3-1.3.6.
Just a note, I have deleted the Gemfile.lock but haven't committed the changes. Please help me install the necessary gems to deploy to Heroku

Why is bundler not able to install rake even though rake appears to be present?

I'm having some trouble with rbenv and bundler. When I bundle install on my app, I get an error saying that an error occurred while installing Rake.
I'm thinking this has something to do with rbenv not pointing to the write path for gems -- but I'm not positive.
Why is bundler not able to install rake when rake appears to be present?
Console Output
deploy#telemed-test:/u/apps/telemed_solutions/current$ bundle install
Fetching gem metadata from http://rubygems.org/.......
Fetching gem metadata from http://rubygems.org/..
NoMethodError: private method `open' called for Gem::Package:Class
An error occured while installing rake (0.9.2), and Bundler cannot continue.
Make sure that `gem install rake -v '0.9.2'` succeeds before bundling.
deploy#telemed-test:/u/apps/telemed_solutions/current$
deploy#telemed-test:/u/apps/telemed_solutions/current$ rbenv version
1.9.3-p125 (set by /home/deploy/.rbenv/version)
deploy#telemed-test:/u/apps/telemed_solutions/current$ gem list
*** LOCAL GEMS ***
bigdecimal (1.1.0)
bundler (1.1.3)
io-console (0.3)
json (1.6.6, 1.5.4)
minitest (2.12.1, 2.5.1)
rake (0.9.2)
rdoc (3.12, 3.9.4)
It might be time to upgrade rubygems. Some of the specification files may be calling rubygems methods that don't exist in your version.
Run gem --version to check your current version.
And gem update --system to upgrade to the latest.