Uninstalling Ruby gems - ruby

user#machine:~$ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.8)
did_you_mean (1.0.0)
io-console (0.4.5)
json (1.8.3)
minitest (5.8.4)
net-telnet (0.1.1)
power_assert (0.2.7)
psych (2.0.17)
rake (10.5.0)
rdoc (4.2.1)
sass (3.4.23)
test-unit (3.1.7)
user#machine:~$ sudo gem uninstall rake
ERROR: While executing gem ... (Gem::InstallError)
rake is not installed in GEM_HOME, try:
gem uninstall -i /usr/share/rubygems-integration/all rake
user#machine:~$ sudo gem uninstall -i /usr/share/rubygems-integration/all rake
Remove executables:
rake
in addition to the gem? [Yn] Y
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/share/rubygems-integration/all/bin directory.
user#machine:~$ ls /usr/share/rubygems-integration/all/
specifications
user#machine:~$
I can not uninstall this gem in particular, neither use it :(
If seems that it doesn't exist.
My ruby verison is 2.3.1.p112

Ideally you would use RVM or rbenv to create a local sandbox and handle your Ruby install and gems instead of the system default. Then you won't have to use sudo you can just use gem uninstall <gem>. It doesn't let you have access for a reason, so it's harder to accidentally mess up the system Ruby.
If you can just read these install directions to get set up with RVM and then install the gems you used previously in your new environment. It'll save you a lot headaches in the future managing Ruby and gems.
--
If you don't want to do that you could try this answer
Try this answer from this related question.
gem list -d 'name of gem' and note the "Installed at:" location
sudo gem uninstall 'name of gem' -i 'the path noted above'
If it still returns a permissions error. Create a folder /bin, in the path above. 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).

sudo is not a magic wand that casts a spell “do it anyway.”
When you list your gems, you execute plain gem list from the user. It lists gems installed for the user. Afterwards you try sudo gem uninstall rake. Why do you expect superuser’s list of gems being the same as user’s one?
To remove user’s gems, listed with gem list, use gem uninstall rake. Without sudo.
To list superuser’s gems, that you were tried to remove with sudo gem uninstall rake, use sudo gem list. With sudo.
More info on sudo: http://aplawrence.com/Basics/sudo.html

Related

OS ruby labs/ PATH installation problems

I am supposed to install ruby labs on my computer and the instructions given to me are found here: http://ix.cs.uoregon.edu/~conery/eic/software.html
However, I'm facing problems downloading the ruby labs gem. The command given was:
gem install --user-install rubylabs -n .
I keep receiving these errors:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Users/Admin/.gem/ruby/1.8 directory.
I then did sudo gem install --user-install rubylabs -n .
But i got this error instead:
Successfully installed rubylabs-0.9.8
Installing ri documentation for rubylabs-0.9.8
/Users/Admin/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block
/Users/Admin/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block
Furthermore, after proceeding on with ruby lab-setup.rb, when I type irb, i receive this error as well: no such file to load -- rubylabs
===============================
Apparently it was my RVM that was causing the problem and deleting it solved the above problem. However, I would like to understand why RVM cause those issues.
Could someone please help? I'm at my wits end.
Thanks
I just had this issue as well:
no such file to load -- rubylabs
ruby lab-setup.rb basically adds lines to require rubygems and rubylabs on each new IRB session. The above no such file to load basically meant that rubylabs is not installed locally in rvm. A gem list command would reveal something like the following:
MBA:~ user$ gem list
*** LOCAL GEMS ***
gem-wrappers (1.2.4)
rvm (1.11.3.9)
I am new to Ruby as well... So what I did was basically just run the following command to install rubylabs:
gem install rubylabs -n .
A gem list would reveal it as installed:
*** LOCAL GEMS ***
gem-wrappers (1.2.4)
rake (10.1.1)
rubygems-test (0.4.3)
rubylabs (0.9.8)
rvm (1.11.3.9)
IRB will now run normally.

Ruby json gem not showing after install

