Homebrew package manager for Mac OS and Linux

Homebrew is a package manager for Mac OS and Linux. You can find more details in http://brew.sh . You can install and uninstall software that you need easily from Command Line Interface(CLI).

There are more than 8500 packages and casks(GUI installation packages) in Homebrew.

Homebrew Cask is the installation and management of GUI macOS applications such as Atom and Google Chrome.

I also posted Chocolatey Package Manager for Windows. Reach out from the following link.

Before installing Homebrew

Firstly, the command-line tools for Xcode should be installed. you can install it by running the following command in a Terminal window.

xcode-select –install

If you already installed Xcode, you can check for softwareupdates.

softwareupdate --list

or you can directly try to update Xcode with the following code

softwareupdate --install xcode-select

Installing Homebrew

Installing Homebrew, in a Terminal window, copy-paste the following command, and press Enter

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Checking Homebrew

brew --version

Checking Homebrew system

Check  your  system  for potential problems with following command.

brew doctor

Updating Homebrew

If you want to ensure the newest version of Homebrew, run the following command in a Terminal window.

brew update

Installing package

Let’s say that you need to use a no sql database (Redis or Mongo, etc.)

brew install redis
brew install mongodb
brew install node

Uninstalling package

If you want to uninstall a package, there are 3 different usages.

If –force is passed, and there are multiple versions of formula installed, delete all installed versions.

brew rm redis
brew remove node
brew uninstall redis
brew uninstall node

Reinstalling package

If you want to reinstall a package again, run the following command in a Terminal window.

brew reinstall redis
brew reinstall mongodb
brew reinstall node

Listing packages

If you want to list all packages installed, then run the following command.

brew list
brew ls

listing in a single column

brew ls -1

Lising in a long format

brew ls -l

Searching packages

Search for text in the given package manager's list.

List all locally available formulae (including tapped ones)

brew search

List all locally available formulae with description

brew search --desc ''

Learning count of packages available in local

brew search --desc '' | wc -l

Let's search for java jdk package. Following code will list packages(Formulaes) and casks(GUI packages)

brew search jdk

searching only in casks

brew search --casks jdk

searching only in formulaes

brew search --formulae jdk

Homebrew Cask (GUI installation packages)

Installing Cask

brew cask install atom
brew cask install google-chrome

or we can install two or more packages in a single line as below.

brew cask install atom google-chrome

Uninstalling Cask

brew cask uninstall atom
brew cask remove atom
brew cask rm atom

Listing casks

Below two commands are depreciated in Homebrew latest version.

brew cask list
brew cask ls

Use the following command instead of any of above commands.

brew list --cask

Learning Cask Information

Display information about cask package.

brew cask info adoptopenjdk

Homebrew Taps (Third-Party Repositories)

brew tap adds more repositories to the list of formulae that brew tracks.

Listing currently tapped repositories

homebrew/core is default repository center but other added manually.

$ brew tap

adoptopenjdk/openjdk
caskroom/fonts
homebrew/cask
homebrew/cask-fonts
homebrew/core

Adding new tap

Assume that we need to install Java JDK, so i search it firstly.

$ brew search jdk

==> Formulae
openjdk
openjdk@11

==> Casks
adoptopenjdk
jdk-mission-control
oracle-jdk
oracle-jdk-javadoc
sapmachine-jdk

let's say we prefer adoptopenjdk cask, if we want to learn more information about this cask, run the following command

$ brew cask info adoptopenjdk

adoptopenjdk: 14.0.1,7
https://adoptopenjdk.net/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/adoptopenjdk.rb
==> Name
AdoptOpenJDK Java Development Kit
==> Artifacts
jdk-14.0.1+7 -> /Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk (Generic Artifact)
==> Caveats
More versions are available in the AdoptOpenJDK tap:
  https://github.com/AdoptOpenJDK/homebrew-openjdk

  brew tap adoptopenjdk/openjdk

so we install adoptopenjdk, we will have 14.0.1,7 in the system. But, output of terminal says that

More versions are available in the AdoptOpenJDK tap:
https://github.com/AdoptOpenJDK/homebrew-openjdk


brew tap adoptopenjdk/openjdk

brew tap adoptopenjdk/openjdk

So what happened after adding new tap(Third-party repository in Homebrew). Run the following code one more time. As shown in terminal, there are more casks related with adoptopenjdk cask

$ brew search jdk

==> Formulae
openjdk                                                                              openjdk@11

==> Casks
adoptopenjdk
adoptopenjdk12
adoptopenjdk13-openj9
adoptopenjdk14-openj9-jre-large
adoptopenjdk9
adoptopenjdk10
adoptopenjdk12-jre
adoptopenjdk13-openj9-jre
adoptopenjdk14-openj9-large
jdk-mission-control
adoptopenjdk11
adoptopenjdk12-openj9
adoptopenjdk13-openj9-jre-large
adoptopenjdk8
oracle-jdk
adoptopenjdk11-jre
adoptopenjdk12-openj9-jre
adoptopenjdk13-openj9-large
adoptopenjdk8-jre
oracle-jdk-javadoc
adoptopenjdk11-openj9
adoptopenjdk12-openj9-jre-large
adoptopenjdk14
adoptopenjdk8-openj9
sapmachine-jdk
adoptopenjdk11-openj9-jre
adoptopenjdk12-openj9-large
adoptopenjdk14-jre
adoptopenjdk8-openj9-jre
adoptopenjdk11-openj9-jre-large
adoptopenjdk13
adoptopenjdk14-openj9
adoptopenjdk8-openj9-jre-large
adoptopenjdk11-openj9-large
adoptopenjdk13-jre
adoptopenjdk14-openj9-jre
adoptopenjdk8-openj9-large

As you can see above output of terminal, we can install adoptopenjdk12 or adoptopenjdk13 or adoptopenjdk8, etc

Ok let's see results, I will install default adoptopenjdk cask package

brew cask install adoptopenjdk
$ java --version

openjdk 14.0.1 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing)

As you can see default adoptopenjdk is latest Java version (this time, it was 14.0.1).

I will install adoptopenjdk10

brew cask install adoptopenjdk10
$ java --version

openjdk 14.0.1 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing)

wait a minute, Java version is still 14.0.1 🙂

So I visited adoptopendjk GitHub repository and it says that we need to add the below function in your ~/.bashrc or ~/.zshrc

jdk() {
        version=$1
        export JAVA_HOME=$(/usr/libexec/java_home -v"$version");
        java -version
 }

and run the following code to source

source ~/.zshrc

or

source ~/.bashrc

We can change version like below

$  jdk 1.8
$  jdk 9
$  jdk 11
$  jdk 13

Removing tap

brew untap adoptopenjdk/openjdk

After adding a new tap, you will

Opening Homepage

Open Homebrew's own homepage in a browser.

brew home

If you want to open a package's homepage in a browser, then use following command.

brew home node

Package Information

Display information about package.

brew info node
brew info openjdk

Detailed Information brew CLI

man brew

Leave a Reply