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

```
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)

[![enter image description here](https://i.stack.imgur.com/YKnK2.png)](https://i.stack.imgur.com/YKnK2.png)