How to Install and Use Wget on Mac

wget is a robust command line application for downloading URL-specified resources. It was designed to work excellently even when connections are poor. Its unique feature, compared to curl which ships with macOS, for example, is that it is non-interactive so it can run in the background.

There are 2 ways to install wget: via Xcode or via Homebrew and I will cover both methods since not everyone uses Xcode or Homebrew.

Installing Wget via Xcode

Installing wget on Mac via Xcode requires you to build the tool from source and the steps are the same on all a Mac versions:

First, install Xcode via iTunes and then install Xcode command line tools with the command:

# xcode-select --install

Download wget source code using curl:

# cd ~/Downloads
# curl -O https://ftp.gnu.org/gnu/wget/wget-1.19.5.tar.gz

Extract and navigate into the folder and run the configure command:

# tar -zxvf wget-1.19.5.tar.gz
# cd wget-1.19.5/
# ./configure

Make and test wget:

# make
# make install
# wget http://ftp.gnu.org/gnu/wget/wget-1.19.5.tar.gz

If you get an error when you run the configure command then run it with an SSL flag like so:

# ./configure --with-ssl=openssl

Remember to delete the now-unnecessary files after the installation is complete.

Installing Wget via Homebrew

Homebrew is a package manager for OS X that makes installing and managing applications a lot easier for Mac users.

There are alternatives like Fink and MacPorts but I prefer using Homebrew. Don’t worry if you don’t have it installed, I’ve got you covered:

Install Homebrew using the following command, it will also install Xcode’s command line tools if they aren’t already installed:

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

Next, install wget command-line download client.

# brew install wget

How to Use Wget on Mac

As long as a file or directory’s URL is publicly accessible, you can download it and files can be downloaded singly or recursively when downloading directories.

Downloading a single file
# wget -X path/to/local.copy http://example.com/url/to/download.html

The syntax is simple. the wget command, -X to indicate the file path (unless you want to save the downloaded content to your current working directory), and the public link.

Downloading a directory
# wget -e robots=off -r -np https://www.w3.org/History/19921103-hypertext/hypertext/

The -e robots=off flag tells wget to ignore restrictions in the robots.txt file which is good because it prevents abridged downloads. -r (or --recursive) and -np (or --no-parent) tells wget to follow links within the directory that you’ve specified. Voila!

While that is all that you need to know to use wget for downloading files, there are many other commands that’ll enable you to control its usage and you can access them within your terminal in wget’s man page or online.

Have you got any questions to ask or suggestions to make? Feel free to drop your thoughts in the comments section below and don’t forget to share.

Divine Okoi is a cybersecurity postgrad with a passion for the open-source community. With 700+ articles covering different topics in IT, you can always trust him to inform you about the coolest tech.

Each tutorial at GeeksMint is created by a team of experienced writers so that it meets our high-quality writing standards.

8 thoughts on “How to Install and Use Wget on Mac”

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

    Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash. Please migrate to the following command:

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

    Reply

Got Something to Say? Join the Discussion...