Getting Started with Terminal: Adding New Commands with Homebrew


As you get more experience with Terminal (or if you’re joining the macOS world from Linux), you might soon find that some important Terminal commands that users reference in online forums are missing. Where’s wget, for example, or nmap? If you need those commands, you can easily add them to the macOS Terminal with a package manager.

A package manager is an application that handles downloading, installing, and upgrading a set of software tools. In this case, our package manager will be responsible for downloading and installing the different Terminal commands that we want to use. Linux users will recognize this functionally from apt-get or yum.

While there are a number of different package managers available for macOS, we’ll use Homebrew for this guide. It’s well regarded, widely used, and easy to get started with. Plus, it’s free.

Note that before you install Homebrew, you’ll need to have the Xcode command line tools installed. This comes with Xcode which is installed from the App Store. You can also install the command line tools without the (very large) Xcode app with the following steps.

1. Open Terminal (/Application/Utilities/Terminal.app).

2. Type the in following command and press Enter:

xcode-select --install

Once you have the Xcode command line tools installed, you can install Homebrew itself and start managing your packages.

1. Open Terminal (/Application/Utilities/Terminal.app).

2. Copy and paste the following command into Terminal and press Enter.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This command will run a Ruby script that downloads the Homebrew package manager from GitHub. You can see that same command on Homebrew’s homepage.

3. Press Enter to continue the installation when prompted.

 

4. Enter your admin password when prompted.

 

5. You’ll be returned to the command prompt when Homebrew is finished installing. From here, you can view Homebrew’s documentation by typing the brew help command, or you can proceed to the next step.

 

Homebrew keeps an exhaustive, user-maintained databases of software utilities that anyone can install. So before we install programs, we’ll need to search for them in Homebrew’s database using the brew search command.

For this example, we’ll search for wget, which is a popular command line utility for downloading files from HTTP and FTP servers.

1. Type the following command and press Enter:

brew search wget

This will search Homebrew’s software database for any software package containing the word “wget.”

2. After a moment, two results will appear: wget and wgetpaste. I don’t know what wgetpaste is, but I can find more info using the brew info command.

 

3. This command tells us that wgetpaste will “Automate pasting to a number of pastebin services.” Since wget is an application that downloads files from the Web, that functionality doesn’t sound like what I’m looking for.

It also includes wget as a dependency, or a required prerequisite, so I wouldn’t be able to run it without wget anyway.

Installing Packages

1. Now that I’ve confirmed that the wget package is the one I want, I’ll type in the following command and press Enter:

brew install wget

This will begin the installation process for the wget package.

2. Homebrew will now start to work its package-managing magic. In addition to wget, I can see that it also installed openssl, which is considered a dependency for wget. A dependency is another software package required to run the downloaded software package. In this case, wget uses openssl to encrypt secure transmissions, so it needs to have access to that software to run properly. This is one of the reasons package managers are so powerful: they handle all the background noise to make sure your software runs successfully.

 

3. When the installation is complete, I’ll be returned to the command prompt.

Now that we’ve installed the wget command, we’ll be able to use it just like any other Terminal command.

1. If we type man wget, we’ll see the man page for wget, just as we would for a pre-installed Terminal command.

 

2. We can now use wget just as we would on Linux. For example, to download a ZIP file from a website, we’d use a command like the one below:

wget https://domain.com/file.zip

This command calls wget and then indicates what publicly-accessible resource it should download to your working directory.

Here’s a real life example of a texture pack I downloaded from TextureMate. This will download the ZIP file at that URL to my current working directory (in this case, my home directory).

 

3. I’m returned to the command prompt once the download is complete.

As you become more experienced with macOS’s terminal, you may begin to realize that some Terminal commands that are common in Linux are missing from macOS. You can easily expand Terminal’s power and your own capabilities using Homebrew.

You might also like the following:

Getting Started with Terminal: Must-Know macOS Terminal Commands

Getting Started with Terminal: Using Grep to Search Files


Alexander Fox

One Comment

Your email address will not be published.