How can I downgrade Homebrew to an older version? - homebrew

Currently I have the latest version 2.2.17, I want to downgrade to version 2.2.12.
Brew does not have a downgrade option, just an upgrade. Is the process to uninstall brew and re-install it again?

If you used the normal installation way via the install script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Then take a look at the brew install script (it has its own repo).
It downloads the actual Homebrew repo to /usr/local/Homebrew.
...
HOMEBREW_PREFIX="/usr/local"
HOMEBREW_REPOSITORY="/usr/local/Homebrew"
...
BREW_REPO="https://github.com/Homebrew/brew"
...
ohai "Downloading and installing Homebrew..."
(
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
# "git remote add" will fail if the remote is defined in the global config
execute "git" "config" "remote.origin.url" "${BREW_REPO}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
...
execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"
...
}
...
==> 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
...
The script installs the latest copy of the Homebrew repo. So the answer to "Is the process to uninstall brew and re-install it again?" would be a "NO". Instead, install it first normally, and then after, go over to /usr/local/Homebrew and checkout the version you want.
~$ cd /usr/local/Homebrew
Homebrew$ brew --version
Homebrew 2.3.0
Homebrew/homebrew-core (git revision d41d92; last commit 2020-05-29)
Homebrew$ git fetch --tags
Homebrew$ git checkout 2.2.12
Note: switching to '2.2.12'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 2ae26808a Merge pull request #7301 from Bo98/cmake-sdkroot
Homebrew$ brew --version
Homebrew 2.2.12
Homebrew$ cd /usr/local/bin
bin$ ./brew --version
Homebrew 2.2.12
Homebrew/homebrew-core (git revision d41d92; last commit 2020-05-29)
I recommend doing a brew doctor after just to make sure everything's still OK.
Then, unfortunately, Homebrew always auto-updates itself every time you install something. So it will always update the repo at /usr/local/Homebrew up again to the latest version. You can disable that by exporting HOMEBREW_NO_AUTO_UPDATE as mentioned here https://github.com/Homebrew/brew/issues/1670.
~$ export HOMEBREW_NO_AUTO_UPDATE=1
~$ brew install python#3.8
You'll need to create an alias or auto-export that env var to your bash_profile (or whatever is the equivalent for the terminal you use), so that it takes effect every time you use brew.

Related

original brew update Error needs to run git fetch --unshallow, but got another git fatal

$ brew update
Error: homebrew-core is a shallow clone. To `brew update` first run:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
I tried to run above command: git ... --unshallow
but I got another error:
fatal: dumb http transport does not support shallow capabilities
$ brew -v
Homebrew 2.6.0-104-g24f7898
Homebrew/homebrew-core (git revision b1ef15; last commit 2020-12-05)
Homebrew/homebrew-cask (git revision 443e7; last commit 2020-08-27)
Anyone can help?
I dug a little after trying to deal with the git repo, but the simplest thing that fixed it for me was untapping and then retapping the casks repo
brew untap homebrew/cask
brew tap homebrew/cask
that put everything back in order.
I haven't RTFM'd lately, but I'm guessing this has something to do with how casks seem to be moving into the main homebrew repo (or at least that's how it seems as a naive user).
I tried to run:
$ git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch
then:
$ git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
brew update seems OK now.
In my case I was getting this
$ brew update
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Homebrew/Library/Taps/myf/homebrew-formulas failed!
Notice the myf/homebrew-formulas in the last line.
This is one of my old repos not accessible anymore.
I got it solved with
$ brew untap myf/homebrew-formulas
Untapping myf/formulas...
Untapped 5 formulae (37 files, 63KB).
Other commands I tried
$ brew upgrade
$ brew update-reset
$ brew doctor

Caching Homebrew bottles and formulas on Travis CI

I need to install a newer version of a dependency via Brew than what is contained in the Travis CI image. Running brew update adds more than 100 seconds to every build job, so I'd like to find a way to cache the installation, or at least cache the Bottle and Formula.
It seems like there should be a simple recipe for caching the Bottles and Formulas from Brew, but so far I have not found that recipe.
To be specific, I'm using pyenv on TravisCI and for the build jobs that runs tests with Python 2.6 I need pyenv to be the latest (1.2.4), since get_pip fails on earlier versions due to recent changes on PyPI.
I added a conditional to my .travis.yml and it works fine:
if [[ "$pyver" == 2.6 ]]; then
brew upgrade pyenv &>/dev/null
fi
However, the command takes a while to run. I've split out the upgrade command and timed it:
time brew update
time brew upgrade pyenv
The brew update takes more than 100 seconds, the brew upgrade takes 10 seconds.
That finding led to the idea to cache the Bottle and Formula and on every subsequent build run:
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv
There's a question on how to cache Brew sources. That works fine.
cache:
directories:
- "$HOME/Library/Caches/Homebrew"
In $HOME/Library/Caches/Homebrew, I find the bottle cached:
pyenv-1.1.5.sierra.bottle.tar.gz
pyenv-1.2.4.sierra.bottle.tar.gz
However even with the bottle cached, running HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv doesn't succeed, presumably because the updated formula is not cached. The command yields:
Error: pyenv 1.1.5 already installed
I added caching of the formula:
cache:
directories:
- "$HOME/Library/Caches/Homebrew"
- /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
and implemented the following algorithm:
Run HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv to upgrade pyenv using the latest cached formula/bottle.
Test if pyenv >= 1.2.4 is installed. If the pyenv 1.2.4 formula and bottle were cached, it will be installed in step (1) without brew update having been run.
If pyenv >= 1.2.4 was not cached, then run brew upgrade pyenv and save the cached bottle and formula.
and the following script:
function ver { printf "%03d%03d%03d" $(echo "$1" | tr '.' ' '); }
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv &>/dev/null
# Update brew and upgrade pyenv if necessary
if [ $(ver $(pyenv --version | cut -d ' ' -f2)) -lt $(ver 1.2.4) ]; then
brew upgrade pyenv &>/dev/null
fi
However, I question whether it's a good idea to cache /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core. The examples in the Travis CI documentation are always caching directories under $HOME. It seems like I might experience problems when Travis updates the image. Does Travis CI delete the branch caches after the image is updated? If not, it seems like I would need to do that manually.
Is there a better way? It seems like Travis CI should offer an easy way to cache Brew formula and bottles.
Should I not bother with Brew and just install pyenv from the source?
I cached the brew formula under $HOME by copying the file on the first build:
cache:
directories:
- "$HOME/Library/Caches/Homebrew"
[...]
before_install:
- |
if [ "$TRAVIS_OS_NAME" = osx ]; then
# Pyenv >= 1.2.4 is needed with Python 2.6
if [[ "$pyver" == 2.6 ]]; then
# Upgrade pyenv and save formula/bottle in cache.
formula=$(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/pyenv.rb
formula_cached=$(brew --cache)/pyenv.rb
if [[ ! -f $formula_cached ]]; then
brew upgrade pyenv &>/dev/null
cp $formula $formula_cached
else
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade $formula_cached
fi
fi

homebrew - how to install older versions

I'm trying to install memcached with older versions (ex: 1.4.5) but I'm not sure how to do it.
brew install memcached installs the latest.
I also tried brew install memecached1.4.5 but it didn't work.
Usually, you can check if multiple versions are available and you can specify the version with #. e.g. brew install package#2.8
$ brew info memcached
memcached: stable 1.4.24
High performance, distributed memory object caching system
https://memcached.org/
Conflicts with:
mysql-cluster (because both install `bin/memcached`)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/memcached.rb
...
If is not available the version you want you can go to the repo, and check the history
cd "$(brew --repo homebrew/core)"
git log master -- Formula/memcached.rb
Then you can find the commit you are looking for
commit 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
Author: Adam Vandenberg <flangy#gmail.com>
Date: Fri Apr 9 21:19:48 2010 -0700
Update memcached to 1.4.5
Checkout that version and install:
cd "$(brew --repo homebrew/core)" && git checkout 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
HOMEBREW_NO_AUTO_UPDATE=1 brew install memcached
Once you get the version installed:
git checkout master # bring brew back to its latest version
brew pin memcached # [optional] prevent formula from updating
and, that's it!
I would do
brew unlink memecached
brew install memecached#1.4.5
brew link memecached#1.4.5 --force
A more expanded version of the good answer from Adrian is also here on SO.
https://stackoverflow.com/a/53766019/3794873
One thing to keep in mind is that if you are installing an older Formula the Homebrew API/methods may have changed since that time so you should brew edit appFormula against the current version and compare to the brew edit app#your.version if you encounter any errors trying to brew install app#your.version after the brew extract command in the answer linked.
2021 update:
$ curl https://raw.githubusercontent.com/Homebrew/homebrew-cask/<commit-hash>/Casks/<FORMULA>.rb > $(find $(brew --repository) -name <FORMULA>.rb)
$ brew reinstall <FORMULA>
You can find the cask or formula file URL here and the commit message should describe the file version to grab the URL for.
https://github.com/Homebrew/homebrew-core/commits/master/Formula/<formula>.rb
https://github.com/Homebrew/homebrew-cask/commits/master/Casks/<cask>.rb
Credit: https://remarkablemark.org/blog/2017/02/03/install-brew-package-version/
Sharing an interactive oneliner I made for myself of Adrian's answer now:
It does a simple parsing, depending only on "/blob/" in the github URL, of "From" in brew info, and does a bash select of commit from git log.
brew install can be replaced with brew reinstall as needed.
Tested (for cask "name=powershell") in bash 5.1 (from macports ;P) and env -i /bin/bash 3.2 on macOS (High Sierra) 10.13.6 against brew 3.3.11. (I might have done some tap'ing the other day.)
(name= && { [[ $name ]]||read -ep "Name: " name;} && [[ $(brew info "$name"|sed -Ene'/^From: (.*)/s//\1/p') =~ ([^/]*)/blob/([^/]*)/([^/]*)/([^/]*) ]] && V=("${BASH_REMATCH[#]:1}") && N=(repo current dir file) && for s in ${!N[#]};do eval "${N[s]}=\${V[s]}" && declare -p >&2 "${N[s]}";done && cd "$(brew --repo "${repo//-//}")" && IFSO="$IFS" && IFS=$'\n' && select line in $(git log --oneline master -- "$dir/$file");do IFS="$IFSO" && commit=($line) && break;done && set -x && git checkout "$commit" && HOMEBREW_NO_AUTO_UPDATE=1 brew install "$name" && git checkout master)
Skål, salud, cheers!

Brew Update not working after mac 10.9

First time running brew since 10.9 upgrade.
From the output below, should I just remove Library/Formula/ant.rb and Library/Formula/apple-gcc42.rb? Also, unclear why git pull is failing. Thanks for any help
525 [projects]$ brew --config
HOMEBREW_VERSION: 0.9.4
ORIGIN: https://github.com/mxcl/homebrew.git
HEAD: 27c26faf7b958de6028ad55be8ccc5a57b094d3f
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit ivybridge
OS X: 10.9-x86_64
Xcode: 5.0.2
GCC-4.2: build 5666
LLVM-GCC: build 0
Clang: 5.0 build 500
X11: N/A
System Ruby: 1.8.7-358
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /Users/*****/.rvm/rubies/ruby-2.0.0-p195/bin/ruby
526 [projects]$ brew update
error: The following untracked working tree files would be overwritten by merge:
Library/Formula/ant.rb
Library/Formula/apple-gcc42.rb
Please move or remove them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
This fixed it for me
cd `brew --prefix`/Homebrew
git fetch origin
git reset --hard origin/master
brew update worked fine after that
Solution
You might still find..
brew update not working after git pull origin master
Here what you need to do.
cd /usr/local
git pull origin master
brew install git
Now you might already have git on your System,
but what this will do it that now.
Your broken brew update will automatically be updated before at first run..
Here is the link to the origin issue in HomeBrew. brew stuck
My brew update was hanging and doing nothing. I am on OSX 10.12.5 and none of the above worked for me and I have no .git in usr/local, only in usr/local/Homebrew.
I ran brew update --debug --verbose and brew update and that fixed the issue, see this issue: https://github.com/Homebrew/brew/issues/895
I simply removed the .git directory inside of the /usr/local directory, then ran the command brew update.
I did this to solve the problem
cd /usr/local
git pull origin master
What worked for me was to update the brew like this:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
On Big Sur 11.1 fixed it for me:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
Brew self described it as:
To brew update, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
What worked for me on Big Sur 11.4 was first following Pritam comment by executing the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
And then executing the following (what MoD said but with addition):
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow && git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
It took a while for both commands to finish, don't worry it's not you.... just let them run 😜
I have tried all solutions posted here but nothing had worked.
I have found solution to fix the problems retated to Homebrew and that is "brew doctor". This command option diagnose the problem and suggest the solution. For my case, the command showed following comment.
I guess this command would solve many problems related to home brew so try it out!
❯ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or run:
softwareupdate --all --install --force
If that doesn't show you any updates, run:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Alternatively, manually download them from:
https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 13.1.

brew doctor says I have have uncommitted modifications to Homebrew but git status says "nothing to commit"

I'm installing brew for the first time, and down to one error when I run brew doctor:
Warning: You have uncommitted modifications to Homebrew
If this 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 && git stash
If I cd to /usr/local and run "git status" I get:
On branch master
nothing to commit (working directory clean)
If I run: cd /usr/local && git stash, I get:
No local changes to save
Should I ignore this warning? I'm on OSX 10.8.
I had this same issue, none of the above suggestions got rid of the warning for me.
It appears that Homebrew will complain about un-committed/un-stashed changes even if they haven't been added to a commit, and if they haven't been added to a commit, git stash won't do anything.
So what i had to do is:
$ cd /usr/local
$ git add . # add the unsaved changes homebrew is complaining about
$ git stash # stash the changes, now that they're in a commit
$ brew update # update homebrew
$ brew doctor # running brew doctor now outputs 'raring to brew'
Or if you want, run everything at once:
cd /usr/local/Homebrew && git add . && git stash && git clean -d -f && brew update && brew doctor
I found the problem, researching a different problem. My computer had an older version of git installed (1.5.6.56.g29b0d). It was located at /usr/local/bin/git. I downloaded the latest version (1.7.11.3) which installed itself at /usr/local/git/bin/git. After tweaking my PATH to recognize the new git, I was able to get past the error above.
brew doctor
Warning: Your Homebrew is outdated
You haven't updated for at least 24 hours, this is a long time in brewland!
Then I was able to run brew update successfully:
brew update
Updated Homebrew from ed127082 to 4a36c56a.
...
And now it looks like I'm good to go:
brew doctor
Your system is raring to brew.

Resources