💄 Как установить и использовать Wget на Mac
wget — это надежное приложение командной строки для загрузки ресурсов, указанных в URL.
Он был разработан для превосходной работы даже при плохом соединении.
Его уникальная особенность по сравнению с curl, который поставляется, например, с macOS, заключается в том, что он неинтерактивен, поэтому может работать в фоновом режиме.
Есть 2 способа установить wget: через Xcode или Homebrew, и я расскажу об обоих методах, так как не все используют Xcode или Homebrew.
Установка Wget через Xcode
Установка wget на Mac через XCode требует сборки инструмента из исходного кода, и шаги одинаковы для всех версий Mac:
Сначала установите Xcode через iTunes, а затем установите инструменты командной строки Xcode с помощью команды:
Загрузите исходный код wget, используя curl:
Извлеките и перейдите в папку и выполните команду configure:
Выполните make и и протестируйте wget:
Если при запуске команды configure выдается ошибка, запустите ее с флагом SSL, например:
Не забудьте удалить ненужные файлы после завершения установки.
Установка Wget через Homebrew
Homebrew — это менеджер пакетов для OS X, который значительно упрощает установку и управление приложениями для пользователей Mac.
Есть альтернативы, такие как Fink и MacPorts, но я предпочитаю использовать Homebrew.
Установите Homebrew с помощью следующей команды,команда также установит инструменты командной строки Xcode, если они еще не установлены:
Затем установите клиент для загрузки из командной строки wget.
Как использовать Wget на Mac
Если URL-адрес файла или каталога общедоступен, его можно загрузить, а файлы можно загружать отдельно или рекурсивно при загрузке каталогов.
Скачивание одного файла
Синтаксис прост. команда wget, -X для указания пути к файлу (если вы не хотите сохранить загруженный контент в текущий рабочий каталог) и публичная ссылка.
How to install wget in macOS? [closed]
Want to improve this question? Update the question so it’s on-topic for Stack Overflow.
Closed 2 years ago .
I try to install wget in MAC OS 10.11.1 but when I run ./configure —with-ssl=openssl I get this error:
How to resolve this problem in OSX 10.11.1?
5 Answers 5
Using brew
And then install wget with brew and also enable openressl for TLS support
Using MacPorts
First, download and run MacPorts installer (.pkg)
And then install wget:
For macOS Sierra, to build wget 1.18 from source with Xcode 8.2.
Since Xcode doesn’t come with OpenSSL lib, you need build by yourself. I found this: https://github.com/sqlcipher/openssl-xcode, follow instruction and build OpenSSL lib. Then, prepare your OpenSSL directory with «include» and «lib/libcrypto.a», «lib/libssl.a» in it.
Let’s say it is: «/Users/xxx/openssl-xcode/openssl», so there should be «/Users/xxx/openssl-xcode/openssl/include» for OpenSSL include and «/Users/xxx/openssl-xcode/openssl/lib» for «libcrypto.a» and «libssl.a».
Go to wget directory, configure:
wget should configure and found OpenSSL, then make:
wget made out. Install wget:
Or just copy wget to where you want.
You may find wget cannot verify any https connection, because there is no CA certs for the OpenSSL you built. You need to run:
New way:
If you machine doesn’t have «/usr/local/ssl/» dir, first make it.
Old way:
Then put cert.pem to: «/usr/local/ssl/cert.pem»
DONE: It should be all right now.
How to Install and Use wget on Mac
wget is a non-interactive command-line utility for download resources from a specified URL. Because it is non-interactive, wget can work in the background or before the user even logs in. The program was designed especially for poor connections, making it especially robust in otherwise flaky conditions. While wget isn’t shipped with macOS, it can be easily downloaded and installed with Homebrew, the best Mac package manager available.
1. Download and Install Homebrew
To install Homebrew, open a Terminal window and execute the following command taken from Homebrew’s website:
You might notice the command called curl , which is a different command-line utility for downloading files from a URL that ships within the Ruby installation included on macOS.
2. Installing wget
Once it has completed installing itself, we will use Homebrew to install wget. In Terminal, run the following command to download and install wget:
You’ll get live updates on the progress of downloading and installing whatever dependencies (software prerequisites) are required to run wget on your system.
If you already have Homebrew installed, be sure to run brew update to get the latest copies of all your formulae.
3. Using wget
The purpose of wget is downloading content from URLs. It’s a quick and simple non-interactive tool for downloading files from any publicly accessible URL.
Download a single file
Like the similar command curl, wget takes a remote resource from a URL and saves it to a specified location on your computer. The command’s structure works like so:
That will save the file specified in the URL to the location specified on your machine. If the -O flag is excluded, the specified URL will be downloaded to the present working directory.
Download a directory recursively
To download an entire directory tree with wget, you need to use the -r / —recursive and -np / —no-parent flags, like so:
This will cause wget to follow any links found on the documents within the specified directory, recursively downloading the entire specified URL path.
That command also includes -e robots=off , which ignores restrictions in the robots.txt file. In general, it’s a good idea to disable robots.txt to prevent abridged downloads.
Other wget Flags
In addition to the flags above, this selected handful of wget’s flags are the most useful:
Controlling the download
- wget -X /absolute/path/to/directory will exclude a specific directory on the remote server.
- wget -nH removes the hostname directories. Remember, the hostname is the part of the URL that contains the domain name and ends in a TLD like “.com.” For example, the folder named “www.w3.org” in our previous example would be skipped, starting the download with the “History” directory instead.
- wget —cut-dirs=# skips the specified number of directories down the URL before starting to download files. For example, -nH —cut-dirs=1 would change the specified path of “ftp.xemacs.org/pub/xemacs/” into simply “/xemacs/,” reducing the number of empty parent directories in the local download.
- wget -R index.html / wget —reject index.html will skip any files matching the specified file name. In this case it will exclude all the index files. The * character can be used as a wildcard, like “*.png,” which would skip all files with the PNG extension.
- wget -i file specifies target URLs from an input file. The input file must be an HTML file or be parsed as HTML with the additional flag —force-html
- wget -nc / wget —no-clobber will not overwrite files that already exist in the destination.
- wget -c / wget —continue will continue downloads of partially downloaded files.
- wget -t 10 will try to download the resource up to 10 times before failing.
Adjusting the level of logging
- wget -d enables debugging output.
- wget -o path/to/log.txt enables logging output to the specified directory instead of displaying the log-in standard output.
- wget -q turns off all of wget’s output, including error messages.
- wget -v explicitly enables wget’s default of verbose output.
- wget —no-verbose turns off log messages but displays error messages.
Conclusion
While that should cover the majority of wget use cases, the downloader is capable of much more. For a full description of wget’s capabilities, you can review wget’s GNU man page online.
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.
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:
Download wget source code using curl:
Extract and navigate into the folder and run the configure command:
Make and test wget:
If you get an error when you run the configure command then run it with an SSL flag like so:
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:
Next, install wget command-line download client.
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
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
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.