When we develop a production software(like, eCommerce website, or an SaaS) it's never just one programming language that satisfies all the requirements, and we end up using various libraries and software packages, which we must install on our server for the software to run. For example, if you develop a web application in Java using Jax-RS API like: Jersey, RESTeasy etc for REST services, then to run this software you must install Java and the other libraries/APIs used on the server. Also during development, you will have to install these packages in your local computer too.
Homebrew is a software package manager for Mac OS which can be used to install required packages, libraries etc to setup your local development requirements.
Another example, if you decide to learn Python, how will you do that? You will use online tutorials to learn the basics of the language and then practice by creating small programs/scripts in python. Now to run/execute these scripts you will have to install python in your local computer, again, how will you do that? If you are a mac user, you can use Homebrew.
Uses of Homebrew
- Install software packages required for setting up local development environment in your macOS.
- Not only this, you can even use Homebrew to install other softwares like VLC, Google Chrome etc.
- You can install all the UNIX Tools on your macOS using Homebrew.
- Using Homebrew Cask, which is an extensuion of Homebrew, you can even install Binary apps(DMG files)
What happens Behind the Scene?
Whenever we install a new software package or tool, it should be installed in the /usr/local directory, as this is the directory where user specific software packages are installed. Homebrew installs the packages inside this directory, or at times, it installs the packages in their own directory and then symlinks(create soft link) their files into /usr/local/ directory
Belwo we have a step by step guide to install Homebrew on your computer/laptop
To install and run Homebrew on macOS we need to install Command Line Tools on our mac. If you have XCode installed on your local environment then you do not need to do anything and can directly jump to the next step.
To install Command Line Tools, open your terminal(Press Command Spacebar and type in "Terminal" to open the Terminal App) and run the following command.
The above command will install command line tools in your computer, or if you already have that installed, it will show the message "error: command line tools are already installed".
To install Homebrew, run the following command,
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Running this script requires password, so when it asks for the password, provide your user passowrd and press "Enter"
Once this command executes without error(if you get any error, post in comment and we will help you out)
Run the following command to see if everything is installed fine.
This will inform you about the status of Homebrew and will ask you to update a few packages, if required.
Once the installation process is done, we will now put the Homebrew directory at the top of the environment variable PATH in our system. You must be wondering, why we need to do this? Well, to ensure that the Homebrew installations(software packages installed using Homebrew) are given priority over the default Mac OS X tools selected by the OS.
Open or create the ~/.bash_profile file using nano editor:
$ nano ~/.bash_profile
Write the following in the file:
To save the file, once you have added the above line to it, press the control key and the letter O, then press the Enter key. Then you can exit the nano editor by pressing the control key and the letter X together.
To activate the changes made to the bash_profile file, type:
$ source ~/.bash_profile
Using Homebrew to Install Software Packages(Open-source Utilities)
Using Homebrew you can easily search, download, updat and remove open-source utilities, libraries etc that you need for your local development.
To search for any software package:
brew search name-of-the-package
NOTE: Here name-of-the-package will be the name of the utility you want to search for.
To download and install the package:
brew install name-of-the-package
To update the package:
brew update name-of-the-package
To remove the package from your system:
brew remove name-of-the-package
Start using these command and your life will become so much easier. You can even look for software packages available with Homebrew on the Homebrew Formulae webpage.
How to Remove Homebrew from your Mac
If you have Homebrew installed in your macOS and now want to remove it for some reason, you can easily uninstall it by running the following command,
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
If you are a mac user, start using Homebrew, because its' easy to use, manages the complete lifecycle of installations(search, download, install, update and remove) and it is free to use. Share your experience of using Homebrew with us by commenting down below.
You may also like: