multiple side-by-side versions with Homebrew? - homebrew

Is it possible to install multiple versions side-by-side with Homebrew?
I find myself in a situation needing sbt-0.7.x, sbt-0.10.x and sbt-0.11.0. I've installed both sbt-0.7.7 and sbt-0.10.1 manually at the moment to work around the issue (with sbt-0.11.0 being the latest 'sbt' from Homebrew).

Yeah. When you install a new version of a package, it keeps the old one. The symlinks in /usr/local/bin or wherever point to the latest version, but you can still call the binaries (or link to the libraries) in the older version.
brew list to see what's installed. You can look in package directories to see all the versions; or call brew list --versions to see all packages and all versions.

To easily switch between versions of formulae, you can use:
brew switch <formula> <version>
For example:
brew switch gradle 3.2.1
To list which versions you have installed try:
brew list --versions
or:
brew list <formula> --versions
If you want to get rid of older versions, just use:
brew cleanup

As of Homebrew 2.0.0, it would remove old packages automatically when brew upgrade is called. (https://brew.sh/2019/02/02/homebrew-2.0.0/). To opt-out of this behavior, set the environment variable: export HOMEBREW_NO_INSTALL_CLEANUP=1

Related

How are different package versions supported in homebrew?

homebrew supports the installation of different versions of a package.
Homebrew install specific version of formula?
But I don't see different versions specified in homebrew formulas.
https://github.com/Homebrew/homebrew-core/blob/master/Formula/bash.rb
Does anybody know how the support of different versions of a package is implemented in homebrew? Thanks.
There is at least three different ways package versions are supported by Homebrew.
1) With brew switch, you can switch back to a version of a package you already installed. For example typing brew switch ansible, I obtain:
ansible installed versions: 2.7.5, 2.7.6
using brew switch ansible 2.7.5, I can switch back to an old version, but this works only for versions that have been already installed.
2) With versioned formulas, you can choose an old version of MySQL with brew install mysql#5.5 or brew install mysql#5.6. This works because there is the corresponding formulas: mysql#5.5.rb and mysql#5.6.rb.
3) You can use the git history to go back to any version of a formula, read this question/answer for details: Install older version of Pandoc (<2) using homebrew

brew doctor warnings - delete or ignore?

