Uninstalled old version of rails and now no longer have rails executable - ruby-on-rails

Working in Nitrous.IO, my rails app was acting strange. So I checked and I was using rails version 0.9.5 instead of version 4.0.1! I decided to do a gem uninstall rails --version 0.9.5. Everything is good, except it also removed the rails executable! How do I get that back? Seems like version 4.0.1 is there, but I can't run the rails command. Should I just uninstall and reinstall rails?
UPDATE: Tried gem install rails even though I already had rails 4.0.1 installed:
action#creativebox-45198:~$ gem install rails
Successfully installed rails-4.0.1
1 gem installed
action#creativebox-45198:~$ rails -v
-bash: rails: command not found

Should be fine running gem install rails.

This issue has been resolved through Nitrous support channels. Somehow the file /home/action/.rvm/gems/ruby-2.0.0-p247/bin/rails was missing, and gem install rails did not add it. Manually adding this file with the following contents solved the issue.
#!/usr/bin/env ruby_noexec_wrapper
#
# This file was generated by RubyGems.
#
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
end
end
gem 'railties', version
load Gem.bin_path('railties', 'rails', version)

Try hash rails if you're using Bash, or rehash rails for csh, at the command-line.
Sometimes the shell loses track of where files are and (re)hash tells the shell to figure it out.
Do a search for hash + shell or use man hash for more information.

Related

Could not find a valid gem 'rails' (>= 0) in any repository

Does anybody else spend more time wrestling with rails than actually coding with it??
Very new to rails and programming in general, so I apologize if this is a stupidly easy question. I don't know enough to understand what's wrong here.
I upgraded to ruby 2.2.2 and somehow lost rails in the process. I don't know why. Now every time I try to load it again, I get the following:
Could not find a valid gem 'rails' (>= 0) in any repository
I've tried sudo gem install rails and gem install rails to the same effect. I've already checked similar postings here, here, here, here, and here to no effect.
How can I fix this and move on?
Macbook pro 10.10.3
Ruby 2.2.2
Chases-MacBook-Pro:pinteresting Chase$ sudo gem install rails
ERROR: Could not find a valid gem 'rails' (>= 0) in any repository
Chases-MacBook-Pro:pinteresting Chase$ gem install rails
ERROR: Could not find a valid gem 'rails' (>= 0) in any repository
Chases-MacBook-Pro:pinteresting Chase$ bundle install
-bash: bundle: command not found
Chases-MacBook-Pro:pinteresting Chase$
edit
I'm behind a VPN, but that shouldn't make a difference because I've checked this several times and it has never been a problem for coding in the past. Since I live in China I have to use VPN a lot, but most of the coding sites are open.
Right now I'm systematically going through each solution and copying down the error messages.
Here's what happened when I did everything at this link
ERROR: Could not find a valid gem 'rails' (>= 0) in any repository
1) railsinstaller.org = the packages are out of date. Nothing over 10.6. Does that matter?
2)where ruby? = -bash where: command not found
3)rvm gem install rails = Please note thatrvm gem ...was removed, trygem install railsorrvm all do gem install railsinstead. ( see: 'rvm usage' )
4) gem install rails = could not find a valid gem 'rails' (>= 0) in any repository.
5) rvm all do gem install rails
= nothing. It just sat there and didn't seem to do anything.
6) curl -L https://get.rvm.io | bash -s stable --autolibs=enabled [--ruby] [--rails] [--trace]
= A bunch of information but no action. I opened to new terminal window 10 minutes ago and it still hasn't done anything.
7) curl -L https://get.rvm.io | bash -s stable --rails
= installs rvm and then ends with the same error could not find a valid gem for rails
8) gem sources -a https://rubygems.org = added the site to the sources... idk if that will change anything...
no change after following all the previous steps
Since I know rails is not on my computer and something might have changed since I did the steps above, I just set my VPN to a new setting and used sudo gem install rails. This appears to have installed rails and many gems, however...
I then ran rails -v and got the following error:
[!] There was an error parsingGemfile: no .<digit> floating literal anymore; put 0 before dot - gem 'rails', 3.2.11
^
/Users/Chase/Desktop/pinteresting/Gemfile:4: syntax error, unexpected tINTEGER, expecting '('. Bundler cannot continue.
# from /Users/Chase/Desktop/pinteresting/Gemfile:4
# -------------------------------------------
#
gem 'rails', 3.2.11
# gem 'sass-rails', '~> 5.0'
# -------------------------------------------`
I solved the same problem as follows:
gem source -a http://rubygems.org/
I think the reason is about https.
After trying all the steps I listed earlier, I connected to VPN through a new setting. The one I was using only routed the VPN through my browser, but the new one affects the entire internet connection. I think this is what finally allowed me to download rails again.
After downloading rails, it was just a matter of messing with the Gemfile to get everything downloaded, and voila!

