While doing local Rails 6 development, via Docker, using the latest Heroku stack image as the starting point (FROM heroku/heroku:20-build), what does a Dockerfile need in order to replace the 'old' version of ruby in the stack image with a newer version from a Heroku ruby buildpack?
For Dockerized Rails development, starting with a Heroku stack image seem like the right way to maintain dev/prod parity to minimize those hard to debug "it worked locally then broke on Heroku" issues.
However, even the latest version of a Heroku stack image (20-build) does not include the current "default" version of ruby (2.7.3 at the moment)... even worse what it comes with is 2.7.0 and avoiding any ".0" version is generally wise.
Looking at the github pages for Heroku's buildpack (https://github.com/heroku/heroku-buildpack-ruby) I see no clues how the buildpack can be used to install a newer version of Ruby to a Dockerfile.
I know from an article I found online that Heroku has Ruby 2.7.3 available at https://heroku-buildpack-ruby.s3.amazonaws.com/heroku-18/ruby-2.7.3.tgz
However I cannot see how in the Dockerfile to replace the existing 2.7.0 with that version 2.7.3 without breaking everything.
On older Heroku stacks and buildpacks you could do something like this:
apt remove -y --purge ruby && curl -s --retry 3 -L https://heroku-buildpack-ruby.s3.amazonaws.com/heroku-18/ruby-2.7.3.tgz | tar -xz
but doing this with heroku/heroku:20-build does not successfully install the new version of ruby in the right path and it breaks rubygems so that a simple gem list throws an error (undefined method rubyforge_project=' for class Gem::Specification' (NameError))
(I considered but dislike the idea of installing some ruby version manager like rbenv in the app's Dockerfile... the app only needs one version of ruby, and it introduces another pointless dependency, so hopefully there is a reasonable way to simply upgrade ruby in the image)
Related
these are my first steps using Heroku; I'm trying to deploy a very basic Ruby on Rails Rest API to Heroku, when I run the command: git push heroku main I got this error:
So, using a couple of commands I found the differences:
Checking versions:
Checking the Gemfile:
Using keroku CLI to check Ruby's version:
so it seems there is a problem with the PATH variable, at least it was I read, and definitively the ruby's version are different using the command heroku run "ruby -v"
My question is: how can I solve the ruby mismatch version?
Thanks a lot
I had an app deployed on Heroku and I am currently trying to create the same app on AWS.
I've copied my folder, created a complete separated repo on Github and installed ebcli, the setup looks fine.
When I try to run eb deploy, I have this error:
[Instance: i-03051e2a022886184] Command failed on instance. Return code: 1 Output: (TRUNCATED)...:in find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems.rb:308:inactivate_bin_path'
from /opt/rubies/ruby-2.5.3/bin/bundle:23:in `'.
I've looked online and it says it comes from incompatibility between your gemlock file bundler version and actual bundler version.
I've tried to change my bundler version to this one, but I gave up and came back to 2.0.1 because I had to install too many dependencies otherwise.
I removed the gemlock, bundle again, but I still got the same error when trying to deploy.
With my heroku version, it always worked.
Any idea how to solve that?
Thanks a lot
We moved from Heroku to AWS a few months back as well and it will likely take some some custom scripting to get things to work.
It would help to know more about your EB environment, but I am assuming you are using Ruby 2.5 with Puma on Amazon Linux 2.9.0 (?)
Not sure what bundle version comes with that, But I don’t think it’s 2.x. so you have to add an .ebextensions file too install your preferred bundled version.
# .ebextensions/01_install_bundler.config
container_commands:
install_bundler:
command: “gem install bundler —-version 2.0.0”
More info on AWS Linux customizations
End of the day, we are much happier with our AWS environment (lower cost, better performance), but requires more work to get it set up
Actually the problem exists because the bundler version in the eb env is older than the one being used in the project source.
So the solution is to use a bundler version less or equal the eb env installed version.
First uninstalled the current bundler:
gem uninstall bundle
and then install the desired one:
gem install bundler -v 1.16.6
See more details
I am having a lot of issues on ruby & gem installation due to which my running projects are stopped working.
Current issues
Can anyone please guide me on "how to completely uninstall ruby + gems + rails out of my Ubuntu 14.04 and then start installing them as fresh".
I am also unable to remove this. Maybe once I completely throughout of my system. It may allow me to fresh install ruby n rails. Looking into this in order to make things work again.
Can anyone help?
If you can see my question up there, I have rbenv, ruby and rails installed and a lot more. I am not able to run it though. And due to which I am thinking of removing it out of my system and install them as fresh. Today, I somehow was able to fix a few issues and created a new rails application and started the server using MySQL. But, its too showing errors on other ruby lib command: rails script/generate model Book Rails is throwing me errors.
/home/<user>/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /home/<user>/.rvm/gems/ruby-2.5.3/bin in PATH, mode 040777
rails aborted!
Don't know how to build task 'script/generate' (see --tasks)
Can anyone help?
I highly highly recommend not touching the built-in ruby/rails/gems installation.
It's pretty standard these days to use a very lightweight manager, like rbenv which allows you to work with multiple versions of ruby, each with it's own installations of gems. There is also rvm, which is a heavier manager and a bit more invasive.
install the newer versions with rbenv
brew install rbenv
rbenv init
Close your Terminal window and open a new one so your changes take effect.
Verify that rbenv is properly set up using this rbenv-doctor script.
rbenv install.
brew upgrade rbenv ruby-build
and then install rails
ruby on rails setup
for database i preferred sqlite browser
I'm working on Bluehost. I installed the 3.2.8 gem of rails, and now I get this:
> gem list --local | grep rails
rails (3.2.8)
But:
rails --version
Rails 2.3.11
How can I make the "rails" command use the latest gem? I guess it has something to do with my $PATH variable but I'm pretty much clueless about it.
Also, the gem and rails command give rise to some errors that look like this:
Invalid gemspec in [XXX]: invalid date format in specification: "YYY"
I'm not sure if that's connected (and I'm wondering what causes such errors anyway).
Try running this command:
curl -L https://get.rvm.io | bash -s stable --ruby --rails
What it does is install RVM, which maintains separate gems for each version of Ruby installed. The --ruby and --rails arguments tell it to install ruby and rails while installing RVM. RVM installation automatically updates $PATH and any other necessary environment variables.
At the end of installation, it should prompt you to run:
source ~/.rvm/scripts/rvm
which will make those environment variable changes effective immediately. Alternatively, you can log out and then log right back in.
Run rails -v and ruby -v at that point, and you should see them pointing to the new version. Run bundle install from your RoR app's directory and all the gems you need should install in ~/.rvm/gems/ruby-/gems.
At that point, you can delete/uninstall any gems/rails/ruby from before installing RVM.
EDIT on 10/17/2012:
Nevermind my answer. Even though it might be possible to get Rails 3.x running with the currently installed Ruby 1.8 (see this Stackoverflow question), you won't be able to run Ruby 1.9.x using Bluehost Shared Hosting. Your only choice (for now) is VPS Hosting.
The reason is that Passenger Phusion is tied to the version of Ruby installed in /usr/lib, which you can't change without root access. Even though you can install any version of Ruby with RVM, you won't get Passenger to talk to it and therefore your rails project won't use its gems.
I used railstutorial.org to install the latest version of ruby and the latest version of rails on my machine.
at the end of the installation I checked
ruby -v ==> 1.9.2 (great)
rails -v ==> 3.0.1 (great)
this morning I opened up terminal
ruby -v
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]
rails -v
Rails 1.2.6
what happened?
My advice for people who are installing ruby is to use RVM. It makes managing your ruby versions and gem versions really simple and you can install multiple ruby versions side by side.
You might want to read this post:
http://rubylearning.com/blog/2010/12/20/how-do-i-keep-multiple-ruby-projects-separate/
You can use Cinderalla to the whole ruby/rvm/mysql/redis/git/... stack set up properly. Cinderella installs everything in ~/Developer and fixes up your PATH as well. I had some issues with a corrupt git mirror last time I used Cinderalla though so YMMV.
With many unix variants, you are likely to have multiple versions of Ruby--particularly if you installed Ruby 1.9 and the system already had 1.8 installed. Essentially, the 1.8 version of Ruby has a higher precedence in your PATH than the 1.9 version. The Ruby Gems command keeps the libraries separate between 1.8 and 1.9 so that the platform will be reasonably stable.
To correct the problem, you have to find where ruby 1.9 is installed. Once you do that, you'll need to override your PATH variable. Assuming 1.9 is installed in the path: /opt/ruby-1.9.2, you will need to set your PATH like this:
PATH=/opt/ruby-1.9.2/bin:$PATH
export PATH
To make the path respect what you want every time, add that to your ~/.profile file (create it if necessary). Once the path has been set, it sould be able to find the correct version of Rails again.
I cannot say for certain because I cannot debug you OSX machine from here, however, I had a very similar occurrence. The problem was caused because I had installed ruby and then rails on my machine using sudo or from the root account. Then when I discovered rvm I installed everything in my user account. When I logged off and back in I appeared to lose everything. I was pulling out my hair. I was pissed that I was going to have to reinstall everything again... when I found the magic.
from the command line execute the command:
rvm list
you'll see that your new version of ruby is there. you'll also notice the tokens that indicate that it is just a normal version. It is not current or default. (see it yet)
Now if you run the command:
rvm use 1.9.2 --default
then every time you login/off and restart your machine your user account will default to that version of ruby and all of the gems that you installed against that version.