I use Ruby 1.9.x syntax in my Rails 3 app, but after pushing it to Heroku it crashes due to older Ruby version (1.8). How can I control it?
Heroku's current stack, Cedar, uses 1.9.2 by default. Cedar also supports specifying the Ruby version in your Gemfile. Currently, 1.9.2 and 1.9.3 are valid options.
# Gemfile
source "https://rubygems.org"
ruby "1.9.3"
...
More details are available in the Ruby support article: https://devcenter.heroku.com/articles/ruby-support
If you are currently using Aspen or Bamboo, you can switch to 1.9.2 by using the stack:migrate command:
$ heroku stack:migrate bamboo-mri-1.9.2
You cannot automatically migrate to the Cedar stack at this time, but there is a guide on how to do so: https://devcenter.heroku.com/articles/cedar-migration
You can now explicitly specify a Ruby version on Heroku.
Simply setup your Gemfile as so
# Gemfile
source "https://rubygems.org"
ruby "1.9.3"
# Gems go here
I wanted to use the version I already had defined in the .ruby-version file so I ended up creating a buildpack that can be used before heroku-buildpack-ruby that injects the version from the .ruby-version into the Gemfile. It also support versions without patch or aliases.
https://github.com/platanus/heroku-buildpack-ruby-version
This way you can have your version defined only in one place.
Related
I put the ruby version 2.3.1 in my gemfile, but Heroku keeps using 2.4.4. How do I make it so Heroku recognizes the version specified in the gemfile?
try to use the heroku console by typing heroku run "ruby -v" and give command to use which version of ruby you want him to
You are probably on the heroku-18 stack which it the current default. Please note that Ruby 2.3.x is not available on this stack.
You have two options:
Update your Ruby version to a more recent version or
Downgrade Heroku to use an older stack.
Given that the maintenance phase for Ruby 2.3.x has ended anyway I would suggest updating our application to use at least Ruby 2.4.4.
The Ruby on Rails Tutorial by Michael Hartl uses a Gemfile without specifying a Ruby version: the ruby keyword is missing in all the applications.
When I deploy to Heroku I receive the following warning:
remote: ###### WARNING:
remote: You have not declared a Ruby version in your Gemfile.
remote: To set your Ruby version add this line to your Gemfile:
remote: ruby '2.2.4'
remote: # See https://devcenter.heroku.com/articles/ruby-versions for more information.
The tutorial says that "the costs associated with including such an explicit Ruby version number outweigh the (negligible) benefits, so you should ignore this warning for now. The main issue is that keeping your sample app and system in sync with the latest Ruby version can be a huge inconvenience".
I am wondering whether the alternative is to keep the pace with the Ruby version at Heroku (presumably 2.2.4 at present), as the book seems to suggest, or also to specify any Ruby version it suits me. In other words, since I am using Ruby 2.2.1p85 for my application, adding ruby "2.2.1", :patchlevel => "85" would work and make Heroku adjust to this version or rather I am supposed to adjust to Heroku and add as suggested ruby '2.2.4'?
I am using rvm and a specific gemset with a specific Ruby version, for no other reason than trying to use an environment as much close to the tutorial as possible. What is the best practice in a real context? Would you suggest to use the last Ruby version and include it in the Gemfile? Can the Gemfile leave out the Ruby version with no worries?
Please follow the steps to solve
You can check which ruby version is associate with your app by command
heroku run "ruby -v"
It is good to have default version of ruby which is 2.2.4 in order to solve your problem. If your ruby version is older than 2.2.4 then please upgrade it.
after checking/upgrading version You can use the ruby keyword in your app’s Gemfile to specify a particular version of Ruby.
source "https://rubygems.org"
ruby "2.2.4"
You will need to install and update bundler again
$ gem install bundler
$ bundle update
This command:
heroku run rake db:migrate
solved same problem
I'm having major issues with the heroku toolbelt. I'm using the cedar 14 stack and when I am trying to use a ruby version that isn't ruby 2.0.0-dev I get this error.
rbenv: heroku: command not found
The `heroku' command exists in these Ruby versions:
2.0.0-dev
I need heroku to be working with ruby 1.9.3 and I don't think cedar 14 supports that version of ruby. Can someone explain first, why I am only allowed to use heroku with ruby 2.0.0-dev and also how I can install a older stack that supports ruby 1.9.3?
The problem is that there are two heroku executables on your system: one in system paths such as /usr/local/bin/heroku (provided by Toolbelt), and one in rbenv's shims because Ruby 2.0.0-dev had "heroku" gem installed.
Because rbenv's shims directory usually have higher precedence, it will block invocation from ever executing the heroku executable provided by Toolbelt.
The solution is to uninstall any instance of "heroku" gem and relying solely on Toolbelt for all heroku usage on the command line:
for v in `rbenv whence heroku`; do RBENV_VERSION=$v gem uni heroku -ax; done
rbenv rehash
which heroku
You can use 1.9.3 on the cedar stack according to this. The heroku toolbelt is installed as a executable not a ruby gem. How are you trying to execute the command? You should be able to use it from the terminal such as heroku run rake db:migrate etc.
I just followed this RailsApps install/setup tutorial, which uses RVM and creates a .ruby-version and a .ruby-gemset to specify the Ruby version and a project-specific gemset.
I already read this post regarding on what to do to these files for version control.
My question is how about when deploying to hosting platforms, like Heroku? They point to your git repository which may or may not include these files. Is it still OK to check-in .ruby-version when deploying?
For example, the Heroku docs says the the Ruby version is specified via Gemfile or environment variable. So I'm a little confused if platforms like Heroku respect these RVM-generated files.
Notes:
Ruby v2.2.3
RVM v1.26.11
Per the docs Heroku will look for your Ruby version in a few places:
1) Gemfile
2) An environment variable called CUSTOM_RUBY_VERSION
I prefer to specify the Ruby version in my Gemfile.
So, Heroku should ignore .ruby-version. The Ruby you specify in your Gemfile should probably match the version specified in .ruby-version
As a general rule I would check .ruby-version into source control.
I had Rails 2.3.5 installed, and wanted to upgrade to 2.3.10 as a stepping stone to Rails 3. I thought running gem install rails -v=2.3.10 would install 2.3.10 and keep 2.3.5 as well. But now when I do rails -v, it only lists Rails 2.3.10. How can I install different versions of Rails and keep the existing ones?
gem list rails should show you all installed versions of Rails. You can specify which one you want each project to use in the config/environment.rb file.
Alternately (or "additionally"), look in to RVM (particularly the "gemset" function) for maintaining separate gem sets for each project.
Updated May 2017 Instead of RVM gemsets, best practice for managing gems in Rails projects (including the Rails gem itself) is to use Bundler. Bundler's Gemfile will list all the gems your project uses, and allows you to "pin" versions, so by changing the version pin for Rails and running bundle you can update your project to the new version.
<sarcasm>Now that I've said that, though, Bundler is probably on the way out to be replaced by something else. </sarcasm>
You still have both versions, as the other answers have mentioned. However, you don't want to call rails newapp and then change the config/environment.rb file. This will cause problems for any files that have changed between versions. Instead, create a new 2.3.5 app this way:
rails _2.3.5_ newapp
And you'll run the exact version of rails you want, to create the file structure correctly. I don't know why this isn't documented better.
To answer your question, you can install many versions of the rails gem without conflict. However, each project is created using a specific version. To install a new version of the rails gem as follow;
Change the version 3.2.18 with any version you like (see link below for all available versions).
gem install rails --version=3.2.18
To install the latest version
gem install rails
To check all the rails version available, check out this link
Here is a link to all the version of rails
You might consider updating your gem software by this command prior to loading new gems.
gem update --system
As per #pjmorse, list the version installed with this command
gem list rails
Hope that helps
You can define the Rails version of an application in config/enviroment.rb.
You can vendor the version of rails you want into your vendor/rails folder. At the command line just run rake `rake rails:freeze:edge RELEASE=2.2.2'. You don't need any version of rails installed for this to work it will take the source and build it from the remote source in your vendor directory.
rake rails:freeze:edge RELEASE=2.2.1
rake rails:freeze:edge RELEASE=2.2.2
rake rails:freeze:edge RELEASE=2.2.3
rake rails:freeze:edge RELEASE=2.2.4
rake rails:freeze:edge RELEASE=2.2.5
rake rails:freeze:edge RELEASE=2.2.6
rake rails:freeze:edge RELEASE=2.2.7
rake rails:freeze:edge RELEASE=2.2.8