searching for an answer to the question above in Stackoverflow I have always bumped into a similar - but not equal - question: whether it is possible to create a new rails app with an older version than the latest installed on the computer (one of the most popular posts of this kind is Specifying rails version to use when creating a new application). However, what I'm interested in is knowing if it's possible to run a command such as 'rails __2.1.0__ new myapp' even if that specific rails version is not yet installed on my computer so that when it runs it it automatically installs this rails version plus it creates all the starting files (in which the Gemfile contains all the compatible gems of that specific version already).
As an example... Right now I'm following the Rails Tutorial book by Michael Hartl and we are asked to use the ruby version 2.0.0, the rails version 4.0.8 and to include the following info into the Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
group :development do
gem 'sqlite3', '1.3.8'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
It happens that I have by default ruby-2.1.2 and rails 4.1.4 so when I have wanted to follow Hartl's book I have had to create a new rails application (which sets up the Gemfile according to rails 4.1.4) and after that I have had to cd into the new app, run $ gem install rails --version 4.0.8 to install the version, substitute the default Gemfile that came with rails 4.1.4 for the above code, then run bundle install and bundle update.
It seems to work, but all in all it is a rather tedious and annoying solution. Couldn't this be solved, like I wrote at the beggining, with a 'rails ____2.1.0____ new myapp' in which version 2.1.0 (that I do not have installed) gets installed at that moment?
I'm sure there has to be an easier way to get started with a different rails version project, I just don't find it or try to solve it with the wrong commands. I'm sure the solution I implemented wasn't good enough either since whenever I try to create another rails app using a version that I have allegedly already installed (2.0.0) this is what I get from the Terminal:
Desktop$ rails _2.0.0_ new myapp
/Users/gaa/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'railties' (= 2.0.0) - did find: [railties-4.1.4,railties-4.1.1] (Gem::LoadError)
Checked in 'GEM_PATH=/Users/gaa/.rvm/gems/ruby-2.1.2:/Users/gaa/.rvm/gems/ruby-2.1.2@global', execute `gem env` for more information
from /Users/gaa/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:322:in `to_spec'
from /Users/gaa/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:53:in `gem'
from /Users/gaa/.rvm/gems/ruby-2.1.2/bin/rails:22:in `<main>'
from /Users/gaa/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /Users/gaa/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
I would really appreciate a helping hand.
Run RubyMine and click New Project on the Welcome Screen. Name: specify a name for the project (rails-helloworld in our case). Location: specify a path to the directory in which you want to create the project. By default, RubyMine creates a directory with the same name as the project.
I think what you're after is this:
gem install rails -v 4.0.8
rails _4.0.8_ new myapp
That would generate a rails 4.0.8 app, and create a default Gemfile locked at 4.0.8. Less tedious.
Rails needs to be installed, to run the rails
command. gem
is the installer. Ruby needs to be installed, to run gem
. Ruby evolves and fixes bugs, old projects may need older versions etc. You probably want a ruby version manager which gets its' own installation (chruby, rbenv, rvm) that should precede the gem install ...
. You can lock the ruby version for a project, in the Gemfile too e.g.:
source 'https://rubygems.org'
ruby '2.1.2'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With