Why won't Rails 4 uninstall?

After uninstalling Rails 4(RC1) I still get Rails 4 apps generated with rails new.
➲ rails -v
Rails 4.0.0.rc1
➲ which rails
/Users/brandon/.rvm/gems/ruby-1.9.3-p392/bin/rails
➲ gem uninstall rails
Select gem to uninstall:
1. rails-3.2.13
2. rails-3.2.3
3. All versions
>
What's the cleanest way to fix this?
It is quite easy.
gem uninstall rails -v=4.0.0.rc1
gem uninstall railties
gem install rails -v 3.2.13
gem update --system
rails -v
By using commands above I was able to install older version of rails as needed :)
Rails does not come as an all-in-one package. You have a base Rails gem, plus it's many dependencies:
Action Mailer
Action Pack
Active Record
Active Resource
Active Support
Bundler
Railties <---- (contains generators)
Sprockets adapter for Rails
To get rid of your Rails 4 installation as a whole, you must remove all of these gems.
The easiest way to do this is to delete your entire gem folder, then reinstall whatever you need.
Try specifying your installed version:
gem uninstall rails -v=4.0.0.rc1
EDIT:
If you've already uninstalled (which you have), the following should work:
gem update --system
rails _3.2.2_ new app_name # or whatever version you're on
Fortunately, this worked as a simple fix for me:
Please note that in order to shift back to 3.2.13 (or whatever version you'd like to go back to), you must remove Railties as well as Rails.
Just do:
gem uninstall rails
Then, select the version of Rails 4 you have and delete it.
Then, do:
gem uninstall railties
And do the same thing.
When I uninstalled the Rails 4 version of railties, it told me that dependencies for a couple gems (coffee-rails and sass-rails) wouldn't be met. So I just did the same thing with both of them as I did above (such as, gem uninstall sass-rails), and deleted their Rails 4 versions as well. For example, for sass-rails, I had a version installed called sass-rails-4.0.0.rc1, so I uninstalled that version).
And that's it; the terminal will list 3.2.13 as your current Rails version, and new apps will be generated from this version as well.
TL;DR:
The simplest and safest solution to the immediate problem is
gem uninstall railties
Slightly Longer & More Complete Approach
If you want to uninstall everything that gem install rails installed, you can get a list of commands to run with this:
gem dependency rails --pipe | ruby -ne 'puts $_.gsub(/\([0-9\. <>=~,]*\)/,"")' | ruby -ne 'puts "gem uninstall #{$_}"'
Copy those and run them one-by-one, and for each one you'll be told what else depends on it, and asked if you want to go ahead with uninstallation. If you see anything in the list that is not part of rails (say you've installed something else that needs that version of active_record) then leave it, otherwise go ahead and uninstall.
The longer explanation
The version displayed is taken from the version of the railties gem, which is not uninstalled by uninstalling the rails gem.
If you open the rails executable with
vim `which rails`
(or the equivalent with the editor of your choice) you'll see the code at the bottom that decides which version of rails to use based on the version of railties:
#!/usr/bin/env ruby_noexec_wrapper
#
# This file was generated by RubyGems.
#
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
end
end
gem 'railties', version
load Gem.bin_path('railties', 'rails', version)
The simplest solution, therefore, is just to gem install railsties. There is no solution built-into RubyGems (that I can find) that will detect which other gems were installed with rails and are no longer used by anything else and uninstall them. RubyGems does not have the idea of an exclusive dependency, so even though nothing else besides rails uses railties, you're still stuck having to know that it (and several other things) are left over and must be manually uninstalled. This is not ideal, but it's what we've got right now, and it's not that bad, especially if you use the solution above to find and remove all the rails dependencies.

