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!
Related
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.
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
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.
I have a few kegs of the same package in /usr/local/Cellar/libfoo like /usr/local/Cellar/libfoo/1.0.1, /usr/local/Cellar/libfoo/HEAD and /usr/local/Cellar/libfoo/mycopy
How can I brew link to a specific version?
This is probably the best way as of 11.1.2022:
To install a specific version, e.g. postgresql 9.5 you simply run:
$ brew install postgresql#9.5
To list the available versions run a search with #:
$ brew search postgresql#
==> Formulae
postgresql postgresql#11 postgresql#13 postgresql#9.5 qt-postgresql
postgresql#10 postgresql#12 postgresql#9.4 postgresql#9.6 postgrest
==> Casks
navicat-for-postgresql
DEPRECATED in Homebrew 2.6.0 (December 2020):
The usage info:
Usage: brew switch <formula> <version>
Example:
brew switch mysql 5.5.29
You can find the versions installed on your system with info.
brew info mysql
And to see the available versions to install, you can provide a dud version number, as brew will helpfully respond with the available version numbers:
brew switch mysql 0
Update (15.10.2014):
The brew versions command has been removed from brew, but, if you do wish to use this command first run brew tap homebrew/boneyard.
The recommended way to install an old version is to install from the homebrew/versions repo as follows:
$ brew tap homebrew/versions
$ brew install mysql55
For detailed info on all the ways to install an older version of a formula read this answer.
Sadly brew switch is deprecated in Homebrew 2.6.0 (December 2020)
$ brew switch
Error: Unknown command: switch
TLDR, to switch to package version 10:
brew unlink package
brew link package#10
To use another version of a package, for example node:
First, ensure that the specific version is installed using brew list. My package here is node (16) and node#14.
➜ ~ brew list
==> Formulae
node
node#14
➜ ~ node -v
v16.1.0
Unlink the current package: brew unlink node.
➜ ~ brew unlink node
Unlinking /usr/local/Cellar/node/16.1.0... 7 symlinks removed.
Link the correct version
➜ ~ brew link node#14
Linking /usr/local/Cellar/node#14/14.16.1_1... 3857 symlinks created.
If you need to have this software first in your PATH instead consider running:
echo 'export PATH="/usr/local/opt/node#14/bin:$PATH"' >> ~/.zshrc
➜ ~ node -v
v14.16.1
Homebrew removed brew switch subcommand in Homebrew 2.6.0. Get it back from here.
brew tap laggardkernel/tap
brew switch --help
name#version formula
There's mainly two ways to switch to an old version of an app.
If it's a bigger version change. Homebrew may have created a versioned package in the repo. Like go, go#1.10, they are two different formulae, installed into two different locations.
# install the old one
brew install go#1.10
# link the executable into /usr/local/bin, or /opt/homebrew/bin
brew link --overwrite --force go#1.10
brew switch
But not every package has a versioned variant. If you just upgraded to the new version and the old one is still in your system, skip step 1, 2.
In this situation, search in the homebrew-core repo and download the specific formula. e.g. mysql 8.0.23
Download the raw file, and install from it brew install /path/to/downloaded/mysql.rb.
Now both the latest and the old 8.0.23 (same formula mysql) exist, switch (link out) the old version with brew switch mysql 8.0.23
brew info mysql will list all the old version still exist.
Step 1, 2 could be replaced by brew extract, but that requires user maintain its own tap. I won't cover it here, just search it if you're interested.
If you have installed, for example, php 5.4 it could be switched in the following way to php 5.5:
$ php --version
PHP 5.4.32 (cli) (built: Aug 26 2014 15:14:01)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
$ brew unlink php54
$ brew switch php55 5.5.16
$ php --version
PHP 5.5.16 (cli) (built: Sep 9 2014 14:27:18)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
brew switch libfoo mycopy
You can use brew switch to switch between versions of the same package, if it's installed as versioned subdirectories under Cellar/<packagename>/
This will list versions installed ( for example I had Cellar/sdl2/2.0.3, I've compiled into Cellar/sdl2/2.0.4)
brew info sdl2
Then to switch between them
brew switch sdl2 2.0.4
brew info
Info now shows * next to the 2.0.4
To install under Cellar/<packagename>/<version> from source you can do for example
cd ~/somewhere/src/foo-2.0.4
./configure --prefix $(brew --Cellar)/foo/2.0.4
make
check where it gets installed with
make install -n
if all looks correct
make install
Then from cd $(brew --Cellar) do the switch between version.
I'm using brew version 0.9.5
In case brew switch produces an error (in this example trying to switch to node version 14):
> brew switch node 14
Error: Calling `brew switch` is disabled! Use `brew link` #-versioned formulae instead.
The correct way switching versions would be :
> brew link --overwrite node#14
if #simon's answer is not working in some of the mac's please follow the below process.
If you have already installed swiftgen using the following commands:
$ brew update
$ brew install swiftgen
then follow the steps below in order to run swiftgen with older version.
Step 1: brew uninstall swiftgen
Step 2: Navigate to: https://github.com/SwiftGen/SwiftGen/releases
and download the swiftgen with version: swiftgen-4.2.0.zip.
Unzip the package in any of the directories.
Step 3:
Execute the following in a terminal:
$ mkdir -p ~/dependencies/swiftgen
$ cp -R ~/<your_directory_name>/swiftgen-4.2.0/ ~/dependencies/swiftgen
$ cd /usr/local/bin
$ ln -s ~/dependencies/swiftgen/bin/swiftgen swiftgen
$ mkdir ~/Library/Application\ Support/SwiftGen
$ ln -s ~/dependencies/swiftgen/templates/ ~/Library/Application\ Support/SwiftGen/
$ swiftgen --version
You should get: SwiftGen v0.0 (Stencil v0.8.0, StencilSwiftKit v1.0.0, SwiftGenKit v1.0.1)
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.