error: unable to unlink old 'README.md' (Operation not permitted) - macos

I did brew update and got a error message
Your local changes to the following files would be overwritten by merge
I've searched previous posts for a workaround and I tried a host of suggested remedies but none worked. A problem is when I fired eg. git reset --hard FETCH_HEAD I got;
error: unable to unlink old 'README.md' (Operation not permitted)
fatal: Could not reset index file to revision 'FETCH_HEAD'.
I used sudo chmod and chown to change a file ownership and permission but I got the same error, "Operations not permitted".
here is an output of my brew --config;
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: f550366b94ab3022d325c9f5bcad496993d80c37
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit
ivybridge OS X: 10.9.3-x86_64
Xcode: 5.1.1 CLT: 5.1.0.0.1.1396320587
Clang: 5.1 build 503 X11: 2.7.5 => /opt/X11 System Ruby: 1.8.7-358
Perl: /usr/bin/perl
Python: /usr/local/bin/python =>/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/bin/ruby
The brew doctor had warnings indicating my /usr/local is not writeable but I had not have any problem using brew until today.
Any help will be appreciated.

Try the following:
cd $(brew --prefix)
git fetch origin
git reset --hard origin/master
brew cleanup --force
brew update

Related

Brew install on macOS fails with "Not a valid ref: refs/remotes/origin/master"?

Please help me find a solution to this error. I am installing brew with this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The result:
==> You are using macOS 10.13.
==> We (and Apple) do not provide support for this old version.
This installation may not succeed.
After installation, you will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew\'s GitHub,
Twitter or IRC. You are responsible for resolving any issues you experience
while you are running this old version.
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /usr/sbin/chown biad:admin /usr/local/Homebrew
==> Downloading and installing Homebrew...
HEAD is now at 3c84e1fef Merge pull request #10381 from jonchang/fix-version-type
error: Not a valid ref: refs/remotes/origin/master
fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
fatal: Needed a single revision
invalid upstream 'origin/master'
Failed during: /usr/local/bin/brew update --force --quiet
It seems you are trying to overwrite an existing install that has a broken core tap. Try deleting the homebrew core folder like this:
rm -fr $(brew --repo homebrew/core)
Then reinstall homebrew using:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Hope this works for you.
This generally happens when something with homebrew/core is corrupt.
% find /opt/homebrew /usr/local/ -type d -name homebrew-core -print
% rm -rf the-directories-found-in-the-above-find
% brew tap homebrew/core
First find your homebrew-core, then remove (rm -rf), then reinstall. If this fails because it didn't install enough to get a working brew, then remove the directory and retry the initial install.

Homebrew failing to install - fatal: not in a git directory

I'm trying to install homebrew on a macOS and I'm failing with the following message:
h
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
fatal: not in a git directory
Failed during: git config --replace-all homebrew.analyticsmessage true
Any ideas of what it could be and how to fix it? Many thanks (:
sudo rm -rf /usr/local/Homebrew
to remove everything before you landed here ;) and then run
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
I hope it helps.
Can you run the following commands to see if it helps?
$ cd `brew --prefix`
$ git remote add origin https://github.com/Homebrew/homebrew.git
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.
Also it would be helpful if you can attach brew doctor and brew config in the original post. Thanks!
I had a similar problem, running this command; "/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
I got this log;
=> /usr/bin/sudo /bin/chmod u+rwx /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> Downloading and installing Homebrew...
/usr/local/homebrew/.git: Permission denied
I gave permission to /user/local/homebrew and now I can test with brew....

No such keg: /usr/local/Cellar/git