After I installed Homebrew,
Then I try the brew doctor command, there comes warnings:
Could I know the reasons and How to fix it? Could I just ignore these warnings?
The files reported by brew doctor are added by a software (that you manually installed before installing Homebrew) that uses a library for the Tcl/Tk language.
Homebrew also provides a library for Tcl/Tk and the existing files will conflict with those installed by Homebrew if you install a package that requires the Tcl/Tk library.
You don't have to worry for now and, very important, don't try to "fix" anything (especially don't remove files).
What you can do to "fix" it is to find out what program installed those files (it was not installed using the App Store, you installed it manually) and see if Homebrew provides it. If it is a macOS GUI application then Homebrew doesn't provide it (it contains only command line applications, no GUI) but Homebrew Cask might do it.
Use
$ brew search app
or
$ brew cask search app
If you are lucky and you find it and you are pleased with the version provided by Homebrew then you can uninstall the application using the uninstaller it hopefully provides then reinstall it using Homebrew (or Homebrew Cask).
You can run brew doctor between uninstall and reinstall to make sure the uninstaller removed all the files listed in the output of brew doctor now.
As written at the beginning of brew doctor's output, you can safely ignore these warnings if everything you use Homebrew for works fine.

Homebrew updates and app self updates

How does homebrew/cask's updates work if the app auto updates itself.
Example: Chrome or Firefox
These two apps auto update themselves.
But what happens when you run a brew update?
Does it detect that it is already updated or does it check an internal list of apps it installed (misses that it is already updated) and reupdates the app>
brew cask upgrade is possible as of version 1.3.9
The Homebrew Cask repository is technically a Homebrew Tap.
This means:
It will pull down the latest Casks every time you issue the Homebrew command brew update
You can check for outdated Casks with brew cask outdated and install the outdated Casks with brew cask upgrade
Most importantly for this question, applications that update themselves include auto_updates true. This means that these casks are ignored by brew cask outdated and brew cask upgrade. This can be overridden by adding --greedy to the command.
See the Firefox cask as an example:
url "https://download-installer.cdn.mozilla.net/pub/firefox/releases/#{version}/mac/#{language}/Firefox%20#{version}.dmg"
appcast 'https://www.macupdater.net/cgi-bin/check_urls/check_url_redirect.cgi?url=https://download.mozilla.org/%3Fproduct=firefox-latest-ssl%26os=osx'
name 'Mozilla Firefox'
homepage 'https://www.mozilla.org/firefox/'
auto_updates true
Further reference is here.
Homebrew doesn't follow a new version of cask apps automatically, and you can leave such apps to their own auto updates as Homebrew intends to leave it to their own upgrade systems and e.g.
brew upgrade google-chrome
does nothing even when google-chrome has got a new update.
N.B. Now with Homebrew 2.5.5, brew cask was deprecated and integrated to the normal brew.
If you want to do for cask explicitly, you may want --cask
brew upgrade --cask google-chrome
but all the same basically.
Should you want to follow the latest version on your Homebrew proper, you can run such a command as
brew upgrade --greedy google-chrome
Also you can check a diff between the latest and your local with
brew upgrade --greedy --dry-run google-chrome
This way however is mostly for cask apps without their own upgrade systems and you don't need these commands for those with the upgrade systems as long as you're not concerned about your version numbers on Homebrew.
No. There is no brew cask upgrade.

How can I tell which homebrew formulae are upgradable?

I know when I brew update, it lists all ==> Updated Formulae, but when I've updated several times without running brew upgrade, how do I get a list of all apps that could be upgraded?
Per homebrew code on github, this shows all apps that can be updated:
brew outdated
brew help does not list the command, but it is documented in man brew.
Since Homebrew 2.6.0 released in 2020.12.01, brew outdated behaves a little differently.
# update package repo
brew update
# list outdated pkgs, both formula and cask
brew outdated
# list formula only, the old behavior of
# `brew outdated` before brew 2.6.0
brew outdated --formula
# list cask only
brew outdated --cask
In Homebrew's jargon, a package is called a "Formula". Homebrew is not only manages TUI apps, it's also capable of managing GUI apps. A package for a GUI app is known as "Cask".
Before Homebrew 2.6.0, brew outdated only list formulae. Since 2.6.0 brew outdated both of formulae and casks.

Ignore formula on brew upgrade

I want to do a brew upgrade and tell homebrew do not upgrade the erlang formula since the latest one does not work on my system.
Is it possible do do something like homebrew upgrade --skip erlang?
I finally found an answer: since commit 85eb73ce there is a pin subcommand available. So ignoring a formula on brew upgrade is as simple as pinning it via brew pin <formula>. To un-pin it, simply invoke brew unpin <formula>.
It is worth noting that brew upgrade <formula> will still update the formula regardless of whether or not it is pinned.
Caveat: This answer is no longer valid for recent versions of Homebrew, since brew pin has been removed.
brew pin is the way to go. It will pin the formula to the current version
brew pin <formula>
brew unpin can be used to reset this
brew unpin <formula>
To view all pinned formulae
brew list --pinned
Note: brew upgrade will not upgrade pinned formulae.
You could upgrade erlang to the latest version but keep using the older working version with the brew commands versions and switch.
To list available versions use:
brew versions erlang
To switch between two installed versions (I'll presume you wanted erlang R14):
brew switch erlang R14B04
i had a similar 'problem'. i installed libfreenect (unstable) directly on my system. and now i dont want homebrew to upgrade it. i solved it by deleting following file:
/usr/local/Library/Formula/libfreenect.rb
analogous it would be /usr/local/Library/Formula/erlang.rb for you

Resources