Removing Gems errors

2019-02-21 01:14发布

问题:

I have 2 versions of rubies using RVM and i am trying to remove all my gems which in this ruby version 1.8.7-p302

first i tried this but i got error

➜  ~  gem list | cut -d" " -f1 | xargs gem uninstall -aIx
Successfully uninstalled actionmailer-2.3.5
Successfully uninstalled actionmailer-2.3.18
Successfully uninstalled actionpack-2.3.5
Successfully uninstalled actionpack-2.3.18
Successfully uninstalled activerecord-2.3.5
Successfully uninstalled activerecord-2.3.18
Successfully uninstalled activeresource-2.3.5
Successfully uninstalled activeresource-2.3.18
Successfully uninstalled activesupport-2.3.5
Successfully uninstalled activesupport-2.3.18
Removing bundle
Successfully uninstalled bundler-1.3.5
ERROR:  While executing gem ... (Gem::InstallError)
    cannot uninstall, check `gem list -d bundler-unload`

then i tried this also an error

➜  ~  gem list --no-version | xargs gem uninstall -aIx
zsh: correct 'gem' to '.gem' [nyae]? n
ERROR:  While executing gem ... (Gem::InstallError)
    cannot uninstall, check `gem list -d bundler`

My Gemlist:

➜  ~  gem list                                                                                 

*** LOCAL GEMS ***

bundler (1.3.5)
bundler-unload (1.0.1)
declarative_authorization (0.5.1)
fattr (2.2.1)
i18n (0.4.2)
mysql (2.9.1, 2.8.1)
rack (1.1.6, 1.0.1)
rails (2.3.18, 2.3.5)
rake (10.1.0, 0.8.7)
rubygems-bundler (1.2.2)
rush (0.6.8)
rvm (1.11.3.8)
session (3.1.0)
sqlite3 (1.3.8)

Update:

I have tried to remove ruby 1.8.7 then install it but the gems still there when i type i got this

➜  ~  rvm gemset empty default
Are you SURE you wish to remove the installed gems for gemset 'ruby-1.8.7-p302' (/home/dexter/.rvm/gems/ruby-1.8.7-p302)?
(anything other than 'yes' will cancel) > yes
➜  ~  gem list

*** LOCAL GEMS ***

bundler (1.3.5)
bundler-unload (1.0.1)
rake (10.1.0)
rubygems-bundler (1.2.2)
rvm (1.11.3.8)
➜  ~  gem list --no-version | xargs gem uninstall -aIx   
zsh: correct 'gem' to '.gem' [nyae]? n
INFO:  gem "bundler" is not installed
INFO:  gem "bundler-unload" is not installed
INFO:  gem "rake" is not installed
INFO:  gem "rubygems-bundler" is not installed
INFO:  gem "rvm" is not installed

Now i can not install rails again !

➜  ~  gem rails -v '2.3.5'
ERROR:  While executing gem ... (RuntimeError)
    Unknown command rails

回答1:

USING RVM

1) Install rvm.

In the rest of the steps:

DON'T EVER USE SUDO

2) Install ruby (pick a version):

$ rvm install 1.9.3

3) Make sure rvm's current ruby is the version you want to use for your app :

$ rvm list

and if necessary:

$ rvm use 1.9.3-p194  #Sometimes you have to specify the patch number as well, e.g p194

4) Create a gemset for your app:

$ rvm gemset create myapp_gemset

5) You can list the gemsets for the current ruby version:

$ rvm gemset list

and if necessary switch to the gemset you just created:

$ rvm gemset use myapp_gemset

6) Install the rails gem:

$ gem install rails --version 4.0.0

That command will install the gem into the current gemset. You can check the version:

$ rails -v

There is a shortcut you can use to select the ruby version and a gemset you previously created for that ruby version:

$ rvm use 1.9.3-p194@myapp_gemset

You can also set a default ruby and gemset that will be selected when you open a new terminal window:

$ rvm use 1.9.3-p194@myapp_gemset --default

Or, you can set up your Gemfile in your app so that rvm switches to the specified ruby version and gemset when you change directories into your app's directory:

Gemfile:

ruby '1.9.3'   #(no patch number allowed here)
#ruby-gemset=myapp_gemset

rvm will read that comment in your Gemfile, and then switch to the ruby version on the previous line and the gemset specified in the comment.

. .

https://rvm.io/gemsets/deleting

Deleting Gemsets

When you delete a gemset, rvm will prompt you to confirm the deletion.

$ rvm gemset use albinochipmunk
$ rvm gemset delete albinochipmunk

To skip confirmation, pass the --force flag:

$ rvm gemset use albinochipmunk
$ rvm --force gemset delete albinochipmunk

By default, rvm deletes gemsets from the currently selected Ruby interpreter. To delete a gemset from a different interpreter, say 1.9.2, run your command this way:

$ rvm 1.9.2 do gemset delete albinochipmunk

.

If you don't use a gemset at all, you get the gems in the 'default' set

.

https://rvm.io/gemsets/emptying

Emptying Gemsets

If you empty a gemset, rvm will prompt you for confirmation. This action removes all gems installed in the gemset.

$ rvm gemset use albinochipmunk 
$ rvm gemset empty albinochipmunk 

To skip confirmation, pass the --force flag:

$ rvm gemset use albinochipmunk 
$ rvm --force gemset empty albinochipmunk


回答2:

RVM installs some gems in the global gemset you can uninstall those gems with:

rvm @global do gem uninstall gem_name

if you do not want to use any gemsets (except the single per ruby gemset) use: this:

echo rvm_ignore_gemsets_flag=1 >> ~/.rvmrc

and from now on RVM will use only single gemset - no global