Remove version of Ruby/RubyGems and gems on MacOS properly - ruby

I recently installed a version of Ruby (and RubyGems) via homebrew on my Mac because the RubyGems that comes installed on Mac doesn't let you install gems due to permissions issues. I followed the instructions in the top answer in this thread: You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user)
After installing some gems, I realized that I don't need this version of Ruby and RubyGems anymore, so I ran brew uninstall ruby to get rid of them (I assume RubyGems gets deleted along with Ruby). However, I checked and it appears the gems I had installed are still in /usr/local/lib/ruby/gems/2.7.0. Can I just delete the usr/local/lib/ruby folder, and is this the correct way of going about it? I don't know if the default RubyGems that comes with MacOS uses this folder.

Basically when you run rbenv versions it will display all your ruby versions including the one installed by default (system).
system ruby usually located in /usr/local/lib/ruby/gems/2.5.1
rbenv ruby default location is inside user path ~/.rbenv/versions/2.5.1/gems
to uninstall ruby using rbenv you need to remove the specific version e.g rbenv uninstall 2.5.1
I suggest that you leave your ruby system installation, but you can remove all the gems inside the ruby system path manually /usr/local/lib/ruby/gems/2.5.1.

I'm the author of that top post in the link you mentioned. You are correct that Homebrew installs gems in /usr/local/lib/ruby/gems/2.7.0. You can confirm that in two ways:
You can run brew info ruby, and then visit the Formula page that's displayed: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ruby.rb
This is the line of code where the Rubygems directory is defined: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ruby.rb#L48
You can install Ruby again with Homebrew, and you should see this section in the terminal output:
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/2.7.0/bin
You may want to add this to your PATH.
I wrote about this in the Homebrew section of my definitive guide to installing Ruby gems on a Mac.
The system Ruby is NOT installed in /usr/local/lib/ruby. It is in /Library/Ruby/Gems/2.6.0. You can safely remove the /usr/local/lib/ruby directory. On a fresh macOS installation, the /usr/local directory is empty.
You can then check if Homebrew is still healthy by running brew doctor.

/usr/local/lib/ruby/gems/2.7.0 used to be brew default install path. Now they have changed it to /opt/homebrew/lib/ruby/gems/2.7.0. So you can delete the previous folder under /usr without a problem.

Related

Ran `brew install ruby` even though I'm already using rbenv, can I just run uninstall?

I haven't updated my version of Ruby in forever and when reading the instructions for a new gem I figured homebrew's install would probably update me to the latest ruby version. As soon as I hit enter I remembered I'm using rbenv to manage my versions. If I run brew uninstall ruby will that just delete the version I installed with brew and leave my rbenv setup alone?
rbenv and brew should be two different things. The location where rbenv installs its own ruby is completely different anyway.
Uninstalling your Homebrew installed Ruby shouldn't impact rbenv at all. It may mess up your path temporarily, so you may need to open a new shell window afterwards, though that depends on how Ruby was put into your path in the first place.

Cocoapod install does not add to PATH

I installed cocoapods on OSX 10.9.3 Mavericks.
The installation finished fine, but I cannot run the pod update command. as nothing was added to my PATH. I am trying to find the /usr/local/Cellar/ruby folder to find the pod file to put in my PATH, but no such folder exists.
Where is the cocoapod file installed, and what I need to add in my PATH to make it work?
Cocoapods is installed using Ruby Gems. If you do not have a previous Ruby installation, you can go ahead and install using SUDO, which will use the OSX system default Ruby installation. But if you have a local version of Ruby already running for whatever reason, using SUDO will not work as the pod binary will be installed in the System default Ruby folder instead of the local version where it should be really installed for all the PATH and environment variable to work correctly. Just using gem install should work in this case.
If you have a local version of ruby rvm
gem install cocoapods
instead of
sudo gem install cocoapods

Installing gem-bundle for Redmine 2.1.4 with Ruby 1.9.3 (including rmagick 2.13.1) on Windows