So I installed the json gem using:
sudo gem install json
Everything appeared to install correctly, but when I call gem list I get this:
bundler (1.2.1)
hpricot (0.8.6)
i18n (0.6.1)
mail (2.4.4)
mime-types (1.19)
polyglot (0.3.3)
rack (1.4.1)
rack-protection (1.2.0)
rake (10.0.0)
rubygems-bundler (1.1.0)
rvm (1.11.3.5)
sinatra (1.3.3)
tilt (1.3.3)
treetop (1.4.12)
As you can see there is no json gem, and it is making it so I can run my Ruby Program. Any help would be great!
You installed JSON using sudo but it appears you're running RVM. Under RVM, using sudo to install gems, is a big NO-NO and causes this sort of problem.
sudo gem install json installed it over the pre-existing JSON in your system, not into the RVM-controlled Ruby.
Do it again, but do NOT use sudo and see what happens.
And, unless you understand what's happening with sudo gem install json or some other gem, don't use sudo gem install or sudo gem remove.
EDIT:
Per the Troubleshooting page on RVM's site, here's how to remove the system-wide installation:
#!/bin/bash
/usr/bin/sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm /usr/local/bin/rvm
/usr/bin/sudo /usr/sbin/groupdel rvm
/bin/echo "RVM is removed. Please check all .bashrc|.bash_profile|.profile|.zshrc for RVM source lines and delete
or comment out if this was a Per-User installation."
If you need sudo permissions to install a gem you should use: rvmsudo
In this case, it fixed my problem without having to reinstall everything.

How to reinstall a gem using bundler