I have been struggling with this for a few hours. I am on a Mac using Yosemite. I had homebrew installed, and was using git just fine. I tried doing $git add -i and I got this error:
Can't locate Git.pm in #INC (#INC contains:
So I followed the instructions here:
Can't locate Git.pm in #INC
$brew uninstall git worked fine, but after I tried to $brew install git I've been stuck in a terrible cycle.
% brew install git
Error: git-git already installed
To install this version, first `brew unlink git'
% brew unlink git
Error: No such keg: /usr/local/Cellar/git
% brew link git
Error: No such keg: /usr/local/Cellar/git
% git --version
git version 1.9.3 (Apple Git-50)
% brew upgrade git
==> Upgrading 1 outdated package, with result:
git 2.2.2
Error: /usr/local/Library/LinkedKegs/git is not a valid keg
% brew install git
Error: git-git already installed
To install this version, first `brew unlink git'
%
I just want to get homebrew & git back to normal and linked to the correct repo again. I'm really rough around the edges at this stuff, so any help would be greatly appreciated!
Give another go at force removing the brewed version of git
brew uninstall --force git
Then cleanup any older versions and clear the brew cache
brew cleanup -s git
Remove any dead symlinks
brew cleanup --prune-prefix
Then try reinstalling git
brew install git
If that doesn't work, I'd remove that installation of Homebrew altogether and reinstall it. If you haven't placed anything else in your brew --prefix directory (/usr/local by default), you can simply rm -rf $(brew --prefix). Otherwise the Homebrew wiki recommends using a script at https://gist.github.com/mxcl/1173223#file-uninstall_homebrew-sh
Had a similar issue while installing "Lua" in OS X using homebrew. I guess it could be useful for other users facing similar issue in homebrew.
On running the command:
$ brew install lua
The command returned an error:
Error: /usr/local/opt/lua is not a valid keg
(in general the error can be of /usr/local/opt/ is not a valid keg
FIXED it by deleting the file/directory it is referring to, i.e., deleting the "/usr/local/opt/lua" file.
root-user # rm -rf /usr/local/opt/lua
And then running the brew install command returned success.
Os X Mojave 10.14 has:
Error: The Command Line Tools header package must be installed on
Mojave.
Solution. Go to
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
location and install the package manually. And brew will start working and we can run:
brew uninstall --force git
brew cleanup -s git
brew cleanup --prune-prefix
brew install git

Install git via homebrew on mac osx 10.10 results in: Error: Permission denied - /usr/local/lib/perl5/site_perl/5.18.2

Hi I just tried installing git via homebrew on my mac - something is wrong. I had the github for mac app installed, but I tried removing that. The current git version in my system is:
Nielsk#~: $ git --version
git version 1.9.3 (Apple Git-50)
This is what happens if I try to install git via homebrew:
Nielsk#~: $ brew install git
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-2.1.3.y
######################################################################## 100,0%
==> Pouring git-2.1.3.yosemite.bottle.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
/usr/local/bin/git-credential-osxkeychain
The 'contrib' directory has been installed to:
/usr/local/share/git-core/contrib
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completion has been installed to:
/usr/local/share/zsh/site-functions
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied - /usr/local/lib/perl5/site_perl/5.18.2
Error: Permission denied - /usr/local/lib/perl5/site_perl/5.18.2
How can I solve this?
I also met the same issue. I think we should change the readable permission to make sure any of the directories is readable by "all". So I tried the command: sudo chown -R $USER:admin /usr/local
and then: brew link --overwrite git It works for me, hope it will also work for you.
From High Sierra, chown of /usr/local is not allowed. However you can still change permission the sub directories in /usr/local.
In my case, I had to create Frameworks in /usr/local and sudo chown -R $(whom) Frameworks. After that follow what brew doctor says.
The better way is to create subdirectory whatever you need and run
sudo chown -R $(whoami) $(brew --prefix)/*
For those with the new El Capitan OS, you'll need to update your permissions:
Open Terminal and type the following commands:
$ sudo chown -R $(whoami):admin /usr/local
$ brew doctor
$ brew update
$ brew link --overwrite git
The above solution will work for other brew installs like node, etc. Just replace the last line if you started the installation but encountered errors during the brew installation.
I had a similar permission denied error on install of git until I cleaned things up:
$brew doctor
..... << long output of issues, so you run:
$brew prune
$brew doctor
..... << less issues now, so manually clean up
$brew update
$brew install git
Does that address your error as well?
I did what brew doctor recommended and it helped:
sudo mkdir -p /usr/local/sbin
sudo chown -R $(whoami) /usr/local/sbin
MacOS 10.14.4

Brew cannot link postgresql OSX Yosemite

The steps I followed:
brew install postgresql
Installed it but couldn't link it
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
No such file or directory - /usr/local/Cellar/postgresql/9.3.3/include/informix
Error: No such file or directory - /usr/local/Cellar/postgresql/9.3.3/include/informix
(ve)Hermans-MacBook-Air: hermanstander$ brew config
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: e04275e113a52ad1e26e2973f6d29b508ca702be
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit haswell
OS X: 10.10-x86_64
Xcode: 5.1.1
CLT: 6.0.0.0.1.1406926514
Clang: 5.1 build 503
X11: N/A
System Ruby: 2.0.0-481
Perl: /usr/bin/perl
Python: /Users/hermanstander/apps/foo/foo_app/ve/bin/python
Ruby: /usr/bin/rub
Based on a hint here that old symlinks can confuse brew link, please try brew prune; brew link postgresql and see if that resolves your issue.
9.3.3 is an old version of postgresql and I don't see the Homebrew revision you're using in the Homebrew git history? If you have brew updated recently, there is some discussion of this issue here. It's not obvious what's causing the issue (unless it's dead symlinks, discussed above) but it looks like cd /usr/local/Cellar/postgresql; cp -r 9.3.5 9.3.3 will allow brew link postgresql to work, though that's kludgey.
If you haven't updated recently, please brew rm postgresql; brew update and try again. You should be installing 9.3.5.
(I don't suppose it's causing trouble here but, incidentally, running Homebrew with an active Python virtualenv is not supported.)

Resources