1

ANSWERED (other noobs should read what I did): Thanks to those who answered, but I think I know why it had still been defaulting to the system ruby earlier. I started a shell session and installed rbenv, then install ruby-build for rbenv, then install ruby 2.1.2 and ran rbenv global 2.1.2 Then I installed the new version of rails and tried to create a new rails project.

I think the mistake was just that I hadn't started a new shell session and so it defaulted to the rails location it had when the session started, which was with the system ruby. Stupid mistake. Blah.

ORIGINAL POST: These are my rbenv versions

  system
* 2.1.2 (set by /home/ab/.rbenv/version)

and this is what I get when I run

gem list -d rails
rails (4.2.0.beta1, 4.1.1)
    Author: David Heinemeier Hansson
    Homepage: http://www.rubyonrails.org
    License: MIT
    Installed at (4.2.0.beta1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
                 (4.1.1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0

The Hartl tutorial online uses 4.2.0beta1, so I want to use that, but when I try to make a new rails project, it defaults to 4.1.1.

Somebody from this suggested a way to change a default rails version, but the command looks in the wrong location. See here

ab@abpc:~/Code/RailsTutorial$ rails _4.2.0beta1_ -v
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (= 4.2.0beta1) amongst [actionmailer-4.1.1, actionpack-4.1.1, actionview-4.1.1, activemodel-4.1.1, activerecord-4.1.1, activesupport-4.1.1, arel-5.0.1.20140414130214, builder-3.2.2, bundler-1.3.5, coffee-rails-4.0.1, coffee-script-2.2.0, coffee-script-source-1.7.0, diff-lcs-1.2.5, erubis-2.7.0, execjs-2.1.0, hike-1.2.3, i18n-0.6.9, jbuilder-2.0.7, jquery-rails-3.1.0, json-1.8.1, libv8-3.16.14.3-x86_64-linux, mail-2.5.4, mime-types-1.25.1, mini_portile-0.6.0, minitest-5.3.4, multi_json-1.10.1, net-http-persistent-2.9, nokogiri-1.6.2.1, polyglot-0.3.5, rack-1.5.2, rack-protection-1.5.3, rack-test-0.6.2, rails-4.1.1, railties-4.1.1, rake-10.3.2, rdoc-4.1.1, rdoc-3.9.4, ref-1.0.5, rspec-2.14.1, rspec-core-2.14.8, rspec-expectations-2.14.5, rspec-mocks-2.14.6, rspec-rails-2.14.2, sass-3.2.19, sass-rails-4.0.3, sdoc-0.4.0, sinatra-1.4.5, spring-1.1.3, sprockets-2.11.0, sprockets-rails-2.1.3, sqlite3-1.3.9, therubyracer-0.12.1, thor-0.19.1, thor-0.18.1.20140116, thread_safe-0.3.4, tilt-1.4.1, treetop-1.4.15, turbolinks-2.2.2, tzinfo-1.2.0, uglifier-2.5.0, webrat-0.7.3] (Gem::LoadError)
        from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
        from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
        from /usr/local/bin/rails:22:in `<main>'

I'm still far from as knowledgeable as I'd like to be, but I can see that "rails" is defaulting to usr/lib/bin/rails and I need to reroute it to ~/.rbenv/versions/2.1.2/lib/ or somewhere around there... not entirely sure where, and I don't know how to get it to do that. Help?

ABvsPred
  • 67
  • 7
  • Maybe this answer will help you: http://stackoverflow.com/a/23432414/2173804 – sweo Sep 27 '14 at 20:15
  • If you have not done too much in the old project create a new rails project with the version you want. When you created your rails app it was created with 4.1.1 and it references the corresponding gem versions. You cannot start that app with a different version of rails as the gem versions differ. – brahmana Sep 27 '14 at 20:53

2 Answers2

1

It looks like you are using your system ruby v1.9.1 which is not compatible with rails 4 at all (Rails 4 requires 1.9.3 or higher).

So first you need to set your ruby version using rbenv global 2.1.2 to set it system-wide or rbenv local 2.1.2 if you just want it for this project. I'm not sure if your system will then default to rails-4.1.1 or the newer beta but you can try rails -v to find out. If not, rails _4.2.0.beta1_ new myapp should work.

surreymagpie
  • 327
  • 1
  • 4
0

The Hartl tutorial online uses 4.2.0beta1

Here is what I am seeing:

Install Rails

Once you’ve installed RubyGems, installing Rails should be easy. This tutorial standardizes on Rails 4.0, which we can install as follows:

$ gem install rails --version 4.0.8

...

but when I try to make a new rails project, it defaults to 4.1.1.

Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=sample_app2_gems

gem 'rails', '4.0.8'

...

Set the version of rails you want to use in your Gemfile.

7stud
  • 46,922
  • 14
  • 101
  • 127