How to Easily Add New Commands to Mac’s Terminal

At installation, all Macs contain a wide variety of Terminal commands. However, as you get more experience with Terminal (or if you’re joining us from Linux), you might soon find that some important commands 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. If you’re a Linux user, you’ll 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.

Installing Homebrew

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.

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

homebrew-package-manager-macos-1

This command will run a Ruby script that downloads the Homebrew package manager from GitHub.

3. When prompted, press Enter to continue the installation.

homebrew-package-manager-macos-2a

4. Enter your administrator password when prompted.

homebrew-package-manager-macos-3a

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

homebrew-package-manager-macos-5

Searching for Packages

To find programs and commands to download, you’ll first need to search Homebrew’s database for the program you want. For this example, we’ll search for wget. Wget is a popular Linux command that downloads files from HTTP and FTP servers.

1. Type the following command and press Enter:

brew search wget

homebrew-package-manager-macos-6

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

brew info wgetpaste

homebrew-package-manager-macos-7

3. We can see from the description that wgetpaste will “Automate pasting to a number of pastebin services.” Since wget is an application that downloads files from the Web, that doesn’t sound like what I’m looking for. It also includes wget as a dependency, so I wouldn’t be able to run it without wget anyway.

homebrew-package-manager-macos-8a

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

homebrew-package-manager-macos-9

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.

homebrew-package-manager-macos-10

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

Using new commands

homebrew-package-manager-macos-11

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

1. For example, if we type man wget, we’ll see the man page for wget, just as expected.

homebrew-package-manager-macos-12

homebrew-package-manager-macos-13

2. And we can 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 http://domain.com/file.zip

3. Here’s a real life example of a texture pack I downloaded from TextureMate.

homebrew-package-manager-macos-14

And when the download is completed, I’m returned to the command prompt.

homebrew-package-manager-macos-15

Conclusion

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. It’s easy to add new Terminal commands to your command library using Homebrew.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Alexander Fox

Alexander Fox is a tech and science writer based in Philadelphia, PA with one cat, three Macs and more USB cables than he could ever use.