I'm having problems installing json or rmagick gems on Windows, which I need because I am trying to install Redmine 2.1.4.
As none of the procedures worked out-of-the-box for me and have struggled with it myself for a couple of hours, I thought I'd just ask here for help.
I'm assuming you don't have Ruby installed yet. If you do, as any of other components mentioned below, probably it's the wisest to uninstall them before proceeding with installation.
This tutorial should help you avoid problems with json and rmagick gems on Windows.
First, download Redmine 2.1.4 from rubyforge as zip or from SVN or Git as described on the relevant Redmine Wiki page. rubyforge tends not to work, so you can be forced to use the latter.
Download RubyInstaller (1.9.3 at the time of this writing) and DevelopmentKit from rubyinstaller.org
Install Ruby using the downloaded installer. Use a directory without spaces in name, i.e. don't install it to Program Files. I checked the options as below
Open command line, check if Ruby path has been added to your system. ruby --version should show the version installed, 1.9.3 in my case. If you had command line opened while installing Ruby, close and reopen it to load path.
Extract DevKit to a path with no spaces. Change to DevKit's directory (might be e.g. under Ruby's installation, i.e. C:\Ruby193\DevKit). Execute the following:
ruby dk.rb init
ruby dk.rb review (should detect Ruby's installation path correctly)
ruby dk.rb install
Install bundler gem gem install bundler
Go to Redmine home directory. Execute bundle install. You will probably (if not yet fixed) get the rmagick error - don't worry yet.
Go get ImageMagick. I picked ImageMagick-6.8.0-7-Q16-windows-dll.exe. Install to a directory whose path doesn't include spaces, e.g. C:\ImageMagick. Choose to install header files as well, as below:
Add ImageMagick home to path. Close command line and reopen it. This will reload path.
Execute `gem install rmagick --platform=ruby -- --with-opt-lib=c:/ImageMagick/lib --with-opt-include=c:/ImageMagick/include
Go to Redmine home directory again. Execute bundle install again. Should work now.
Hope that helps!

How do I point RVM to my Homebrew Ruby dir?

I installed Ruby 1.9.2 using homebrew, then installed RVM.
I want to point RVM to the version I have in my Cellar folder. How can I make rvm --default 1.9.1 point to the one in Cellar without having to reinstall it again using RVM?
You can't do it and get the right behavior.
RVM works within its own directory when running as a single-user's sandbox. Any Ruby it controls will exist in your ~/.rvm directory.
Anything outside of RVM's control will be considered the system setting, and it will be up to you to manage whether that is the regular Ruby installed in /usr/bin or /usr/local/bin or in /opt or wherever.
In my opinion, you should let RVM manage the Ruby installations. It is very slick and has rapidly become the favored way to manage Ruby development environments on Linux and Mac OS.
You could try creating aliases from the Cellar folder to the appropriate place in the ~/.rvm, but RVM modifies some things during its install process, such as gem, which would not be done in the Homebrew-installed folder, and would cause RVM's gem support to break for that Ruby version.

ruby 1.9.2 installation and gems

I have installed Ruby 1.9.2 from source. But it seems there is some trouble recognizing the bundler gem which I have already installed.
My /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
It looks like my gems are in /usr/local/ruby/gems/1.9.1/gems/.
In my rails application when I attempt to run sudo bundle install I get an error:
sudo: bundle: command not found
Also, why do the directories say 1.9.1?
Type which ruby to see the path your system thinks ruby is in.
Did you use a --prefix=... option for configure when you set up the configuration? Normally Ruby from source wouldn't be in /usr/local/ruby/bin. The Ruby executable would be in /usr/local/bin/ruby, but that is not how you'd set up your PATH to use it, so that looks suspicious. Notice that your path already contains /usr/local/bin so if Ruby installed into the normal location for a source-installation, that path will pick it up and your final search of /usr/local/bin/ruby will be wrong and unnecessary.
If you installed the gem before you installed the new version of Ruby then the gem would be part of the previous installation, not the current one, and wouldn't be visible to it. They're separate installs.
Unless you are trying to do a system-wide install for multiple users there is no real reason to compile from source and allow it to install to /usr/local/bin. I highly recommend installing RVM, then letting it install any Ruby versions into RVM's ~/.rvm sandbox. Gems will also be installed relative to the currently enabled RVM controlled ruby, which is a really good thing.

Resources