When I try to build my app on Heroku, it fails because the Ruby version I purportedly am using is not supported by Heroku. My app has no problem building/deploying locally. Here is full message log:
-----> Ruby app detected
-----> Compiling Ruby/Rails
Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.8.tgz -s -o - | tar zxf - ' failed on attempt 1 of 3.
Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.8.tgz -s -o - | tar zxf - ' failed on attempt 2 of 3.
!
! An error occurred while installing ruby-2.3.8
!
! This version of Ruby is not available on Heroku-18. The minimum supported version
! of Ruby on the Heroku-18 stack can found at:
!
! https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
!
! Push rejected, failed to compile Ruby app.
! Push failed
However, in my Gemfile and Gemfile.lock, I am NOT using ruby-2.3.8. That is why I am very confused. I have links to my Gemfile gist and Gemfile.lock gist.
Things I have tried on Heroku:
Running bundle install.
This. Did not resolve issue, my Gemfile, Gemfile.lock, and local Ruby is ALL 2.6.3.
Making sure Gemfile and Gemfile.lock are the most recent ones in my Github.
Running gem install bundler -v 1.17.3 but it gives me ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.5.0 directory
EDIT:
It appears after running heroku run ruby -v, that my Ruby version is actually ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
It's possible that the "blessed" version of bundler hasn't been updated yet to 2.0.2, and only 2.0.1 is supported on the official ruby buildpack.
To test this out, you can edit your Gemfile.lock manually and change:
BUNDLED WITH
2.0.2
to 2.0.1
It will be overridden every time you bundle though, so if that is the fix, you might want to downgrade bundler for the time being.
On Heroku you cannot configure the version of bundler directly -> https://devcenter.heroku.com/articles/bundler-version#app-not-using-the-currently-supported-bundler-version
I am guessing you are using the heroku buildpack, if not you will want to set that up.
You can switch to a supported buildpack with:
heroku buildpacks:set heroku/ruby
I believe I have had issues where heroku wasn't updating, try the top 2 answers here:
Heroku is not updating my code?
One of the pitfalls of heroku is you will need to work with in their construct. I would make sure you are using whatever version of bundler and ruby they want locally prior to deployment and after deployment confirm by sshing on to the heroku box to confirm it is the same version.
Sidenote, using the ruby keyword will only work for certain versions of bundler
https://devcenter.heroku.com/articles/ruby-versions#selecting-a-version-of-ruby
I usually set my ruby version in a .ruby-version file in the root of the project.
Related
I am trying to push something to Heroku by this command
git push heroku master
and it gave me this error :
Your Ruby version is 2.6.4, but your Gemfile specified 2.6.3
Failed to install gems via Bundler.
Detected a mismatch between your Ruby version installed and
Ruby version specified in Gemfile or Gemfile.lock.
You can correct this by running:
$ bundle update --ruby
$ git add Gemfile.lock
$ git commit -m "update ruby version"
I changed my Gemfile from 2.6.3 to 2.6.4, ofcourse update the gemfile by bundle install command, but I failed. I also tried to run all the command they gave me, but nothing changed, I still have the error. When I check, the Gemfile still 2.6.4, but the error still told me that your Gemfile specified 2.6.3.
Could you still give me some ideas for me? Thank you very much.
I was breaking my head.
$ ruby -v
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]
$ bundle 2.2.17 platform --ruby
ruby 2.7.4p191
$ cat .ruby-version
2.7.4p191
$ cat Gemfile.lock | grep -A 2 RUBY
RUBY VERSION
ruby 2.7.4p191
$ cat Gemfile | grep -A 2 "ruby '2.7.4'"
ruby '2.7.4', :patchlevel => '191'
They all point to the same ruby version: 2.7.4p191. Reading the Heroku log output, I edited the line in the bin/bundle file where it says
#!/usr/bin/env ruby2.7
to
#!/usr/bin/env ruby
That's all.
This error message is a well known error message. (see https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html for example.) Although I'm getting it with a new Elastic Beanstalk application with Ruby 2.6.1, and bundler 2.0.1. The error is:
/opt/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0/rubygems.rb:308:in `activate_bin_path'
from /opt/rubies/ruby-2.6.1/bin/bundle:23:in `<main>' (ElasticBeanstalk::ExternalInvocationError)
I've tried putting the following file: 01_install_bundler.config in the .ebextensions folder:
container_commands:
01_install_bundler:
command: "gem install bundler —-version 2.0.1"
Although this never gets run because if I look at the above error, I can see that it is happening during this point in the deploy process:
.../AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
(i.e. during the bundle install command of an AppDeployPreHook script). See https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html for reference of PlatformHooks.
I'm pretty sure that if I can ensure that the version of bundler being used is at least version 2.0.0, then there won't be a problem. Although I don't know how I can specify that easily. At the moment I'm ssh'ing to the server to /opt/elasticbeanstalk/hooks/appdeploy/pre/ to edit and fiddle with the scripts. Although I obviously need an automated, repeatable way of doing it.
It's frustrating that ruby 2.6.1 isn't choosing bundler version 2.0.0 by default. Any ideas?
==============================
Update:
If I edit the file /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh
if [ -f Gemfile ]; then
echo "running 'bundle install' with Gemfile:"
cat Gemfile
+++ gem install bundler +++
if [ -d $EB_APP_STAGING_DIR/vendor/cache ]; then
bundle install --local
else
bundle install
fi
else
echo "no Gemfile found! Skipping bundle install stage!"
fi
and add the gem install bundler (without the pluses), then this fixes the problem because it installs the latest bundler, which is 2.0.1. For those who want to know the hack, the commands were:
eb ssh
sudo -i
cd /opt/elasticbeanstalk/hooks/appdeploy/pre
vim 10_bundle_install.sh
The problem with this solution is that it feels like a bit of a hack because it doesn't use .ebextensions. Is there a more proper way of fixing this?
So here's the programmatic solution to the above problem. Create the below file under .ebextensions/gem_install_bundler.config:
files:
# Runs before `./10_bundle_install.sh`:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/09_gem_install_bundler.sh" :
mode: "000775"
owner: root
group: users
content: |
#!/usr/bin/env bash
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
# Source the application's ruby, i.e. 2.6. Otherwise it will be 2.3, which will give this error: `bundler requires Ruby version >= 2.3.0`
. $EB_SCRIPT_DIR/use-app-ruby.sh
cd $EB_APP_STAGING_DIR
echo "Installing compatible bundler"
gem install bundler -v 2.0.1
Then when you next eb deploy, the bundler will have been updated to version 2.0.1, and you won't get the above error again.
More information in the docs here:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html
and here:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-files
Last note: Ensure that you either commit these changes before running eb deploy, or stage them and run eb deploy --staged. See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html. I learned this the hard way!
Here is a version that can be used on the new Amazon Linux 2 platform versions as the old /opt/elasticbeanstalk/hooks/ folders are entirely discontinued. It parses the bundler version out of the Gemfile.lock
This script would go into .platform/hooks/prebuild/01_install_app_bundler.sh and it needs to be marked as executable or it will fail with a permissions issue (chmod +x 01_install_app_bundler.sh)
#!/usr/bin/env bash
# Load environment data
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config platformconfig -k AppStagingDir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config platformconfig -k AppUser)
EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config platformconfig -k AppDeployDir)
# Set up correct environment
export $(cat /opt/elasticbeanstalk/deployment/env | xargs)
BUNLDER_VER_TO_INSTALL=$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n1 | tr -d ' ')
echo "Installing bundler $BUNLDER_VER_TO_INSTALL"
gem install bundler -v $BUNLDER_VER_TO_INSTALL
I left some unused EB_ variables in there just to show how they can be determined on the updated platform.
I only just saw this post after I had found an alternative (perhaps easier) solution: backgrading bundler to 1.17.3 (gem unistall bundler followed up with gem install bundler -v 1.17.3)
You need the correct version of the bundler that the lockfile was generated with. To find out that version, use the following command
$ cat Gemfile.lock | grep -A 1 "BUNDLED WITH"
BUNDLED WITH
1.17.3
I'm trying to migrate my heroku app to Cedar 14 (following this: https://devcenter.heroku.com/articles/cedar-14-migration)
My problem is that heroku thinks I'm using ruby v 2.1.1 (where my machine is on ruby 2.2.2. This is confirmed by ruby -v and which ruby (both return 2.2.2).
However, when I try:
heroku run ruby -v
The return is:
Running `ruby -v` attached to terminal... up, run.4550
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
I can't figure out how to get heroku to recognise that ruby 2.2.2 is what should be used. It's in my gem file, I set it as the default and its in my bash profile at the top of the list.
As a result, I can't push the migration on heroku because it's not supported by older versions of ruby. I get this error:
Only the most recent version of Ruby 2.1 is supported on Cedar-14
remote: ! Command: 'set -o pipefail; curl --fail --retry 3 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/cedar-14/ruby-2.1.1.tgz -s -o - | tar zxf - ' failed unexpectedly:
Does anyone know how to get heroku to recognise ruby v 2.2.2?
Thank you
You have the add the desired Ruby version to your Gemfile like this:
source 'https://rubygems.org'
ruby '2.2.3'
gem 'rails', '~> 4.2.4'
# ...
There is an article about Specifying a Ruby Version in their devcenter.
I had updated my ruby version in my gem file, and updated my path and set the default. I had installed all my gems, but I didn't update my gems. Gem update solved this for me.
I'm following this tutorial, but it fails when I try to push to Heroku. It seems "sqlite3.h" is missing. I'm new to development so I'm not sure what information will help people diagnose the problem, so here's everything :). I'm running on Mac OS X 10.7 Lion. Here are the versions of everything I'm working with:
Amits-MacBook-Air-2:demo_app amitgupta$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
Amits-MacBook-Air-2:demo_app amitgupta$ rails -v
Rails 3.2.3
Amits-MacBook-Air-2:demo_app amitgupta$ sqlite3 -version
3.7.11 2012-03-20 11:35:50 00bb9c9ce4f465e6ac321ced2a9d0062dc364669
Amits-MacBook-Air-2:demo_app amitgupta$ heroku -v
2.25.0
Amits-MacBook-Air-2:demo_app amitgupta$ port -v
MacPorts 2.0.4
Entering interactive mode... ("help" for help, "quit" to quit)
[RailsApps/demo_app] > quit
Goodbye
When I try to push to Heroku:
Amits-MacBook-Air-2:demo_app amitgupta$ heroku create --stack cedar
Creating floating-stream-8009... done, stack is cedar
http://floating-stream-8009.herokuapp.com/ | git#heroku.com:floating-stream-8009.git
Amits-MacBook-Air-2:demo_app amitgupta$ git push heroku master
Here's what I get:
Counting objects: 119, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (104/104), done.
Writing objects: 100% (119/119), 33.74 KiB, done.
Total 119 (delta 17), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.2
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Fetching gem metadata from https://rubygems.org/.......
Installing rake (0.9.2.2)
.
.
.
Installing sqlite3 (1.3.6) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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
.
.
.
--disable-local
Gem files will remain installed in /tmp/build_2l2dn7bx7lu34/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.6 for inspection.
Results logged to /tmp/build_2l2dn7bx7lu34/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.6/ext/sqlite3/gem_make.out
An error occured 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
To git#heroku.com:blazing-mountain-3659.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:blazing-mountain-3659.git'
When I do:
Amits-MacBook-Air-2:demo_app amitgupta$ sudo port install sqlite3 +universal
I get:
Password:
---> Computing dependencies for sqlite3
---> Cleaning sqlite3
Next I tried:
Amits-MacBook-Air-2:demo_app amitgupta$ sudo gem install sqlite3 -v '1.3.6'
And get:
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.6
1 gem installed
Installing ri documentation for sqlite3-1.3.6...
Installing RDoc documentation for sqlite3-1.3.6...
Then:
Amits-MacBook-Air-2:demo_app amitgupta$ bundle install
gives:
Using rake (0.9.2.2)
.
.
.
Using sqlite3 (1.3.6)
Using uglifier (1.2.4)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Then I try pushing to Heroku again, but get the same problem. Perhaps it has something to do with the discrepancy between the first command "Creating floating-stream-8009" and the second command "failed to push some refs to 'git#heroku.com:blazing-mountain-3659.git'"?
gem 'sqlite3', :group => [:development, :test]
group :production do
gem 'pg'
end
edit Gemfile as above
remove Gemfile.lock
run bundle install --without production
git add .
git commit -am "bundle updating sqlite3"
git push heroku master
Heroku uses postgresql so you want to remove sqlite3 or move it into a development group in your Gemfile.
Check you Gemfile.lock for any other gems that may have dependencies on sqlite3, as this can also cause problems.
I had a similar problem and I wasn't even using sqlite3 for anything but after removing it from the gem file I still got that error
what solved it for me was a commit command
git commit -am
that I found on this tutorial
What happened to me was, I was following along the Heroku tutorial and when I used git push heroku master it was pushing from my latest Git commit (obviously!)
What I forgot was that in the eyes of Git, I was still using sqlite in the gemfile! Silly me!
So I used git add . followed by a git commit -m "Changed to Postgres." so Git knew about these changes. Pushing after that worked fine for me.
Yes, as these answers suggest, most of the time you will want to avoid using SQLite in production due to the constraints of the Heroku platform. However, you may have a perfectly acceptable use case (ex. read-only config) for using SQLite anyway. My recommendation is to:
Add the heroku-buildpack-apt buildpack
Add to your Aptfile:
libsqlite3-dev
libsqlite3-0
We have an app that's been running on Heroku (bamboo) for over a year. When pushing a change yesterday, the push was rejected when it failed to install the paperclip gem. No changes had been made to the gem list up to the point of failure. I tried a brand new, barebones app and got the same result. It seems the bamboo stack has changed in some way. Anybody else experiencing this or know what might be going on?
Here are repro steps:
$ rails temp-app
$ cd temp-app
$ cat >.gems
rails -v 2.3.14
paperclip -v 2.5.0
<control-D>
$ git init
$ git add .
$ git commit -m "init"
$ heroku create --stack bamboo
$ git push heroku master
this is the output:
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Configure Rails to log to stdout
Installing rails_log_stdout... done
-----> Installing gem rails 2.3.14 from http://rubygems.org
Successfully installed activesupport-2.3.14
Successfully installed activerecord-2.3.14
Successfully installed actionpack-2.3.14
Successfully installed actionmailer-2.3.14
Successfully installed activeresource-2.3.14
Successfully installed rails-2.3.14
6 gems installed
-----> Installing gem paperclip 2.5.0 from http://rubygems.org
ERROR: While executing gem ... (NoMethodError)
undefined method `call' for nil:NilClass
! Heroku push rejected, failed to install gem
I did get an answer from Heroku support: Paperclip specifies a dependency on Active Record like this: 'activerecord', '>= 2.3.0' which causes the latest AR version to be installed. The latest version as of a few days ago is 3.2, which is broken on Rails 2.3, hence the failure.
I solved this by adding --ignore-dependencies to the paperclip gem in .gems and manually adding dependencies to .gems.