Brew List and Install Specific Versions of Formula - homebrew

I would like to install 2.6.X but cannot find documentation on how to specify a formula version. Brew is only installing the latest version of the formula.
I'm using the following versions of brew
Homebrew 1.8.6
Homebrew/homebrew-core (git revision 5ea559; last commit 2018-12-18)
Homebrew/homebrew-cask (git revision 4144b74; last commit 2018-12-18)
I'm upgrading from 2.2.1 and want to be pinned to 2.6.X
ls /usr/local/Cellar/ansible
2.2.1.0_2 2.3.1.0 2.7.5
brew search ansible
==> Formulae
ansible ✔ ansible-cmdb
ansible-lint ansible#1.9
ansible#2.0 terraform-provisioner-ansible
==> Casks
ansible-dk
brew install ansible
ansible --version
ansible 2.7.5
If someone could point me to the correct docs at https://docs.brew.sh/ to both list all available versions and to install specific versions that would be awesome.

Go to the directory containing formulas:
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
Look at the history of the ansible formula
git log -- ansible.rb
Select the commit where the version you are interested in is and checkout this formula:
git checkout f9466d14ee6e9fa7a -- ansible.rb
Install that formula:
HOMEBREW_NO_AUTO_UPDATE=1 brew install ansible
Check the installation of ansible:
ansible --version
Pin this version of the formula to avoid upgrade
brew pin ansible
That's it, an I'm not sure that this is in the documentation.

Related

New MacBook Homebrew Install Issue

I have a Macbook Pro that has an M1 Chip that is causing issues trying to install Homebrew. I have followed the steps in this article: https://mac.install.guide/homebrew/3.html but when I get to the Homebrew install and I type brew in the terminal I get this
Example usage:
brew search TEXT|/REGEX/
brew info [FORMULA|CASK...]
brew install FORMULA|CASK...
brew update
brew upgrade [FORMULA|CASK...]
brew uninstall FORMULA|CASK...
brew list [FORMULA|CASK...]
Troubleshooting:
brew config
brew doctor
brew install --verbose --debug FORMULA|CASK
Contributing:
brew create URL [--no-fetch]
brew edit [FORMULA|CASK...]
Further help:
brew commands
brew help [COMMAND]
man brew
https://docs.brew.sh
Shouldn't it tell me what version of Homebrew I have and that it's installed?
I am trying to set up my Homebrew so that I can use it with git. I am trying to do brew install git and brew install git-lfs but I get the below error messages when I try to do that.
fatal: Could not resolve HEAD to a revision
Warning: No available formula with the name "git".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.
Shouldn't it tell me what version of Homebrew I have and that it's installed?
To find the installed version, use the -v option.
% brew -v
Homebrew 3.6.0
Homebrew/homebrew-core (git revision e5722d08e47; last commit 2022-09-09)
Homebrew/homebrew-cask (git revision 0dc06a0f09; last commit 2022-09-09)
fatal: Could not resolve HEAD to a revision
You will need to reinstall, and make sure it uses /opt/homebrew because you are on an M1.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
There shouldn't be any errors displayed when this runs.

Homebrew does not upgrade pyenv

I'm trying to upgrade pyenv with homebrew for getting new Python releases.
Here is the problem:
$ brew upgrade pyenv
Error: pyenv 1.2.7 already installed
Is there a kind of update latency in homebrew package versioning? I am aware of the existence of other ways to install pyenv, but I'd like to use homebrew.
pyenv 1.2.8 is not yet officially released.
On the master branch the last tag is 1.2.7.
The commit you mentioned in your question is in preparation for release 1.2.8.
Version 1.2.7 is here https://github.com/pyenv/pyenv/tree/v1.2.7
Version 1.2.8 should be here https://github.com/pyenv/pyenv/tree/v1.2.8 but nothing is there (yet).
Verify which pyenv your system is using.
I thought I had this issue but then realized I had two different installs on my computer and my system was not actually using the brew installed pyenv --version.
Grepping my shell history, I saw that at some point I installed pyenv with curl using pyenv-installer for some reason. The command I found in my history was curl https://pyenv.run | bash. I followed the pyenv-installer directions to uninstall. Make sure to restart your shell once you uninstall!
I then reinstalled pyenv with brew. brew reinstall pyenv though I'm not sure if that's necessary.
I now see the newer versions of python available for install with pyenv install --list

what exactly does the command brew -v do and how can i undo it?

I am new to using homebrew, and in my naivety i tried the command brew -v to see if that would give me the version of homebrew i have installed, but instead i got this output:
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.3.7.leopard_64.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.3.7.leopard_64.bottle.tar.gz
Homebrew 1.7.3-17-g817b72d
Homebrew/homebrew-core (git revision 6b80; last commit 2017-12-22)
i am not sure what that just did and where to find it in my system, or how to undo/uninstall whatever i just installed.
Any help would be appreciated
Im on a mac running High Sierra
If I type brew -v, I obtain:
Homebrew 1.7.3-2-g654ad46
Homebrew/homebrew-core (git revision 8a091; last commit 2018-09-03)
In your case, it first install portable-ruby because you never run this command before and homebrew needs this package to run.
This is just a normal behavior.

brew upgrade <package> does not update to the latest version

I've noticed this happening a few times but this most recent instance is with wp-cli Running brew upgrade wp-cli does not download the latest version.
$ brew upgrade wp-cli
Error: homebrew/php/wp-cli 0.20.1 already installed
$ brew info wp-cli
homebrew/php/wp-cli: stable 0.20.1, HEAD
A set of command-line tools for managing WordPress installations.
http://wp-cli.org/
/usr/local/Cellar/wp-cli/0.20.1 (2635 files, 15M) *
Built from source
From: https://github.com/Homebrew/homebrew-php/blob/master/Formula/wp-cli.rb
Note the version is 0.20.1. When I check the formula repo, I see,
head "https://github.com/wp-cli/wp-cli.git"
When I check that repo, I see that the version in the master branch is 0.24.0. brew info and wp --version both return 0.20.1. Why isnt Homebrew grabbing the latest version? How do I force it to get the latest?
You'll need to run brew update first to force brew to update its list of formulae.

How can I brew link a specific version?

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)

Resources