How to completely wipe rubygems along with rails etc - ruby-on-rails

Ok, so I decided I'd be cool and try to use Rails3 that's in beta. Then, things were getting hard to manage so I got rvm. I installed ruby 1.9.2-head in rvm and things were working, and then a computer restart later rails wouldn't start up. So I figured I'd just try running the system ruby and start rails in it. same error. Then, I uninstalled rails3 and got rails: no such file or directory type errors..
So now I'm royally screwed because rails2 is still installed but will not uninstall because of invisible dependencies, along with a lot of other random gems. How do I completely clear out all ruby gems and such so I can start anew?

I've recently had to so just this. I had built up alot of cruft with my system installed ruby and gems and wanted to clean all that out and move everything over to run under rvm for various projects.
1. Clean up old and busted
First thing I did, before messing with rvm (or run rvm system to get back to the system ruby), was to remove all my gems:
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
WARNING: this will uninstall all ruby gems. If you installed as root you may want to switch to root and run this.
2. Install new hotness
Now you can run gem list to see what is left.
Time to install rvm, I recomend blowing away your current install and reinstall fresh:
rm -rf $HOME/.rvm
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Now the real trick is to use gemsets to install rails 3, and this is easy if you follow Waynee Seguin's gist:
rvm update --head
rvm install 1.8.7
rvm --create use 1.8.7#rails3
curl -L http://rvm.beginrescueend.com/gemsets/rails3b3.gems -o rails3b3.gems
rvm gemset import rails3b3.gems
One difference is I use 1.8.7 since I have had issues with 1.9.2-head and RSpec, but 1.8.7 has been smooth.

You say that you already got Rails 2 and afterwards installed rvm. Try if you can remove Ruby and Rails using the package manager of your system (yum, apt, ...)
The error you got is most likely the result a link in some general place which still exists, but is pointing to the real installation directory which no longer exists.
For example: /usr/bin/ruby exists and is pointing to /usr/local/lib/ruby/1.9.2/bin/ruby which no longer exists.
Afterwards manually clean out any Ruby and Rails related paths in /usr and its subdirectories.

Related