Error while running rails on windows 7

I am trying to set my machine up so I can follow this tutorial: the intro to rails screen-cast i wish i had.
I keep running into issues, most recently the following:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ansi-1.4.1/lib/ansi/code.rb:5:in `require':
no such file to load -- Win32/Console/ANSI (LoadError)
This occurs when ever I run rails g. (I would like to see if my r spec generator has been added.)
Environment details: Windows 7, ruby 1.9.2p290, rails 3.1.1, rubygems 1.8.15
After you installed "gem install win32console", can you add this gem into your Gemfile file and try to run bundle install again?
Gemfile
gem "win32console", "~> 1.3.0"
RailsInstaller may be your best bet if you're looking for an integrated Windows Rails experience.
It's up-to-date (-ish, doesn't use Ruby 1.9.3) with:
Ruby 1.9.2-p290
Rails 3.1.1
Git 1.7.6
and other useful bits.

Can I change the expected Rails version of a Rails application?

I downloaded an archive containing code for a Rails application ( from a book I'm reading ). I'm running Rails 3.0.1 but the application fails to start, because it's looking for 3.0.0beta3. Is there some way of starting it with my version of Rails?
Yes, look for the Gem file in the application root and look for the line
gem 'rails', '3.0.0beta3' and change it to
gem 'rails', '3.0.1'
then run bundle install from a terminal in your application root.
this is because your Gemfile.lock is probably showing Rails 3.0.0.beta3. Even if you change your Gemfile to 3.0.1 AND install it using gem install rails, you will need to run bundle install or bundle update rails
There is probably a line in the environment.rb file that looks like
RAILS_GEM_VERSION = '3.0.0beta3' unless defined? RAILS_GEM_VERSION
Updating this should sort your issue.

How to use the Rails 2.3 app generator when I have Rails 3 installed?

to clarify: there's only one rails command, which gets installed from the latest Rails gem, which is Rails 3 ATM. However, I'm required to create a Rails 2.3 app.
Running ruby /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails fails with a NoMethodError, I suppose because it also tries to use gems from the 3.0.0 release.
Uninstalling the gem produces some strange results:
$ gem uninstall rails-3.0.0
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rails-3.0.0`
$ gem list -d rails-3.0.0
*** LOCAL GEMS ***
(and no gems here)
What should I do?
The easiest way to do it was:
Create the directory for the project
Create a Gemfile there containing
gem "rails", "2.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
Run bundle install
Run bundle exec rails . to create an app in the current path
You don't even need rvm to do this.
(I assume 2.3.11, given it's the latest)
rails _2.3.11_ new app will do this for you without you having to muck about.
(Had to make a comment since I don't have enough Stack Overflow cred and can't directly respond to answers yet.)
For folks running rails 3 now the "new" command is now required for creating new rails applications. As such "new" will need to be appended to the end of the commands.
So for Leonid Shevtsov's answer, Step 4: bundle exec rails new .
And for Robert Speicher's answer: rails new .
Install rvm and then create a new gemset, so that Rails 2 is isolated.
Or, go to the directory where you want your Rails 2 app to be, create a Gemfile like a Rails 3 app, but specify gem "rails", "~> 2.3" and run bundle install, and you should now be able to issue rails .

Resources