Completely broken Homebrew install, getting weird error upon reinstall - ruby

I'm trying to reinstall Homebrew and the installation is successfull up to when I try typing 'brew doctor' to which I receive this message:
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 26: /usr/local/Library/brew.rb: Undefined error: 0
I definitely think this may be something wrong with one of my .profile files, but I can't seem to figure out what to do. I've manually compiled Ruby because I accidentally screwed that installation up, and I've installed RVM.
In RVM, running 'rvm install ruby' gives me the same error as above, along with this one below:
ERROR: '/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.
I've tried to run
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
to delete Homebrew but I get the same error as listed above.
I've spent a few hours trying to solve this mess but I'm getting no where and just cluttering my system with broken installations. Any advice on how to finally solve this would be greatly appreciated.

I ran into the same problem. The program /usr/local/Library/brew.rb calls an old version of the ruby interpreter, that no longer exists due to a recent MacOS X upgrade:
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
Change that to:
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0
Then run:
$ brew update
You will have to clean up a bunch of git related problems in /usr/local/Library, basically you need to make a commit of your changed version of brew.rb, but there may be other things git will complain about. I was able to salvage my brew installation in this manner.

Related

Rvm error: Error running '__rvm_make -j2'

Error running '__rvm_make -j2',
please read /usr/share/rvm/log/1657548775_ruby-2.5.5/make.log
There has been an error while running make. Halting the installation.
After struggling a lot. This worked for me
rvm pkg install openssl
rvm remove x.x.x
rvm install x.x.x -C --with-openssl-dir=$HOME/.rvm/usr
Foreword: I encountered this problem while trying to install rvm in WSL2
Onto to the meat now.
You may encounter newer versions of this error marked by a different end switch. I mean, instead of the last switch being strictly -j2, yours might be -j3, j4, j5, or other subsequent ones. Therefore proceed to read below for a possible solution.
Shortly, I suggest two commands to resolve this error. Please do not run the installation suggestion that may appear immediately after running the first command. Instead, just proceed to run the second command.
On pasting the second command, replace <version> portion with the appropriate ruby version you would like to install. In my case, I wanted to install ruby version 2.7.4, and therefore, I set it as ruby-2.7.4
rvm pkg install openssl
rvm install ruby-<version> --with-openssl-dir=/usr/share/rvm/usr
However, if the above fix fails to remedy the ruby installation problem, you can ensure that rvm is added to the user group by running the command below:
rvm group add rvm $USER
After running the command above, close the Ubuntu app and reopen it. Then proceed to run the command below:
rvm fix-permissions
Now try reinstalling ruby with the command rvm install 2.7.4 --default. If problems persist, run sudo usermod -a -G rvm $USER and attempt a reinstall. If that fails, only further research gives you a chance.
PS:
Please note that I was making this installation in Windows Subsystem for Linux (WSL2) Ubuntu Therefore, if this problem persists in another system like macOS, it may mean that this solution is perhaps not platform agnostic, and thus, the specific solution for such requires further digging.
I ran into a similar problem - Error running "__rvm_make -j4". The bug was the lack of support for OpenSSL 3.0 when used on Ubuntu 22.04. You can try using "rbenv" instead of "rvm", it worked for me.
Had a similar error "Error running '__rvm_make -j10'" and solved with --with-out-ext=fiddle flag.
rvm install "ruby-2.7.0" --with-out-ext=fiddle
This on M1
you can try this command to solve the issue
sudo apt-get install curl git g++ make libssl-dev libreadline-dev zlib1g-dev

gem install - fatal error: 'ruby/config.h' file not found in Mojave

