Can't switch default version ruby for rails - ruby-on-rails

I'm desperate, please help. I can't figure out how to change Ruby on Rails to run with 2.0.0, even though I think I've done everything to set 2.0.0 as the default, and rvm -list doesn't even show 1.8.7 as an option. I don't know what files I need to move/what pathways I need to change, and my attempts to uninstall rails have been unsuccessful as there's a "missingBundle" error.
$ ruby - v
returns ruby 2.0.0p247
$ rvm--default use 2.0.0
Using /Users/ericafischer-colbrie/.rvm/gems/ruby-2.0.0-p247
Then,
$ rails -s
Rails prefers to run ruby 2.0. You're running ruby 1.8.7 (2012-02-08 patchlevel 358)
[universal-darwin12.0]. Please upgrade to Ruby 1.9.3 or new to continue.
I've spent a lot of time looking at similar questions posted on stackoverflow and those solutions so far have not yielded any results.

Since you're using rvm, make sure you create a gemset and ruby-version file and install the version of rails you want to use.
E.g inside you're working dir tell rvm which ruby to use, which gemset to use, create both a gemset and ruby-version file:
rvm use ruby-2.0.0#my_cool_project --ruby-version --create
Then
gem install rails
To check run which ruby in that directory to make sure it's ruby 2 - - which rails will show you that it's using the gem of rails inside the ruby 2 my cool project gemset. Should be ok

Looks like you may have used something like sudo gem install rails.
When installing gems, you want to be sure to not use the sudo command.
Try sudo gem uninstall rails; rvm use ruby-2.0.0#myapp --create; gem install rails

Install rvm in your Macintosh
Then do rvm install 2.0.0 or rvm install version(whatever version you need)
Where ever you need a particular version of Ruby(say 2.0.0), do rvm use 2.0.0 and whichever version you need you can switch similarly.
If you are not sure how to install rvm or stuck with something else. Please see link for detailed explanation.
Updated, thanks #Momer.

Related

How do I upgrade the Ruby version of my project?

I recently started learning Rails using Ruby 1.9.3p385, and I'm trying to develop a small project with it.
I'm using Linux so I installed Ruby using RVM.
I developed a few pages, following some tutorials. I would like to upgrade my project to use Ruby 2.0.0. What do I have to do?
I installed Ruby 2.0.0 with RVM:
rvm install 2.0.0
Everything seems OK, so I tried to use it:
rvm use 2.0.0-p247
But when I try to run my Rails server using rails server, I get the following message:
bash: rails : command not found
I've read the RVM documentation about upgrading Ruby but I don't really understand what it does; I'm afraid of breaking everything.
Does it will upgrade my project in a way it will use Ruby 2.0.0 or what should I do?
Next, I will want to upgrade also to Rails v4.
Your gemset which comes with new Ruby version is empty. Try this:
gem install bundler # this will install bundler
bundle # this will use bundler to install required gems
rails server
Did you run rvm use 2.0.0-p247 or did you use rvm use 2.0.0-p247 --default? The later will set Ruby v.2.0 as the default for your system. Failure to do that will revert your Ruby to whatever RVM's default is the next time you log into your system or open a new terminal window.
When RVM installs a new version of Ruby, it installs only the default gems. It CAN upgrade a Ruby to another version, and optionally install the existing gems as it does so, but that's not what you asked it to do: rvm install 2.0.0 only installs Ruby. At that point you have to install the other gems you need, which would include Rails.
My general practice when installing various versions of Ruby and the gems I like is to use two command-line pipes to dump my existing gems, then (re)install them. First I switch to an existing Ruby whose gems I want to duplicate, then run:
gem list | cut -f1 -d' ' > ~/gem_list
Then I switch to the newly installed one, and run this:
xargs gem install < ~/gem_list
This does a completely clean install of the gems, outside of RVM's commands.
Why? Habit. Paranoia based on some "experiences" I had in the past with RVM.
Once that's all done and I have brand-spanking-new Ruby and gems, I'll proceed with running bundler or other housekeeping chores.
when you install a new ruby version, you have to reinstall all the gems for that version. start of by installing bundler first. Then run bundle in your rails root directory. When you encounter no errors, you're good to start the rails server. Good luck!
run bundle install on the application root, you need to reinstall all your dependencies for the new version of Ruby.

How to point Rails to the right Ruby install

I've been fighting with my Mac OS X 10.8 installed version of Ruby and tried to move to a .rvm install in order to keep everything up to date.
After going through all the documentation on the RVM website, here are some outcomes:
~$ which ruby
/Users/localadmin/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
~$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
~$ which rails
/usr/bin/rails
~$ rails -v
-bash: /usr/bin/rails: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
I'm not exactly sure what's causing this. I'm expecting that Rails is trying to use the system Ruby version, which isn't what I set as default in RVM.
I've read that it could be a .gemrc problem, but I can't seem to find a .gemrc file in my home directory. I can't seem to find any references to rails in my .rvm directory, so I'm thinking maybe when I did "gem install rails", "gem" was actually the one affiliated with my system Ruby.
Sorry to answer my own question, and I'd be happy if it gets deleted, but the solution was fairly annoying.
I had been installing rails with:
sudo gem install rails
I guess this took me out of the userspace in which my RVM installation sat
gem install rails
installed rails properly and now I get "Rails 3.2.9" as the outcome to rails -v
Could anyone shine any light on why this happened?
When using RVM, you pretty much NEVER use sudo for anything. The only common exception to this I've found is when installing the Passenger module.
That means all operations you want to perform on or with gems, rubies, rubygems, or RVM itself should NOT be performed with sudo.
Also make sure to do rvm use [RUBY] --default to make certain you're always using a ruby other than the system ones.

Mac OS X Mountain Lion "Rails is not currently installed on this system."