Rails - Closed terminal and rebooted machine - now bash tells me rails isn't installed

Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)
I'm working through the railsapps.org book on learning rails and made it about 1/2 way through yesterday. When I stopped for the day, I closed out iTerm2 and shut off the Macbook Pro. Today, I powered up, opened iTerm, navigated to my working directory (~/rubyonrails/learn-ruby) and entered rails -v.
I see this:
`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.`
So I run sudo gem install rails and it shows that it has installed rails-4.1.0. Now rails -v still gives me the same error message above.
I tried also running rvm use ruby-2.1.1#learn-rails first and I still get the error message.
So I'm a little stuck and I can't figure out what to do to get rails working. Also, how do I go about setting up the bash environment such that I don't have to go through this each time? It would be nice to nav to my working directory and just start work without having to do a bunch of re-installation and reconfiguration each time.
Regards,
Jeff
please type in your shell:
$ bash --login
and then repeat your commands.
rails -v
Also try to call it with the full path:
like:
/your/path/to/rails -v
I think that the shell just doesn't know where rvm/rails etc is located.
You can solve this by entering:
$ source ~/.rvm/scripts/rvm
When you switch to the ruby-2.1.1#learn-rails ruby/gemset combo, and do gem list, what do you see?
The way people usually use rvm is to have every project folder specify the ruby & gemset it uses (they don't all have to be different). This is done with files called .ruby-version and .ruby-gemset. These should contain, in your case, ruby-2.1.1 and learn-rails respectively.
Set these if you haven't already, then leave the folder and enter it again. Then do bundle install to install the gems for the project into the rvm/gemset combo.
Your problem is that you ran
sudo gem install rails
The error message telling you to do this comes from your system Ruby, which doesn't know that you want to use RVM.
RVM installs gems into your user-space directory. By using sudo, you're bypassing this and installing it into (effectively) the superuser space, i.e. globally.
If you instead just run
gem install rails
then you'll be using RVM's copy of the gem utility rather than the globally installed version.

Proper way to set up Rails app on local machine using existing Github repo and RVM

I've tried looking around the internet for a solution to this but to no avail. Every single time I try to set up a new app on my local machine I run into a ridiculous amount of issues with RVM. I decided its finally time I learn to do this right.
Basically I have been given permission to a Rails project in Github and I want to get it running properly on my local machine.
Generally speaking, what I have been doing in the past is this:
$ git clone git#github.com/projectpath
$ ls projectpath
$ bundle install
$ rake db:setup
And cross my fingers. Sometimes it works, other times I have to use RVM to change rubies and redo bundle install. Today, everything is breaking and I keep running into problems like this:
$ rails -v
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.
I have a feeling that I am not setting up these apps correctly and also not using RVM as its supposed to be used - basically I believe that my fundamental understanding of RVM is wrong. I would very greatly appreciate it if someone could outline the proper way to do set up a new app using a remote Github repo, as well as explain the proper way to use RVM to get this new app running. Thanks in advance!
I think your life would be easier if you used RVM's gemsets. One gemset per rails application. This keeps everything nice and isolated from each other.
So... something like this...
# install bundler in the global gemset as you want it available everywhere.
$ rvm use #global
$ gem install bundler
# create a project specific rvmrc/gemset.
$ cd /folder/containing/your/github/repo
$ echo "rvm use #myapp" > .rvmrc
$ cd into/rails/root/for/your/app
$ bundle install
At this point you're installing the gems into the 'myapp' gemset, totally isolated from your other gems. There's a new file name for .rvmrc, but I can never remember what it is. .ruby-version or something.
You may also need to create the gemset before it can be used. See the RVM docs for how to make that happen automatically.
Do these cloned projects have files named
.ruby-version
and
.ruby-gemset
in the top level directory? Those files instruct rvm (and other versioning systems) to use a particular ruby version and gemset combo. It could be sometimes you cd into a cloned directory that references the name of a gemset you've already created, in which case bundle and rake work, and sometimes it references a gemset you don't have, in which case you get mysterious blowups.

Rails - the newest gem is installed but the applicaiton is old

I'm working on Bluehost. I installed the 3.2.8 gem of rails, and now I get this:
> gem list --local | grep rails
rails (3.2.8)
But:
rails --version
Rails 2.3.11
How can I make the "rails" command use the latest gem? I guess it has something to do with my $PATH variable but I'm pretty much clueless about it.
Also, the gem and rails command give rise to some errors that look like this:
Invalid gemspec in [XXX]: invalid date format in specification: "YYY"
I'm not sure if that's connected (and I'm wondering what causes such errors anyway).
Try running this command:
curl -L https://get.rvm.io | bash -s stable --ruby --rails
What it does is install RVM, which maintains separate gems for each version of Ruby installed. The --ruby and --rails arguments tell it to install ruby and rails while installing RVM. RVM installation automatically updates $PATH and any other necessary environment variables.
At the end of installation, it should prompt you to run:
source ~/.rvm/scripts/rvm
which will make those environment variable changes effective immediately. Alternatively, you can log out and then log right back in.
Run rails -v and ruby -v at that point, and you should see them pointing to the new version. Run bundle install from your RoR app's directory and all the gems you need should install in ~/.rvm/gems/ruby-/gems.
At that point, you can delete/uninstall any gems/rails/ruby from before installing RVM.
EDIT on 10/17/2012:
Nevermind my answer. Even though it might be possible to get Rails 3.x running with the currently installed Ruby 1.8 (see this Stackoverflow question), you won't be able to run Ruby 1.9.x using Bluehost Shared Hosting. Your only choice (for now) is VPS Hosting.
The reason is that Passenger Phusion is tied to the version of Ruby installed in /usr/lib, which you can't change without root access. Even though you can install any version of Ruby with RVM, you won't get Passenger to talk to it and therefore your rails project won't use its gems.

Error when executing rvm rubygems latest

I'm adding ruby 1.9.2 to a Mac running 10.6.8 and hitting a problem with rvm rubygems latest. I've run the following with no problem:
$ rvm install 1.9.2
$ rvm use 1.9.2
$ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
Then hit this error:
$ rvm rubygems latest
Removing old Rubygems files...
Installing rubygems-1.8.10 for system ...
ERROR: Error running 'GEM_PATH=":#global" GEM_HOME="" "/usr/local/rvm/rubies//bin/ruby" "/usr/local/rvm/src/rubygems-1.8.10/setup.rb"', please read /usr/local/rvm/log/system/rubygems.install.log
WARN: Installation of rubygems did not complete successfully.
ln: /usr/local/rvm/rubies//lib/ruby/gems/: No such file or directory
The obvious thing here is the extra forward-slash in the bin/ruby and lib/ruby paths. Any ideas where this is coming from and how to fix it?
Note that I've also got the following line at the end of my .bash_profile file:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
I'm doing all of this so that I can run Octopress. I've also got a Rails 2.3.8 project that I am developing on this same machine. This is the first time I've dealt with anything other then the system version of ruby (1.8.7).
I've had the same problem, and although I didn't really fully understood why it was happening, attacking the main symptom solved it for me.
It seems that you have already another version of ruby installed on your system. The line on the rvm rubygems script that generates the error is this:
__rvm_run "rubygems.install" \
"GEM_PATH=\"$GEM_PATH:${GEM_PATH%%#*}#global\" GEM_HOME=\"$GEM_HOME\" \"${rvm_ruby_binary}\" \"${rvm_src_path}/$rvm_gem_package_name/setup.rb\"" \
"Installing $rvm_gem_package_name for ${rvm_ruby_string} ..."
https://github.com/wayneeseguin/rvm/blob/master/scripts/rubygems#L104
I think that internally rvm is losing itself and creating paths with the double slash on it, probably because RVM is appending the RVM local dir with the output of some command similar to which ruby (or whatever the path rvm is searching for may be). I really don't know why it does that (doesn't RVM work in a system with ruby installed?).
Anyhow, to fix that in my machine I simply ran sudo aptitude purge ruby (you would of course run the MAC equivalent of that), to remove the ruby version that was messing with rvm.
If you have something related with ruby installed on your computer, I think a good idea would be to remove them all, and use RVM to manage all your ruby related goodness.
On linux (debian/ubuntu), a good approach is typing dpkg -l | grep ruby to see which packages related to ruby are installed on your machine, and then purge them all.
After that, run
$ rvm use 1.9.2
$ rvm rubygems latest
Everything should work like a charm. At least uninstalling ruby worked for me.
Hope it helps.
I just ran rvm default which allowed everything to work properly. I fields is right that rvm hasn't set something completely or at all. This has actually fixed this problem for me consistently.

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