gem install is failing in MacOs Mojave. Anything that can help me solve this? My ruby version is ruby 2.3.7p456.
➜ sudo gem install json -v '1.8.3'
current directory: /Library/Ruby/Gems/2.3.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^~~~~~~~~~~~~~~
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Update 15/03/2021
According to Apple, Ruby won't be included anymore in future versions of the system, so using a Ruby version manager will be the only way to go once this will actually happen.
Original answer
After hours and hours of trial and errors I wanted to go deeper into the reasons of this error and I finally found this that I think is the clean way to go around this issue:
Catalina (NdMe: I think this started earlier, on Mojave) no longer supports including macOS headers in command line
tools, they have to be explicitly used through Xcode SDK. You can do
so by running gem through the xcrun tool like:
xcrun gem install <your_gem>
Quoted from a Github issue comment.
Xcode 12 upgrade messed this up for me.
I installed ruby from brew and added this to my .zshrc
export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
If you have the Xcode 10 beta running this might fix it
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
In macOS Monterey (in the Beta at least), Ruby (ruby 2.6.3p62 (2019-04-16 revision 67580)) is still included but it doesn't seem to work well (fatal error: 'ruby/config.h' file not found), so I installed my own version of Ruby. You can install ruby manually, but I prefer to use rbenv, a Ruby version manager.
Install ruby using rbenv
Install rbenv: brew install rbenv ruby-build
ruby-build is a plugin for rbenv to actually install a ruby version, it provides ruby install command.
Setup rbenv: rbenv init, (and follow its recommended instructions, for example if you're using zsh, it says add eval "$(rbenv init -)" to ~/.zshrc)
Install ruby: rbenv install 3.0.1. Latest version listed here
Do what you came to do: sudo gem install cocoapods or bundle install
Or install ruby manually:
Run brew install ruby
Run echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc so that this version is used
Restart terminal
asdf?
An alternative to rbenv is asdf, but I find asdf a bit complicated to use, since it supports more than just ruby, NodeJS. I would argue it does none of them very ergonomically.
Note: I have an M1 mac, and it's still working.
I got into this issue when trying to install fastlane with homebrew. None of the suggestions mentioned earlier helped me. Manually installing the macOS_SDK_headers_for_macOS_10.14.pkg fixed it.
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
I was having this same issue where I could not install native extensions due to a failure when including "ruby/config.h".
I believe the cause of this issue was because I was using the ruby version installed with Homebrew. After upgrading to a new version of Ruby with Homebrew, I saw the following helpful message from Homebrew:
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
Adding the following lines to my ~/.bash_profile fixed the issue for me:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
xcrun gem install <your_gem> worked for me, but I had to do it multiple times — every time bundle install failed.
The best solution is probably to set the same vars as xcrun in your .zshrc file. xcrun env on my system adds:
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPATH=/usr/local/include
LIBRARY_PATH=/usr/local/lib
I had this problem after installing Big Sur. I found the file ruby/config.h was not present in the Xcode Packages in the Xcode versions I had installed prior to upgrading. I was able to correct it by uninstalling the Xcode versions and reinstalling them.

OSX homebrew error when install gdb: ''Uninitialized constant Homebrew::FormulaClassUnavailableError"

I am having problems installing gdb on OS X El Capitan 10.11.6.
I ran brew install homebrew/dupes/gdb in terminal,
and got
Error: uninitialized constant Homebrew::FormulaClassUnavailableError
Please report this bug:
https://git.io/brew-troubleshooting
/usr/local/Library/Homebrew/cmd/install.rb:151:in `rescue in install'
/usr/local/Library/Homebrew/cmd/install.rb:82:in `install'
/usr/local/Library/brew.rb:84:in `<main>'
What does that mean and how to fix that?
Could anyone please help me.
Edit:
After run brew doctor I got these:
Warning: /usr/local/bin isn't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.
You should probably change the ownership and permissions of /usr/local/bin
back to your user account.
sudo chown -R $(whoami) /usr/local/bin
Warning: You have MacPorts or Fink installed:
/opt/local/bin/port
This can cause trouble. You don't have to uninstall them, but you may want to
temporarily move them out of the way, e.g.
sudo mv /opt/local ~/macports
Warning: Suspicious git origin remote found.
With a non-standard origin, Homebrew won't pull updates from
the main repository. The current git origin is:
https://github.com/Homebrew/brew
Unless you have compelling reasons, consider setting the
origin remote to point at the main repository, located at:
https://github.com/Homebrew/homebrew.git
Warning: You have uncommitted modifications to Homebrew
If this is a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
cd /usr/local/Library && git stash && git clean -d -f
Is it the cause of the homebrew or any other reasons?

brew doctor bad interpetor no such file

I haven't tried using brew since upgrading from Mavericks to Yosemite. I'm getting the following error.
legion:~ jkratz$ brew doctor
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 26: /usr/local/Library/brew.rb: Undefined error: 0
Would you have anything against running the uninstaller script and starting again? Looks like ruby has moved and it can't find it.
You haven't run brew upgrade in a while and Apple upgraded their Ruby!
To fix, do cd /usr/local && git pull and you should be fine.

Ruby error Homebrew uninstall while having macports

I installed ruby via \curl -L https://get.rvm.io | bash -s stable and did rvm install 1.9.2 doing this creates and error
Installing requirements for osx, might require sudo password.
fatal: Unable to create '/usr/local/.git/index.lock': Permission denied
Error: Failure while executing: git checkout -q master
Failed to update Homebrew, follow instructions here:
https://github.com/mxcl/homebrew/wiki/Common-Issues and make sure `brew update` works before continuing.
Upon doing a which git it shows it's installed in /usr/bin/git yeah homebrew keeps trying to reference /usr/local/.git. I tried unistalling homebrew so I can do a fresh install using what's listed at homebrew gist. All seemed well but doing a which brew still shows it as /usr/local/bin/brew so I tried to manually uninstall it by doing it one by one.
One thing to note is I never had a Cellar folder, why I don't know. While doing a brew prune I noticed a lot of macport items are starting to ask if I should override them.
Is it typical to of ran the uninstall script but still have the brew commands available or the dirs?
Why is it that homebrew needs root access to /user/local/ to work, this is extremely bad.
That /usr/local/.git it's referencing is not the git executable, but the config file for the repository it's trying to set up under /usr/local/. It's trying to write to that file.
To run homebrew you need write permissions to /usr/local as the user you'r going to run brew as. Homebrew's recommended method is to adjust the ownership and permissions on /usr/local to allow you to write to it from your regular user account or a dedicated homebrew account, instead of using sudo. This is done as part of the homebrew installation script, typically by putting you in the admin group and making /usr/local group-writable.
To fix this, check the owner and permissions on /usr/local/ and /usr/local/.git and make sure you can write to them (and the rest of the /usr/local/ hierarchy) as the user that you're running brew and RVM commands as.
Ended up just doing a sudo $USER as I really could not find any other approach to fixing this.

Resources