Reputation: 2058
I recently upgraded my distro (Ubuntu from 16.04 to 18.04), and I guess either on the upgrade or on the regular sudo update/upgrade
calls gem
was upgraded and I currently have the 2.7.6
version. I barely use Ruby lately, but just now I had to run a jekyll/bundle
command which returned me that it had a bad interpreter (it was looking for ruby2.3
and it's currently installed on the 2.5
version).
My next step would be updating the jekyll
and bundle
gems (so they update the interpreter version), but to my surprise they aren't listed when I run gem list
. They were obviously installed since there's a /usr/local/bin/jekyll
executable and a /usr/local/bin/bundle
one as well. But I think when gem
was upgraded it started checking gems on a different folder (/var/lib/gems/2.5.0
I'm guessing) but jekyll/bundle
apparently are in /var/lib/gems/2.3.0
. I'd be fine just installing jekyll/bundle
on the 2.5.0 version, but is there a way to remove all gem files from the older version since they are useless now?
Upvotes: 0
Views: 1645
Reputation: 2058
I'd like to thank both answers. I upvoted them because even though they're not a direct solution to my problem they give good directions to prevent it.
NOTE: These are the steps I took, which doesn't mean they are the correct way, so don't take more as a reference than a guide.
Here's what I did to clean up those old Ruby version gems:
gem
to be able to find those obsolete gems, by running GEM_PATH=/var/lib/gems/2.3.0
.gem contents name_of_gem
and gem specification name_of_gem
.sudo GEM_PATH=/var/lib/gems/2.3.0 gem uninstall -i /var/lib/gems/2.3.0 name_of_gem
. In my case I did a sudo
install, so I needed sudo
which also required me to set the environment variable again because of sudo
's security policy. Also, I needed to manually set the install directory for some reason.gem uninstall
to remove it because it claimed I didn't have write permission to /var/lib/gems/2.3.0/bin
(which is weird because the EXECUTABLE DIRECTORY
gem environment variable was /usr/local/bin
). I asked gem
not to remove the executables, wrote down their names and removed them manually from the EXECUTABLE DIRECTORY
folder. You can also use which gem_executable_name
to find out where it's located.After uninstalling all the gems I believe it's safe to remove the /var/lib/gems/2.3.0
folder and its contents. Running gem contents
on all of them only returned me files on this folder so I believe the only external files were the script/executables that were added to /usr/local/bin
.
Upvotes: 0
Reputation: 16687
Here's what I recommend:
rbenv
for multiple Ruby version management, no customizations needed
rbenv rehash
anymorervm
has a noticable load time on shell startup)Options to invoke bundler dynamically (I recommend the last one):
bundle exec
in front of every ruby executable
alias be='bundle exec'
bundle binstubs <LIST GEM EXECUTABLES YOU WANT>
for each project
bin/
in front of every ruby executable to call the binstubs.git/safe
bin/
folder while in that project rootbin/
anymoreNow multiple gem versions will all be installed into the same Ruby version bucket, and you let bundler dynamically add the right versions to the load path before every startup.
Removing a Ruby version will also mean removing all the gems (and versions of those gems) installed for that Ruby version as well.
Upvotes: 2
Reputation: 216
I highly recommend you to use a ruby version manager like rvm or rbenv to manage different ruby versions installed on your system.
If you just want to remove the gems from your disk, you can find the location of each gem with the command bundle show $gem_name
and delete the parent directory to delete all of them. You may need to delete the Gemfile.lock
as well to reset the locked gem versions.
Upvotes: 2