Question: 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?

Answer: 
Sadly `brew switch` is deprecated in [Homebrew 2.6.0](https://brew.sh/2020/12/01/homebrew-2.6.0/) (December 2020)

```
$ brew switch
Error: Unknown command: switch

```

TLDR, to switch to `package` version `10`:

```sh
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](https://brew.sh/2020/12/01/homebrew-2.6.0/). Get it back from [here](https://github.com/laggardkernel/homebrew-tap#external-commands).

```sh
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.

```sh
# 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.

1. In this situation, search in the [homebrew-core](https://github.com/Homebrew/homebrew-core/) repo and download the specific formula. e.g. [mysql 8.0.23](https://github.com/Homebrew/homebrew-core/blob/58946207e43b0e7222f6c920ef4b053e52baf76d/Formula/mysql.rb)
2. Download the **raw** file, and install from it `brew install /path/to/downloaded/mysql.rb`.
3. 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.