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
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.
I am trying to set my machine up so I can follow this tutorial: the intro to rails screen-cast i wish i had.
I keep running into issues, most recently the following:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ansi-1.4.1/lib/ansi/code.rb:5:in `require':
no such file to load -- Win32/Console/ANSI (LoadError)
This occurs when ever I run rails g. (I would like to see if my r spec generator has been added.)
Environment details: Windows 7, ruby 1.9.2p290, rails 3.1.1, rubygems 1.8.15
After you installed "gem install win32console", can you add this gem into your Gemfile file and try to run bundle install again?
Gemfile
gem "win32console", "~> 1.3.0"
RailsInstaller may be your best bet if you're looking for an integrated Windows Rails experience.
It's up-to-date (-ish, doesn't use Ruby 1.9.3) with:
Ruby 1.9.2-p290
Rails 3.1.1
Git 1.7.6
and other useful bits.
I'm working on two different rails installations for two different projects. They are on different versions of rails. Here's what I have installed:
gem list --local | grep rails
shows that I have this installed:
rails (3.0.0.beta4, 2.3.5)
When I run a command to do a deployment for the app that uses 2.3.5, I get the following error:
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your
RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do
have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
It's not finding the correct rails version, even though I have it installed. What are good short- and longer-term solutions for this problem?
I suggest you RVM. It allow you to have different ruby/gems versions on the same machine.
The long term solution is to look into rvm, especially the gemset feature makes it really easy to keep separate versions of gems and even ruby versions for different projects.
A short trem solution may be to add the the following line to your boot.rb file, somewhere before rails is required:
gem rails, "2.3.5"
This loads the right version of the gem, otherwise gem will think you want the latest version.
As others have noted, rvm is one way to solve this problem. The other is to use bundler, which involves some setup in your application and potentially requiring you to use 'bundle exec command' everywhere you want to run conflicting versions of a command (eg cucumber)
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
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.