So I have a few homebrew packages that I maintain. When I release a tagged version of one of the packages, I have a cumbersome dance that I have to do in order for the whole process to work end to end. It is as follows:
Update package and tag with new version number
Push to github
Update the URL in my homebrew formula to the new tag
Push formula to github
brew upgrade [package]
when it gives me the sha256 error I copy and paste the Actual sha256 into the formula file and push it again up to github.
problem solved
Bellow is the error I get when I brew upgrade [package]
Error: SHA256 mismatch
Expected: f95ec88f22bd217271199695593f9a217cc0fc3b69469e31cafd09f0a55dc1a4
Actual: 3b52516206cdec8fd85f74c5d346665195fdef3095dc7665a680e48842edd5cf
I have tried to generate the sha256 locally before I commit the formula to github and it never matches:
shasum -a 256 [package]
I have tried downloading the tarball and issuing the same command on the tar.gz and it doesnt match either.
curl -O http://address/0.0.9.tar.gz
shasum -a 256 0.0.9.tar.gz
What gives? I am sick of doing this dance. There has to be a less cumbersome way that only involves me committing my formula file once.
SOLVED
The problem was with the curl command.
The following command will output the correct sha256 checksum to put in the formula file.
Using Curl
curl -Ls https://address/0.0.9.tar.gz | shasum -a 256
Using wget
wget -qO- https://address/0.0.9.tar.gz | shasum -a 256
Related
After updating gcloud I get this warning, but how do I do it(Should I remove Docker)?
WARNING: There are older versions of Google Cloud Platform tools on your system PATH.
Please remove the following to avoid accidentally invoking these old tools:
/Applications/Docker.app/Contents/Resources/bin/kubectl
I have this in my .zshrc:
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/<NAME>/google-cloud-sdk/path.zsh.inc' ]; then source '/Users/<NAME>/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/<NAME>/google-cloud-sdk/completion.zsh.inc' ]; then source '/Users/<NAME>/google-cloud-sdk/completion.zsh.inc'; fi
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
This happens because docker-for-mac installs a bin for kubectl, and gcloud-sdk also installs another bin with gcloud components install kubectl.
My recommendation is to uninstall kubectl as component from gcloud, overwrite the symlink from docker-for-mac, and only use the homebrew installed bin.
Try this commands:
gcloud components remove kubectl
brew install kubernetes-cli
brew link --overwrite kubernetes-cli
TLDR
/usr/local/bin/kubectl is a link installed by Docker: ls -l /usr/local/bin/kubectl => /usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl. Removing the link has no side effects and solves the conflict:
rm /usr/local/bin/kubectl
Justification
The conflict is with the Docker-provided version of kubectl so it makes sense to check what Docker docs have to say about it. https://docs.docker.com/desktop/kubernetes/#use-the-kubectl-command
Extract:
If you installed kubectl using Homebrew, or by some other method, and experience conflicts, remove /usr/local/bin/kubectl.
Here is my case you can refer to. After running gcloud components update, I got this warning:
WARNING: There are older versions of Google Cloud Platform tools on your system PATH.
Please remove the following to avoid accidentally invoking these old tools:
/usr/local/Cellar/kubernetes-cli/1.10.2/bin/kubectl
I check this tool using brew list
☁ issue [master] brew list
coreutils gdbm git-lfs icu4c kops kubectx libpng mtr openssl python#2 sqlite tree wxmac
erlang geoip git-redate jpeg kube-ps1 kubernetes-cli libtiff node pcre readline telnet watchman
After reading the doc. I decided to uninstall kubernetes-cli and its dependencies kops, kube-ps1, and kubectx to avoid the conflicts.
☁ issue [master] brew uninstall kops kube-ps1 kubectx
Uninstalling /usr/local/Cellar/kops/1.9.0... (5 files, 129.8MB)
Uninstalling /usr/local/Cellar/kube-ps1/0.6.0... (6 files, 29.0KB)
Uninstalling /usr/local/Cellar/kubectx/0.5.0... (12 files, 27.8KB)
☁ issue [master] brew uninstall kubernetes-cli
Uninstalling /usr/local/Cellar/kubernetes-cli/1.10.2... (178 files, 52.8MB)
☁ issue [master] gcloud components update
All components are up to date.
This warning is gone.
I just went into the Docker file's bin folder and moved the kubectl to the trash.
Do echo $PATH and check which folder takes precedence. In my case it is like .../Users/myname/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:.... Here the kubectl in gcloud is actually before the kubectl from Docker Desktop (which is in /usr/local/bin/kubectl) so there is no problem. If this is also your case you don't need to do anything.
Of course, if you want to completely remove confusion you can just delete the link /usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl, or rename it.
Update:
In the recent docker desktop releases they actually provided another link /usr/local/bin/kubectl.docker -> /Applications/Docker.app/Contents/Resources/bin/kubectl to differentiate it from other kubectl so it is not a bad idea to just simply delete the link /usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl
Is there a way to brew link just those files without conflicts?
As near as I can tell, the only options are to force an overwrite of all conflicting roles, or to link no files at all. For example I have an existing compare that I need to keep, but need ImageMagick's convert. When I brew install imagemagick I get
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/compare
Target /usr/local/bin/compare
already exists. You may want to remove it:
rm '/usr/local/bin/compare'
To force the link and overwrite all conflicting files:
brew link --overwrite imagemagick
To list all files that would be deleted:
brew link --overwrite --dry-run imagemagick
Possible conflicting files are:
/usr/local/bin/compare -> /Applications/Araxis Merge.app/Contents/Utilities/compare
But the only way offered to proceed is either to leave all of ImageMagick unlinked, or to overwrite my existing compare.
How do I brew link everything but the existing compare? Is there a way to install only convert perhaps?
Here's a shell function I wrote to do this (for the zsh that's now standard on macOS, but it will run on Bash with small adjustments 1):
local targetdir
targetdir=($(brew --cellar $1)/*/bin) || return
local linksdir=$(brew --repo)/bin
for ex in "$targetdir"/*(^/) # files (and symlinks), not subdirectories
do
local exname=${ex##*/}
if builtin which "$exname" &>/dev/null
then
echo " $exname already available in the path - skipped"
else
ln -s "$ex" "$linksdir/" && echo "$exname linked from $linksdir"
fi
done
I saved it as a shell function called blink and when I call it with a package name, like
blink binutils
it symlinks only the binaries whose names aren't already available in the $PATH.
1The adjustments to make it work on Bash: remove the final (^/) form the for ex... line, and the builtin 3 lines further down.
This seems like a very noob question but I can't find an answer anywhere!
I'm very new to developing packages for Homebrew but when I edit my formula and come to update my package I get the following error
Error: SHA256 mismatch
My question is, how do I generate the expected SHA256 value?
After editing the formula, you can run brew fetch your-formula --build-from-source to fetch the tarball and display the new checksum. If you've already downloaded the tarball somewhere, you can calculate the hash with openssl sha256 < some_tarball.tar.gz or shasum -a 256 some_tarball.tar.gz.
For casks, I prefer to change the cask sha256 to something wrong and then run brew cask fetch {caskName}, which then throws an error that shows the "Actual" sha256 for the downloaded file. You can just copy and paste that.
I have a Homebrew installation in $HOME/brew, and historically it has worked well. Unfortunately, over time Homebrew has become less and less tolerant of installations outside of /usr/local. Various formulae make hard assumptions about the installation prefix, and do not work properly (i.e., were not tested) with a non-standard prefix. The brew doctor command even goes so far as to warn about this now:
Warning: Your Homebrew is not installed to /usr/local
You can install Homebrew anywhere you want, but some brews may only build
correctly if you install in /usr/local. Sorry!
As such, I would now like to migrate my Homebrew installation over to /usr/local. However, I am loath to simply mv all the files, as I suspect this will cause problems. I could not find any instructions on the Homebrew site or here on migrating an existing installation to a new prefix. Of course, I could uninstall Homebrew and then reinstall it, but I would prefer not to rebuild all my kegs.
Is there any existing script or documented practice for performing such a migration?
Or is this impossible due to hardcoded absolute paths in linked binaries?
The modern way to do this is with homebrew-bundle.
brew tap Homebrew/bundle
brew bundle dump # Creates 'Brewfile' in the current directory
# later ...
brew bundle # Installs packages listed in 'Brewfile'
I just wrote a script to achieve the goal to migrate homebrew packages to a new system, which also applies for your case (named backup-homebrew.sh):
#!/bin/bash
echo '#!/bin/bash'
echo ''
echo 'failed_items=""'
echo 'function install_package() {'
echo 'echo EXECUTING: brew install $1 $2'
echo 'brew install $1 $2'
echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed to install.'
echo '}'
brew tap | while read tap; do echo "brew tap $tap"; done
brew list --formula | while read item;
do
echo "install_package $item '$(brew info $item | /usr/bin/grep 'Built from source with:' | /usr/bin/sed 's/^[ \t]*Built from source with:/ /g; s/\,/ /g')'"
done
echo '[ ! -z $failed_items ] && echo The following items were failed to install: && echo $failed_items'
You should first run this script on your original system to generate a restore script:
./backup-homebrew.sh >restore-homebrew.sh && chmod +x restore-homebrew.sh
Then, after installing Homebrew on your new system (in your case the same system), simply run restore-homebrew.sh to install all those packages you have on your original system.
The benefits of this script over the one given by #ctrueden is that this script also tries to back up the installation options you used when you installed the packages.
A more detailed description is in my blog.
As suggested by Peter Eisentraut, I indeed ended up migrating my Homebrew installation by reinstalling it. You can script things a bit to retap all your extra taps, and reinstall all your previously installed kegs, without too much manual work:
#!/bin/sh
# save list of kegs for later reinstallation
brew list > kegs.txt
# back up old Homebrew installation
mv $HOME/brew $HOME/old-brew
# install Homebrew into /usr/local
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# retap all the taps
# NB: It is not enough to move the tap repos to their new location,
# because Homebrew will not automatically recognize the new formulae.
# There might be a configuration file we could edit, but rather than
# risk an incomplete data structure, let's just retap everything.
for tapDir in $HOME/old-brew/Library/Taps/*
do (
cd $tapDir
tap=$(git remote -v | \
grep '(fetch)' | \
sed 's/.*github.com\///' | \
sed 's/ (fetch)//')
/usr/local/bin/brew tap $tap
) done
# reinstall all the kegs
/usr/local/bin/brew install $(cat kegs.txt)
# much later... ;-)
rm -rf kegs.txt $HOME/old-brew
Of course, customized Homebrew installations will have additional wrinkles. For example, if you have committed changes to any of your Homebrew-related Git repos, you may want to import that work before reinstalling your kegs or blowing away your old installation:
cd /usr/local
for f in $(find . -name '.git')
do (
repoDir=$(dirname $f)
cd $f/..
git remote add old-brew-$f $(dirname $HOME/old-brew/$f/..)
git fetch old-brew-$f
) done
Note that I only tested the second snippet above very lightly, as I personally have not customized my Homebrew in such a way.
Another aspect of Homebrew not addressed by this approach is custom flags using during your original installation. For example, to install wine you need to install various dependencies with the --universal flag, and the script above will not reinstall them with such flags enabled. See #xuhdev's answer for a solution that does so.
Or is this impossible due to hardcoded absolute paths in linked binaries?
Indeed. You'll need to reinstall everything from scratch.
Trying to update Homebrew with brew update I got the following error
error: The following untracked working tree files would be overwrittenby merge:
Library/Formula/argp-standalone.rb
Library/Formula/cocot.rb
Please move or remove them before you can merge.
Aborting
Updating e088818..5909e2c
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
I found a blog post by someone who experienced a similar problem after having installed Mountain Lion (which I did this week too). He explains how he removed the files referred to in the error message
I removed these files:
$ cd $(brew --prefix)
$ rm cocot.rb
However, removing these files didn't help with the brew update. Instead I had to manually update brew through git:
$ cd $(brew --prefix)
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.
Assuming those instructions are correct (which I maybe shouldn't assume), I tried to follow these instructions and do
$ cd $(brew --prefix)
$ rm cocot.rb
However, it said 'file doesn't exist' when I tried to rm cocot.rb
One thing I'm not sure about is the cd $(brew --prefix) Are those the exact words I type or do I have to replace prefix with something? the cd was successful, so I'm assuming it was correct -- it moved me into /usr/local, but there was no file to remove. Contents of /usr/local are
Cellar clamXav git mysql var Library doc heroku mysql-5.5.15-osx10.6-x86_64 README.md etc include rvm bin foreman lib share
At any rate, do you know how I can fix the 'brew update'
Update: After removing the files according to favoretti's instructions and trying chown -R <your_username> $(brew --prefix)/.git, I got the following error running brew update
error: The following untracked working tree files would be overwritten by merge:
Library/Aliases/gperftools
Library/Aliases/hashdeep
Library/Aliases/htop
Library/Aliases/nodejs
Library/Aliases/ocio
Library/Aliases/oiio
Library/Aliases/pgrep
Library/Aliases/pkill
Library/Aliases/qt4
Library/Aliases/twolame
Library/Aliases/wxwidgets
Library/Contributions/cmds/brew-aspell-dictionaries
Library/Contributions/cmds/brew-beer.rb
Library/Contributions/cmds/brew-dirty.rb
Library/Contributions/cmds/brew-graph
Library/Contributions/cmds/brew-grep
Library/Contributions/cmds/brew-leaves.rb
Library/Contributions/cmds/brew-linkapps.rb
Library/Contributions/cmds/brew-ls-taps.rb
Library/Contributions/cmds/brew-man
Library/Contributions/cmds/brew-md5-to-sha1
Library/Contributions/cmds/brew-mirror-check.rb
Library/Contributions/cmds/brew-pull.rb
Library/Contributions/cmds/brew-readall.rb
Library/Contributions/cmds/brew-server
Library/Contributions/cmds/brew-services.rb
Library/Contributions/cmds/brew-switch.rb
Library/Contributions/cmds/brew-test-bot.rb
Library/Contributions/cmds/brew-tests.rb
Library/Contributions/cmds/brew-unpack.rb
Library/Contributions/cmds/brew-which.rb
Library/Contributions/cmds/git
Library/Contributions/cmds/svn
Library/ENV/4.3/apr-1-config
Library/ENV/4.3/bsdmake
Library/ENV/4.3/c++
Library/ENV/4.3/c89
Library/ENV/4.3/c99
Library/ENV/4.3/cc
Library/ENV/4.3/clang
Library/ENV/4.3/clang++
Library/ENV/4.3/cpp
Library/ENV/4.3/g++
Library/ENV/4.3/gcc
Library/ENV/4.3/git
Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
Library/ENV/4.3/ld
Library/ENV/4.3/llvm-g++
Library/ENV/4.3/llvm-g++-4.2
Library/ENV/4.3/llvm-gcc
Library/ENV/4.3/llvm-gcc-4.2
Library/ENV/4.3/make
Library/ENV/4.3/mig
Library/ENV/4.3/sed
Library/ENV/4.3/svn
Library/ENV/4.3/xcrun
Library/ENV/libsuperenv.rb
Library/ENV/pkgconfig/leopard/libcrypto.pc
Library/ENV/pkgconfig/leopard/libcurl.pc
Library/ENV/pkgconfig/mountain_lion/libcurl.pc
Library/ENV/pkgconfig/mountain_lion/libexslt.pc
Library/ENV/pkgconfig/mountain_lion/libxml-2.0.pc
Library/ENV/pkgconfig/mountain_lion/libxslt.pc
Library/Formula/abcl.rb
Library/Formula/abcmidi.rb
Library/Formula/aiccu.rb
Library/Formula/akka.rb
Library/Formula/alac.rb
Library/Formula/alure.rb
Library/Formula/appledoc.rb
Library/Formula/arangodb.rb
Library/Formula/argp-standalone.rb
Library/Formula/argtable.rb
Library/Formula/autopano-sift-c.rb
Library/Formula/avian.rb
Library/Formula/avidemux.rb
Library/Formula/avro-cpp.rb
Library/Formula/aws-cloudsearch.rb
Library/Formula/aws-sns-cli.rb
Library/Formula/backupninja.rb
Library/Formula/bact.rb
Library/Formula/bam.rb
Library/Formula/basex.rb
Library/Formula/berkeley-db4.rb
Library/Formula/bind.rb
Library/Formula/blazeblogger.rb
Library/Formula/bochs.rb
Library/Formula/boost149.rb
Library/Formula/bsdconv.rb
Library/Formula/bsdmake.rb
Library/Formula/buildapp.rb
Library/Formula/bup.rb
Library/Formula/byacc.rb
Library/Formula/cadubi.rb
Library/Formula/camellia.rb
Library/Formula/casperjs.rb
Library/Formula/ccextractor.rb
Library/Formula/cconv.rb
Library/Formula/cdo.rb
Library/Formula/cdpr.rb
Library/Formula/cgvg.rb
Library/Formula/checkstyle.rb
Library/Formula/chordii.rb
Library/Formula/chruby.rb
Library/Formula/cifer.rb
Library/Formula/clhep.rb
Library/Formula/cntlm.rb
Library/Formula/cocot.rb
Library/Formula/cogl.rb
Library/Formula/collada-dom.rb
Library/Formula/crash.rb
Library/Formula/crossroads.rb
Library/Formula/crosstool-ng.rb
Library/Formula/css-crush.rb
Library/Formula/csync.rb
Library/Formula/ctemplate.rb
Library/Formula/curlftpfs.rb
Library/Formula/cutter.rb
Library/Formula/cvsutils.rb
Library/Formula/darkstat.rb
Library/Formula/darner.rb
Library/Formula/dart.rb
Library/Formula/dasm.rb
Library/Formula/debianutils.rb
Library/Formula/dfc.rb
Library/Formula/dgtal.rb
Library/Formula/dhcping.rb
Library/Formula/di.rb
Library/Formula/dmtx-utils.rb
Library/Formula/drip.rb
Library/Formula/dsniff.rb
Library/Fo
Aborting
Updating e088818..c1fbc29
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
You need to do the following:
cd $(brew --prefix)
rm Library/Formula/argp-standalone.rb
rm Library/Formula/cocot.rb
And then do the
git fetch origin
git reset --hard origin/master
brew update
Basically, to explain a bit more:
cd $(brew --prefix)
tells cd to change the directory to whatever brew --prefix will output.
If you try executing brew --prefix command you should see something in lines of:
brew --prefix
/usr/local
So the command would be in this case an equivalent of cd /usr/local.
Newer brew versions have formulae under its installation prefix and Library/Formula/, so that's where you need to look for those outdated/changed files.
Note, that if you changed those formulae yourself for a particular reason (like pinning a version) this action will revert them back to default ones and may produce unwanted effects.
#TedPennings noted in comments that this worked for him, but his sequence was:
chown everything to my_username:admin, ie, sudo chown -R ted:admin $(brew --prefix)
run the two git commands above,git fetch origin and git reset --hard origin/master
cd $(brew --prefix)
git reset --hard HEAD
brew update
This is caused by an old bug in the update code that has long since been fixed. However, the nature of the bug requires that you do the following:
cd $(brew --repository)
git reset --hard FETCH_HEAD
If brew doctor still complains about uncommitted modifications, also run this command:
cd $(brew --repository)
git clean -fd
$ cd $(brew --prefix)
$ git clean -fd
$ git reset --hard
$ sudo chown -R `whoami` `brew --prefix`
$ brew update
Note: steps 2&3 worked for me since I did step 5 before 4 before I got the error. The brew update before changing the owner of the folder caused the whole problem.
I had a similar issue where my brew package library got downloaded as a root user and then I was not able to run brew update as git would complain about not able to merge the file.
Solution was to do :-
sudo chown -R <user> /usr/local/Library
Resetting the brew repository should be the most efficient way if you don't mind to discard potential modifications on formulas you might have been applied:
$ cd `brew --prefix`
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew update
I was able to fix this on my machine by adding admin group write (and setgid bit) permission at these paths:
sudo chmod -R g+ws /usr/local /Library/Caches/Homebrew
The s sets the group id on execution so that the write permissions aren't lost the next time a different admin user updates or upgrades Homebrew.
This answer is somewhat incomplete because when I try to do brew cleanup --force there is a permissions issue when Homebrew tries to remove content in /usr/local/Cellar/. (Unfortunately I'm not able to investigate this further at the moment.)
Another option is to just use git stash.
The brew update command performs a git pull, so if there are any changed files (or even file attributes, which happened to me when I changed permissions in the directory recursively) you have to somehow fix the conflicts. Using git stash is one way; it takes any changes and puts them aside so you effectively revert to the last updated repo version. The Homebrew 'location' is by default /usr/local and it installs as a git repository. You can look for a .git folder to see for yourself. I'm writing a homebrew uninstall script to be posted on my GitHub profile soon with more info.
sudo chown -R USER /usr/local/bin
note - for USER use command whom i.e. your username
sudo brew doctor
This approach may be simpler than some. It involves:
fixing a git issue so you can delegate management of changes to it again.
no manual moves of files or directories.
no manual adjustments of file or directory permissions.
Steps (with notes for those who want explanations):
cd $(brew --repository) // see Note 1 below
git remote add brew https://github.com/Homebrew/brew // see Note 2 below
git pull brew master // promising fast-forward report!
brew update // see Note 3 below
Overview:
From what I can tell, the actual cause of this issue is a change in the repo url. It's now brew and was brew.git. (Full up-to-date url: https://github.com/Homebrew/brew)
Note 1: This first command takes you from anywhere in your file structure to the correct directory. The directory structure is different for me than what others show above (Mac OS 10.11.16), but with this command, those differences should not matter.
Note 2: This second command adds the correct remote url to a new alias; I did so just in case this approach didn't accomplish what I wanted and I needed the previous address again. Since the new remote worked, I'll invite someone else to comment on simply changing the url aliased by origin. I'll happily update the answer to reflect what worked for you.
Note 3: This forth command has exactly the desired result: it reports a large number of updates, including the particularly nice report of "==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!" (emphasis theirs).
This post helped me after updating to El Capitan. In my case, chown wasn't working ("zsh: command not found: chown"), so step 1 was adding this line to my .zshrc:
export PATH="$PATH:/usr/sbin"
I'd already tried several of the more popular answers above, so I'm pretty sure that git status was coming up clean by the time I pasted in the critical command from the blog post:
sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
This should work.
1. cd `brew --prefix`
2. git fetch origin
3. git reset --hard origin/master
4. sudo brew update