Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset anything related to Ruby to factory settings on Mac OS High Sierra

Tags:

macos

ruby

After a number of misadventures involving RVM, Ruby and Rails on my new laptop have left me completely bewildered. I uninstalled RVM but all the paths, versions and permissions are all messed up.

I searched and couldn't find the right fixes. It feels like each solution makes the problem get worse.

I want to start fresh without having to reset my computer to factory settings. How can I reset just the Ruby-related things like Ruby, Rails, etc., without erasing my computer?

like image 559
Forrest Avatar asked Dec 17 '18 18:12

Forrest


People also ask

How do I factory reset my Mac High Sierra?

Turn on your Mac and immediately press and hold these four keys together: Option, Command, P and R. Release the keys after about 20 seconds. This clears user settings from the memory and restores certain security features that may have been altered.

How do you erase all content and settings in macOS High Sierra?

Choose Apple menu > Restart, then immediately press and hold Command-R. In the Recovery app window, select Disk Utility, then click Continue. In Disk Utility, select the volume you want to erase in the sidebar, then click Erase in the toolbar.

How do I completely remove Ruby on Rails from Mac?

Uninstall Ruby on Mac with rbenv For rbenv, use rbenv versions to see which versions you have installed. Use the uninstall command to remove a version. This will remove any gems associated with the version as well. If you want to reinstall Ruby, see Install Ruby on Mac for recommendations of newer version managers.


1 Answers

I would close & reopen your terminal window before you start all of this to make sure you don't have any old env vars loaded.

General things:

  • Run env | grep RUBY, env | grep RVM and look for any leftover environment variables that you may have set
  • Same for env | grep GEM. Sometimes you'll see GEM_PATH, GEM_HOME, etc. but these aren't necessary for system ruby
  • Peek inside your ~/.bash_profile, ~/.bashrc, and ~/.profile files and see if you've added any rvm stuff

If you're running macOS Mojave (I'm comparing against my system):

which ruby should return /usr/bin/ruby. If it doesn't, you have something else interfering. Post what that is and we can get it fixed.

Running /usr/bin/ruby --version should return ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

Permissions for system ruby:

-r-xr-xr-x  1 root  wheel  52016 Nov 30 02:38 /usr/bin/ruby

This should be something like sudo chmod 555 /usr/bin/ruby to fix this if yours is difference. If you have different owners you'll need to sudo chown root:wheel /usr/bin/ruby

You'll also want to check which gem, and see if it reports /usr/bin/gem. Permissions should be the same as /usr/bin/ruby. /usr/bin/gem --version should return 2.5.2.3

Running /usr/bin/gem env should return something similar-ish to below. Replace jay (my computer user) with yours

RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.2.3
  - RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
  - USER INSTALLATION DIRECTORY: /Users/jay/.gem/ruby/2.3.0 # this doesn't matter much
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /Users/jay/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-18
  - GEM PATHS:
     - /Library/Ruby/Gems/2.3.0
     - /Users/jay/.gem/ruby/2.3.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => false
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org/"]
     - "benchmark" => true
     - "gem" => "--document=yri"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/bin
     - /Users/jay/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /opt/X11/bin

From there you've got two directories you probably want to look at:

Run ls -al /Library/Ruby/. You should see this:

drwxr-xr-x   3 root  wheel    96 Aug 17 18:59 Gems
drwxr-xr-x   3 root  wheel    96 Aug 17 18:59 Site

You may need to chmod/chown each of those directories (with -R for recursive)

When you're done, please note that running /usr/bin/gem install bundler and gem install bundler (assuming you haven't installed a new ruby version manager) should yield an error as below (this means you re-configured the permissions correctly).

Fetching: bundler-1.17.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

You'll see some tutorials mention changing those permissions, or running sudo to install gems but I don't recommend that. My favorite ruby version manager is asdf which may be worth a look. You'll install the core, and the ruby plugin.

This should get you a little bit closer. If you see anything else messed up, please post the error.

like image 124
Jay Dorsey Avatar answered Nov 15 '22 09:11

Jay Dorsey