Thank you this community for getting me started on the right path. Specifying rails version to use when creating a new application gets me close, but the differing ruby version is what is throwing me off. I'm running into an error after running rails new that I'm not sure where to begin to resolve it. I gather from the error that my command is missing a parameter, but I can't determine what it is.
Any advice?
I would like to create a rails 5.2.6 project and I'm finding consistent responses elsewhere indicating that my approach to getting a rails project created with a specific version is to:
install the rails gem with gem install rails -v 5.2.6
create a new rails project, specifying the rails version with rails _5.2.6 new appName
I think I'm on to it. Did a specific google search for compatibility of Ruby 3 with Rails 5 and appears this is the likely problem.
I've now run 'rvm install 2.7.4' then 'rvm use 2.7.4' but still seems to be using ruby 3 in the command. The new error:
user#ubuntudev:~/railsprojects$ rails _5.2.6_ new rpapitest
/home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem railties (= 5.2.6) with executable rails (Gem::GemNotFoundException)
from /home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:300:in `activate_bin_path'
from /home/user/.rbenv/versions/3.0.0/bin/rails:23:in `<main>'
Try with rbenv global 2.7.4 if you have rbenv installed
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?
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.
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.
I'm new to rails/ruby and I'm following a tutorial on how to create your first app using git and heroku!
After figuring out the sqlite3 debacle, the error I receive now comes every time I try to start a server.
rails server
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:827:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:261:in `activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:68:in `gem'
from /usr/bin/rails:18
This error is a pain in the arse, and I don't know how to get around it. There's several articles on here about this particular error, but no one mentions receiving this error while trying to launch the server.
Is there anybody out there that could walk me through the steps to take to remedy this.
Should I provide my gemfile
Should I also provide my database.yml file for reviewing
Logs, anything else I'm not mentioning that could be of help to figure out the source of this problem
Let me know, I'm trying to move forward ad don't want to be stuck at this particular error for days.
First you should install rvm: https://rvm.io/rvm/install then you should install ruby =< 1.9.3
rvm install 2.1
then you should install rails
rvm use 2.1 && gem install rails
then
cd PROJECT_PATH && rails server
everything should work fine
I am new to ruby, i want to set up a new hello application in ruby, but i get always this error: (i am using osx, mountain lion), what to do?
rails new hello
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:777:in report_activate_error': RubyGem version error: rack(1.5.2 not ~> 1.4.5) (Gem::LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:211:inactivate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:246:in activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:245:ineach'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:245:in activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:246:inactivate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:245:in each'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:245:inactivate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:1056:in `gem'
from /usr/bin/rails:18
You need to update your gems:
sudo gem update
However, you will also be a lot happier if you also update your ruby. There are various ways to do this, but I am particularly fond of rbenv, which you can find at github. If you install rbenv and also its plug-in ruby-build, you can ask rbenv to download and install a higher version of ruby in a single command. Note that you will need to have installed Xcode first, including the Xcode command-line tools.
In fact, I just tried this and it worked. I used rbenv and ruby-build to install Ruby 2.0 freshly on Mountain Lion, as described here:
http://www.apeth.com/nonblog/stories/ruby2onmountainlion.html
I switched rbenv to use ruby 2.0. That didn't include rails, though, so I then did gem install rails. Finally, I said: .rbenv/shims/rails new hello and it worked. (The only reason I had to specify the path like that is that I'd forgotten, in all the excitement, to do an rbenv rehash. Silly me.)
So this must work, because I just did it in real time, between the time you asked your question and the time I wrote this answer!
It looks like your version of rack isn't supported with the version of ruby you are using. It also looks like you are using ruby 1.8, which is pretty outdated. I would try and go back and use 1.9.3, or ruby 2.0, which might solve your problem. Also, as far as text editors go, I would go with Sublime Text... http://www.sublimetext.com/2 It has a lot more shortcuts than TextMate.
I am trying to teach myself ruby on rails and I when I tried to access my server using Terminal on my Mac this is what I got back:
rails server /Library/Ruby/Site/1.8/rubygems/dependency.rb:247:in
to_specs': Could not find railties (>= 0) amongst [bundler-1.0.22,
rake-0.9.2] (Gem::LoadError) from
/Library/Ruby/Site/1.8/rubygems/dependency.rb:256:into_spec' from
/Library/Ruby/Site/1.8/rubygems.rb:1208:in `gem' from
/usr/bin/rails:18
Any thoughts on this?
Try typing "bundle exec rails server" to ensure that the proper gems are being loaded.
Also you'll probably want to be using Ruby 1.9.x for new Rails apps. Since you're using OS X I suggest https://github.com/sstephenson/ruby-build to build the latest version of Ruby. You can use it in conjunction with rbenv which will help you manage having two versions of Ruby on the same system.
If you do decide to use rbenv you'll want to type "gem uninstall bundler" and then reinstall it after you install rbenv so that the gem bin is in the right place. As stated above, you'll want to use "bundle exec" before any rails or rake command to make sure the proper environment is loaded.