I am on a fresh install of OS X Mountain Lion. I have installed rails via:
sudo gem install rails
Everything seems to install correctly, but when I type the rails command (rails s, rails -v, etc), I get this error:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
The result of 'which rails' is /usr/bin/rails
I thought it was a path issue, and perhaps it is, but I can see that /usr/bin is part of my PATH.
Any help? Thanks!
UPDATE: I noticed everything on my other mac with same exact OS works pretty well... I just can't remember how I got it to work that way. If I run 'which rails' I see it's in a totally different place /Users/username/.rvm/gems/ruby-1.9.3-p194/bin/rails
If you're using rbenv, don't forget to rbenv rehash after installing/updating ruby.
Use RVM http://rvm.io or rbenv to install newer Rails versions than what come pre-installed with OS X.
Follow examples on the site https://rvm.io/rvm/install/ but basically:
Install RVM: $ \curl -L https://get.rvm.io | bash -s stable
You can then $rvm list known to see what Rubies are available to you (lots). And simply $rvm install 1.9.3 to get the most current version of Ruby (which as of this writing is ruby-1.9.3-p327)
Set that ruby as your default $rvm --default use 1.9.3
Create a default gemset to store your gems $rvm use 1.9.3#mygemset --create --default
Then install Rails $ gem install rails will get you current which today is same as typing gem install rails -v 3.2.9
Just had this issue using rbenv, no idea how this happened, but figured that my ~/.rbenv/shims/rails was empty...
So to fix this:
Cleaned empty shims: find ~/.rbenv/shims -empty -delete
Then regenerate: rbenv rehash (was not overwriting empty one...)
I had the same problem.
After typing:
sudo gem install rails
and installing rails correctly, just close the Terminal window and open again. Then type:
~ $ rails -v
Rails 4.0.2
So, reseting the Terminal window fix the problem.
I think install rvm that will help you
rvm get head && rvm reload
rvm install 1.9.3
rvm use 1.9.3#current --create --default
The last line creates a gem set called current.
Now check to make sure you RubyGems was installed correctly by typing which gem in your terminal. Now update your gems.
gem update --system 1.8.24
Finally install rails.
gem install rails -v 3.2.3
I hope this works, let me know if you have any issues.
Yes, OSX comes standard with a lot of great software for Ruby on Rails, as well as PHP, Mysql, etc. However, sometimes it's better for sustainment purposes to use a 3rd party installer to get everything you want without digging through your /usr/ directory.
I recommend checking out http://railsinstaller.org/
With one easy install, you have everything you could want for a Rails project, including common software people use, and the site even has a tutorial. I recommend going this way. It saves you time. Plus, it comes with an easy uninstaller that it will put in your Applications folder to remove if you're not happy with the configuration. Enjoy.
Actually, /usr/bin/rails script is just a
# Stub rails command to load rails from Gems or print an error if not installed.
(Comment quoted from the very script's source)
If Rails is installed, then it is loaded. Else, the script will throw the error you pasted in your question.
Yet, another alternative to RVM is the awesome rbenv tool.
It is very easy to install (just a simple brew install rbenv) and work with. In my opinion, it is the best way to manage your rubies on a Mac.
However, if you have rvm installed on your machine already, consider removing it from your system by doing rvm implode.
Since setting up a fresh ruby on rails dev environment is a common barrier to most newbies (including myself when i started off with rails) I've put together detailed instructions on how to do exactly that in a blog post, which i will link to below. Hope you will find it useful.
http://blog.parsalabs.com/blog/2013/08/27/setting-up-a-ruby-on-rails-4-development-environment-on-a-clean-mac-os-x-installation/
i got the same error and uninstall rvm then i follow the instructions on this page https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm
i think that help was
rvm requirements
on the terminal.
Our company uses a script to setup each new machine with a Rails dev environment:
We've open source it, give it a try: https://github.com/platform45/let-there-be-light
After a new
gem install rails
do
rbenv rehash
It worked for me.

Messed up Rails installation (OS X)

I had already installed rails 1.8.7, forgot about it, then installed 1.9.3 through RVM. I was getting weird errors, so I purged my Mac of the system version of Ruby and started again using RVM. So far I've
Installed Ruby:
rvm reinstall 1.9.3-p0
which ruby
/Users/User/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Manually setup Rubygems
which gem
/Users/User/.rvm/rubies/ruby-1.9.3-p0/bin/gem
Tried to install rails
sudo gem install rails
Successfully installed rails-3.2.1
1 gem installed
gem list
rails (3.2.1, 3.2.0)
It says rails is installed, but which gem does not work, and when I try to use rails new I get:
-bash: rails: command not found
I'm definitely missing something here. The only explanation I can think of is that there are remnants of a previous ruby or rails install that's causing problems. Is there a way to start completely from scratch?
If you are using RVM, you should not use "sudo" when you install gems. That will install gems to your system ruby version (not on the RVM rubies).
First, set up default rvm ruby like
rvm use ruby-1.9.3-p0 --default
Then, install rails on it by running:
gem install rails -v=3.2.1
It's actually better to use gemsets so you can have different gems set for the same ruby version. Check here for more info.

Every time I close terminal rails defaults back to 2.3.5 from 3.0.3?

I'm going through the rails by example tutorial.
Its seems that every time I close terminal rails defaults back to 2.3.5 & I have to go through the process of installing 3.0.3 every time I open the terminal?
I installed rails using: $ [sudo] gem install rails --version 3.0.3
Has anyone experienced a similar issue? I've tried googling around and searching stack to no avail.
The problem is almost-assuredly RVM interpreting 2.3.5 as your default rails version in your default gem set. I ran into this problem myself when first experimenting with RVM. Try this:
rvm --default use 1.9.2 (or whatever you want your default ruby interpreter to be)
rvm gemset create rails-3.0.3
rvm use 1.9.2#arails-3.0.3 --default
gem install rails
That will:
Set your default ruby interpreter to the desired ruby version
Create a gemset for your Rails 3.0.3 install and make it your default gemset
Install rails
Once you close the terminal and open it back up, it'll load RVM's defaults, putting you back on Rails 3.0.3 again.
Try uninstalling the rails gem:
gem uninstall rails
If you are prompted to select a version, select 2.3.5 and leave the 3.0.3 version intact.
P.S: Are you using RVM? If not, I would highly recommend it.
I've had this problem using RVM, if you're using RVM do: $rvm 1.9.2 (or whatever ruby version you installed the rails 3 gem with).
Check the output of $ ruby -v when you seem to have access to rails3 and again $ ruby -v when you can only seem to get to v2.3.5. If it shows different versions of ruby then you most likley are using RVM.
#Ads If youre using RVM and you install rails using sudo like so
$ [sudo] gem install rails --version 3.0.3
youre doing it wrong. RVM depends on you using a ruby distro that was installed by RVM into your user directory. If youre using sudo, youre installing rails gem into your system-wide ruby.
So check that youre using the right ruby version by doing 'rvm info' and then do your 'gem install rails --version 3.0.3' without sudo

Resources