I did a bundle show and get the complete path to a gem directory.
Unfortunately, I removed the directory using rm -r gem_path. Then my rails app isn't working anymore. If I try start server or start rails console it outputs the following error:
<class:Application>: uninitialized constant MyAPP::Application::Gem (NameError)
What should I do to have it back?
I tried bundle install or bundle update in hope of forcing the bundle to search the gem and install it back, but didn't work.
I also tried delete the Gemfile.lock and run bundle install. Nothing changed, same error.
The gem in question is Act as taggable on.
If using rbenv, this will let you completely uninstall and re-install a gem such as rmagick:
First: Try a simple uninstall/reinstall
gem uninstall rmagick
bundle install
If that doesn't work, you can remove all trace of the installed gem. Find your gem installation location:
bundle show rmagick
BUNDLE_DIR=$(dirname $(dirname $(bundle show rmagick)))
echo $BUNDLE_DIR
Your gem installation prefix will either be the default e.g. ~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0 or something you set e.g. .vendor
Clear out the gem directory:
rm -rf $BUNDLE_DIR/gems/rmagick-*
Clear out the compiled gem cache:
rm $BUNDLE_DIR/cache/rmagick*.gem
Also clear out bundler's spec cache:
rm $BUNDLE_DIR/specifications/rmagick*gemspec
Then you can re-install:
bundle install
You can always use:
gem pristine acts-as-taggable-on
pristine - Restores installed gems to pristine condition from files located in the gem cache
If you just want to restore the gem for the current project you should run:
bundle exec gem pristine acts-as-taggable-on
First I did a gem q --L, the shortcut for gem query --local. It outputs me the all the local gems installed.
actionmailer (3.2.8, 3.2.6, 3.2.1, 3.1.0)
actionpack (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activemodel (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activerecord (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activeresource (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activesupport (3.2.8, 3.2.6, 3.2.1, 3.1.0)
acts-as-taggable-on (2.3.3)
...
And then, following DVG advice, I uninstalled the gem using its correct name gem uninstall acts-as-taggable-on and ran bundle install. After that I was able to rails c or rails s again without any problem.
From project directory in terminal
gem uninstall gem_name
If using RVM with gems in ~/.rvm/, this works if bundle is not re-installing a gem.
First, delete the gem source:
bundle show $GEM
rm -rf $PATH_TO_GEM
Clear out the compiled gem cache:
rm -rf ~/.rvm/gems/ruby-$RUBYVERSION[#$GEMSET]/cache/$GEM.gem
Also clear out bundler's spec cache:
rm -rf ~/.rvm/gems/ruby-$RUBYVERSION[#$GEMSET]/specifications/$GEM*gemspec
Then you can re-install:
bundle install
bundle exec gem uninstall <gem_name> - uninstalls gem from the bundle (the <app_root>/vendor/bundle/ruby/2.3.0/gems/ path). This is equivalent to the answer #ioquatix gave, but is the slightly more convenient solution that he was looking for.
gem uninstall <gem_name> - uninstalls gem only from the global gemset in the system
If you've installed into ./bundle/vendor or similar, you need to remove the gem first but explicitly specify the GEM_HOME, e.g.
GEM_HOME=./vendor/bundle/ruby/2.3.0/ gem uninstall rmagick
This is by far the simplest way to uninstall gems installed using bundler into a vendor directory. Ideally, there would be a command bundle uninstall or bundle reinstall, etc.
If your goal is to simply reinstall, the following command will help:
GEM_HOME=./vendor/bundle/ruby/2.3.0/ gem uninstall rmagick && sudo -u http bundle install
If you're like me and have several web-applications under a directory (e.g. /srv/http), the following does it in all directories:
cd /srv/http
for d in ./*/ ; do (cd "$d" && sudo -u http GEM_HOME=./vendor/bundle/ruby/2.4.0/ gem uninstall --force rmagick && sudo -u http bundle install); done
If you're trying to reinstall rake, gem pristine rake will fail with Skipped rake-10.X.X, it is a default gem and bundle won't install it either, because it can't uninstall it.
If you're using rvm, it seems the easiest was is simply to do a rvm reinstall 2.x.x. At least for me, rvm repair all also didn't help.
The same probably goes for all other default gems. I'll just list them here so that the desperate googlers find some help:
bigdecimal
drip
io-console
json
minitest
psych
rake
rbtree
rdoc
test-unit

Can't remove execjs gem

I am using Ruby and I am having trouble removing a gem. The gem is execjs. Here is some background information.
rvm use #global
rvm gem list
Outputs...
*** LOCAL GEMS ***
...
execjs (1.2.9)
...
Running either of the following commands
rvm gem uninstall execjs
OR
rvm gem uninstall execjs -v 1.2.9
outputs this
INFO: gem "execjs" is not installed
So it showed the gem in the gem list, but when I go to uninstall it, it says that it isn't there. I'm confused ?
You should use this command for remove any gem
gem uninstall execjs -v=1.2.9
Hope it will work.

How to remove installed ri and rdoc?

How can I remove the ri and rdoc of installed gems? Thanks
You can simply remove the doc directory in the RubyGems installation directory.
rm -r `gem env gemdir`/doc
On Mac OS X by default, it's /Library/Ruby/Gems/1.8/doc.
Keep in mind that there might be several installation directories for RubyGems.
RubyGems will try to install to your user directory (something like ~/.gem/ruby/1.8/) if it can't access the normal installation directory (e.g. you installed a gem without sudo).
RVM also installs RubyGems for each Ruby it installs which will contain a doc directory containing rdoc and ri files (e.g. ~/.rvm/gems/ruby-1.9.2-preview1/doc).
This will merely remove existing files, but new ones will come with new installations anyway, unless you use the --no-document flag for gem install or make it a default.
It worked for me when I tried this:
gem rdoc <gem name> --no-ri --overwrite
Then you can remove only ri of the gem, and leave the gem itself. I don't see we need any other way around for this.
I just had this problem to, after thinking it would be a good idea to have some local rdoc for the train etc, I completely filled up my disc!
So, I bit the bullet, and did it (the hard way).
First, this is how I got in this stupid predicament :-
$ gem install rdoc-data
$ rdoc-data --install
$ gem rdoc --all --overwrite
To undo this, I thought I'd uninstall the gems, and then install them as needed (but without rdoc!)
Get list :-
$ gem list
*** LOCAL GEMS ***
aasm (2.1.1)
actionmailer (3.2.3, 3.2.2, 3.1.4, 3.1.3, 3.1.1, 3.1.0, 2.3.8, 2.3.5)
actionpack (3.2.3, 3.2.2, 3.1.4, 3.1.3, 3.1.1, 3.1.0, 2.3.8, 2.3.5)
active_support (3.0.0)
... +100 ...
Copy and search/replace \(.*\) with '\'
Bulk uninstall :-
$ gem uninstall actionmailer \
actionpack \
active_support \
... 100 more ...
ZenTest \
-a -x -I
Watch as the disc gains GB's of free space! (~11GB!)
Twas a stupid idea in the first place, and my solution may be just as much so, but it worked.

Resources