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

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!

Related

Ruby on Rails - Errno::EACCES (Mac 10.9.1)

I installed Ruby (v. 2.1.2) and Rails (v. 4.1.4). When i try to start server (using the command rails s) I get an error:
`Could not find columnize-0.8.9 in any of the sources
Run `bundle install` to install missing gems.`
when i run the bundle install, i get:
`...Errno::EACCES: Permission denied # rb_sysopen - /Users/BBB/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/columnize-0.8.9/.gitignore
An error occurred while installing columnize (0.8.9), and Bundler cannot continue.
Make sure that gem install columnize -v '0.8.9' succeeds before bundling.`
and then i try gem install columnize -v '0.8.9'
i get permission denied~
`ERROR:While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/BBB/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/columnize-0.8.9/.gitignore`
does anyone have any ideas?
The /Users/bor-shyangsheu/.rvm/ is the directory that is in user home and it is a local path for the user (that is /Users/bor-shyangsheu/) and it should really be owned by 'bor-shyangsheu' user.
Therefore, installing stuff with sudo does not make any sense.
And, I guess the setup or the gem installation had been wrong before ( you might accidentally used sudo gem install before etc.) which have led you to the permission problem later on (including this one)
I think what you should do now is.
Check what group that the user 'bor-shyangsheu' belongs to.
id bor-shyangsheu
or just type id if you're currently logged in as 'bor-shyangsheu'
Change all of the directorys and files owner to be owned by bor-shyangsheu and his group by
sudo chown -Rf bor-shyangsheu:<group name> /Users/bor-shyangsheu/.rvm/*
For instance, if the group name is 'staff', run this command
sudo chown -Rf bor-shyangsheu:staff /Users/bor-shyangsheu/.rvm/*
Always use gem install <gem name> later.
Hope this clarifies thing a bit more.
You may try deleting the "Gemfile.lock". You can learn more at Bundler.io.
After developing your application for a while, check in the application together with the Gemfile and Gemfile.lock snapshot. Now, your repository has a record of the exact versions of all of the gems that you used the last time you know for sure that the application worked. Keep in mind that while your Gemfile lists only three gems (with varying degrees of version strictness), your application depends on dozens of gems, once you take into consideration all of the implicit requirements of the gems you depend on.
This is important: the Gemfile.lock makes your application a single package of both your own code and the third-party code it ran the last time you know for sure that everything worked. Specifying exact versions of the third-party code you depend on in your Gemfile would not provide the same guarantee, because gems usually declare a range of versions for their dependencies.

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.

Not able to view site in browser with railsinstaller due to missing Gem

I am super, super new at programming and I have been trying to get everything set-up on my computer. I have installed RailsInstaller, go to >railsinstaller_demo, and type in rails s. I get the following error though could not find gem 'uglifier <>= 1.0.3> x86-mingw32'
I looked through the forum and found how to do a gem list and i noticed it was not there. I then went to gembundler and ran $ gem install bundler. I tried again but it did not work.
I am sure the answer is on this site, but i am so new that i see all these lines of code I actually have no idea where to type it in.. I am running Windows 7.
thanks for taking the time to help out a real beginner.
Have you gone to the $ railsinstaller_demo directory and run the bundle install command? This will install the gem dependencies for the application; you will not be able to run the server until you've bundled the gems. Additionally, if you're still having issues with the uglifier gem, go ahead and remove the line in the Gemfile and then run bundle install
If you need further help with the Command Prompt, you an find out more at http://bit.ly/ZajVeW.
Thanks,
Evan

ZenTest Error in Rails

I am following the tutorial on railstutoiral.org and encounter the following error: "ZenTest is not part of the bundle. Add it to Gemfile. (Gem::LoadError)." I have ZenTest (4.4.2) installed according to gemlist so what's wrong? Thanks!
Open 'Gemfile' in the root of your rails application, and add a section like this to the bottom:
group :development, :test do
gem 'ZenTest'
end
Then at the command line, type:
bundle install
This command will install the gem and associate it with your application. It might take a few minutes :)
The cause of your problem is that under rails 3, rubygems are managed by a tool called bundler, which manages all the dependencies between your gems and ensures that your application is always started with the right versions of the right gems, even when you move it between servers.
One more thing to note is that if you want to run a command from a gem you've installed using bundler, you need to type 'bundle exec <command>' to ensure the right environment is established to run the command.
Even if you have it installed it isn't getting loaded because it says it isn't in the Gemfile. The Gemfile exists at the root of your project directory.

Uninstalling rails and gems, getting error "cannot uninstall, check 'gem list -d ...'

I'm going to start with the usual noob line, "I'm new to rails". Oh, and I'm running Mac OSX 10.6.4
I've been following a bunch of guides to get set up, specifically these two here and here. The guides are great, the reason I'm using the second one is because of RVM and the reason I'm using the first is for MYSQL.
Anyway, when I started, I wasn't following the directions completely and so after I installed RVM, for some reason I installed rails with sudo gem install rails -v 2.3.8 because thats the version I need. So... I realized I was using the system ruby, and wasn't taking advantage of RVM. What I did now was install Ruby 1.9.2 so I can install rails 3 and test it out, and I also installed 1.8.7 and rails 2.3.8 so I can use it for what I need it.
Now, I'm trying to uninstall the gems from the system Ruby, but whenever I try to I'm getting this error:
ERROR: While executing gem ...
(Gem::InstallError)
cannot uninstall, check 'gem list -d
whatever gem I try to uninstall'
Any ideas on how to remove rails and all these gems? I just want to start from scratch with RVM.
UPDATE:
By running the command gem list -d rails I've located the gems in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/18. Should I delete them manually?
SOLUTION!! I still don't understand why this happened, I'd love if someone could explain. Why was the path non-existant? What caused this error?
Also, I want to mention that the solution I linked to has a comment saying that the question is a duplicate. However, the original has a different solution and did not help me (though its the basis to finding this answer). Simply deleting the gems manually in finder would not remove them from the gem list.
Without further ado - it turns out that when trying to uninstall the gem, it can't locate its path (I think the problem is because of installing with sudo, but I might be wrong). What you need to do is (you have to do this one by one for each gem, or at least I had to):
gem list -d 'name of gem' and note the "Installed at:" location (in my case, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8)
sudo gem uninstall 'name of gem' -i 'the path noted above' (ex. in my case, sudo gem uninstall rails -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Some gems still might not uninstall returning a permissions error. If this is the case, what you need to do is create a folder /bin, in the path above. (in my case, mkdir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/bin
Continue uninstalling as in step 2, still using the original path (/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8).
Now all uninstalls should work!
Two things you should note when using rvm:
You should NEVER use sudo to install gems, just do a gem install xxx
You can not uninstall gems installed in the global gemset from within another gemset. You should switch to the global gemset and uninstall from there:
rvm gemset use global
gem uninstall xxx
execute this either in irb or in a script proper:
`gem list --no-versions`.split("\n").each do |gem|
`gem list -d #{gem}`.gsub(/Installed at(.*):.*/).each do |dir|
dir = dir.gsub(/Installed at(.*): /,'').gsub("\n", '')
system "gem uninstall #{gem} -aIx -i #{dir}"
end
end
try this way :
sudo apt purge rails
ok i see....
at this point, if you're in the terminal, it shouldn't take but a few minutes to reinstall the whole shebang
I suspect you might not be in the correct rvm name that has the gems you're trying to install so thats why i'd suggest reinstalling rubygems and building you're core gems from the beginning in your Global rvm gemset name.
A more generic answer to delete all gems for older versions of gem 1.8.
gem list --no-versions | xargs sudo gem uninstall -aIx
I was using RVM to manage my gemsets and had not selected the gemset. I wasn't that I had selected the wrong gemset, it was that I hadn't selected the gemset at all. A lovely way to spend the bulk of an hour of my first morning back after my summer holidays!

Resources