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
I am using rvm to manage ruby versions. Also I am making use of trinidad. When I run trinidad -e production from any path then it runs but when I ran it through the shell script then it given the error
Gem::LoadError: Could not find 'trinidad' (>= 0) among 14 total gem(s)
to_specs at /usr/local/rvm/rubies/jruby-1.7.13/lib/ruby/shared/rubygems/dependency.rb:298
to_spec at /usr/local/rvm/rubies/jruby-1.7.13/lib/ruby/shared/rubygems/dependency.rb:309
gem at /usr/local/rvm/rubies/jruby-1.7.13/lib/ruby/shared/rubygems/core_ext/kernel_gem.rb:47
at /usr/local/rvm/gems/jruby-1.7.13/bin/trinidad:22
eval at org/jruby/RubyKernel.java:1101
(root) at /usr/local/rvm/gems/jruby-1.7.13/bin/jruby_executable_hooks:15
Use rvm x.x.x do trinidad -e production in your script or specify default rvm ruby version use rvm use x.x.x#global --default.
Update
Probably you problem can be related to current rvm gemset. So, try to specify ruby version with and without #global.
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 am very new to Ruby on Rails. I installed ruby on rails on my Windows 7 using the installer in http://railsinstaller.org/. I could create a project once and thereafter I was not (I dont know what did I do in between :-( ).
The complete errors messages are :-
On creating a new project :-
c:\Sites>rails new Tickets_Test
E:/Ashish/Ruby192/lib/ruby/1.9.1/rubygems.rb:762:in `report_activate_error': Cou
ld not find RubyGem rails (>= 0) (Gem::LoadError)
from E:/Ashish/Ruby192/lib/ruby/1.9.1/rubygems.rb:219:in `activate'
from E:/Ashish/Ruby192/lib/ruby/1.9.1/rubygems.rb:1065:in `gem'
from E:/Ashish/RailsInstaller/Ruby1.8.7/bin/rails:18:in `<main>'
on just getting the version:-
c:\Sites>rails --version
E:/Ashish/Ruby192/lib/ruby/1.9.1/rubygems.rb:762:in `report_activate_error': Cou
ld not find RubyGem rails (>= 0) (Gem::LoadError)
from E:/Ashish/Ruby192/lib/ruby/1.9.1/rubygems.rb:219:in `activate'
from E:/Ashish/Ruby192/lib/ruby/1.9.1/rubygems.rb:1065:in `gem'
from E:/Ashish/RailsInstaller/Ruby1.8.7/bin/rails:18:in `<main>'
Any idea why the above is happening?
EDIT
Appearently there are two command prompts :-
Ruby command prompt :-
and
Ruby for rails command prompt (The problem is resolved using this command prompt):-
I was using ruby command prompt. Sounds like a stupid question, however, I am not sure how there are "two" command prompts?
I ran into a similar issues after installing heroku toolbelt. I found that heroku added the second one to my path. I removed it from the path and life seems good again!
You seem to have two Ruby versions in your system, 1.9.1 and 1.8.7. Rails gem seems to be installed only for one of them. I'd suggest you to remove one of these versions, and reinstall Rails.
If you have two Ruby versions in your system, 1.9.1 and 1.8.7, then no need to remove any. You can switch between these two Ruby versions with the help of RVM on OS X and Linux. And for Windows you can use Pik.
For further details, you can go through posts - http://rorguide.blogspot.com/2011/03/pik-rvm-tools-to-manage-multiple-ruby.html
Try using Pik (available at http://github.com) to switch between the two or edit your path to include one but not the other. That's simpler.
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)