Package Managers are essentially software applications that help users to: Search, Download, Install, Remove and Update software applications on their computer operating system. These can be either Command Line tools or a complete Graphical User Interface application. In What is a Linux Package Manager we discussed package managers from a Linux Perspective.
What is Homebrew
Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple's mac OS operating system and Linux. The name is intended to suggest the idea of building software on the Mac depending on the user preference.
Homebrew is billed as the missing package manager for Mac OSX. It simplifies the task of installing terminal utilities and graphical applications using the terminal window. It is designed to look and act like a typical
*nix package manager.
Homebrew has spawned several sub-projects such as Linuxbrew, a Linux port now officially merged into Homebrew; Homebrew Cask, which builds upon Homebrew and focuses on the installation of GUI applications and taps dedicated to specific areas or programming languages and Frameworks like PHP & NodeJS etc.
Why use Linuxbrew
There are a few reasons you might want to opt to use Linuxbrew instead of your system standard package manager.
First, there is no need to use
sudo to install packages. You don't even necessarily need root privileges to install Linuxbrew itself.
Packages are installed in either your
$HOME directory or a Linuxbrew-specific home directory.
How to install Linuxbrew
In order to install Linuxbrew, you will need to ensure that your system as the following dependencies are installed:
- Build Essentials
To ensure all these packages are installed use
sudo apt-get install build-essential curl file git
Once all dependencies have been installed, we can now install Linuxbrew.
Linuxbrew is not actually available in any Distro package managers and therefore we will need to make use of bash and curl to install the application. It is well worth taking the time to visit the Linuxbrew GitHub repository to check whether the instructions have changed.
At the time of writing the instructions were as follows:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
Once the command has completed then we need to add the following to our
~/.profile which can be done using any text editor. Personally I tend to make use of
nano , so typically will use
nano ~/.profile to open the file for editing and paste the code below, at the bottom of the file.
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv) test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
Save and exit the file, then we can simply refresh the terminal window using either
. ~/.profile or closing and open a terminal window.
Homebrew makes it really easy to install, update and maintain various packages on your system which is really useful for developers.
A common use case for developers is to install various compilers or frameworks. For Node.JS developers they may need to install different versions of the Node to support a number of different projects. For this purpose, Node Version Manager (nvm) helps them to easily install and switch to different versions libraries on there machine.
Homebrew helps developers to easily install nvm to their machines. To install nvm using Homebrew use
brew install nvm
Once complete you will be prompted to edit your
~/.bashrc file to add the following
export NVM_DIR="$HOME/.nvm" [ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && . "$(brew --prefix)/opt/nvm/nvm.sh" # This loads nvm [ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && . "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
Save and Exit your
~/.bashrc file and then refresh your current terminal window using
. ~/.bashrc and nvm is ready for use. You can check your version of nvm using
Search for packages
Homebrew has loads of useful packages. You can view the list of packages available using
The list can also be viewed at Homebrew Formulae
If you would like to search for a package via description you can use
brew search --desc "manage multiple node"
This will return all the packages that will help to manage multiple node versions. To get more information about a particular package, in our case we want to learn more about nvm we can use.
brew info nvm
If you want a list of commands that are available for use in Homebrew, you can simply use.
In addition to the help command-line switch, Linuxbrew also has a detailed instruction manual available. To view it use
How to remove packages with brew
To remove or uninstall packages with Homebrew is really easy, using the
brew uninstall packageName
Using Homebrew you can also use the
remove command to uninstall the package, both methods are synonymous with each other and achieve the same goal.
brew remove packageName
Update and Upgrade packages
Probably the biggest advantage of using Brew to install development based packages on your machine, is that I have noticed packages are updated far more frequently. So as in my case, I use brew to install packages like the Github CLI, AWS CLI and dotnet, Node Version Manager etc, the latest versions of these packages always seem to appear in the HomeBrew repository far quicker than they do in the other repositories.
Updating and upgrading packages in homebrew is really easy and follows simimilar process to other Linux package managers.
To update your repository simply use
To upgrade all your packages simply use
Homebrew is a tool that makes it even easier to install applications on Linux. It is not intended to replace the traditional package managers, but rather works as a complement to them.