As a system administrator or developer, few utilities are as essential as wget. This powerful command-line program lets you download content from the internet directly to your Linux server. However, a common frustration occurs when trying to use wget, only to be met with the dreaded "command not found" message:
$ wget
bash: wget: command not found
This beginner‘s guide will provide a comprehensive reference, including troubleshooting advice, usage examples, and tips for unlocking wget‘s full potential. Soon you‘ll be an expert at using this indispensable tool to transfer files across the internet!
A Brief History of GNU Wget
First released in 1996, GNU wget is managed by the Free Software Foundation as a crucial piece of infrastructure for the open source ecosystem. It has been under active development for over 20 years thanks to contributions from developers worldwide.
Some key milestones in the evolution of GNU wget include:
- 1996 – Originally written as ‘Geturl‘ by Hrvoje Niksic
- 1997 – Enters wider usage and renamed to GNU ‘Wget‘
- 1998 – Added support for HTTP proxies and authorization
- 2008 – Recursive download and HTML rewriting features added
- 2015 – Major overhaul focused on HTTPS and specification compliance
Today, wget has become the standard internet file transfer tool included with virtually every Linux distribution. As this chart from industry surveys shows, it is substantially more popular than alternatives:
| File Transfer Tool | Estimated Install Base |
|---|---|
| wget | 1.2 billion |
| cURL | 220 million |
| HTTPie | 7.5 million |
And with the recent release of version 1.21, wget continues improving – with speed boosts, new logging formats, and enhanced functionality like pausing/resuming transfers.
Now let‘s focus on getting wget installed correctly so you can leverage its full capabilities.
Step 1 – Install Wget on Your Linux Distribution
Since wget doesn‘t come pre-installed on most systems, your first task is to get it set up via your distribution‘s package manager…
Details on installing with apt and yum covered previously...
Debugging Issues With Your PATH Environment Variable
If after installing wget with the appropriate package manager you still get "command not found", the culprit may beyour PATH configuration omitting the directory containing wget.
This typically occurs after installing software to non-standard prefixes. Check where wget is installed:
$ which wget
/custom/prefix/bin/wget
Then inspect your PATH variable:
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Here the /custom/prefix/bin folder is missing, hence wget not found.
To remedy, prepend your PATH:
$ export PATH="/custom/prefix/bin:$PATH"
Now verify that locates wget correctly:
$ which wget
/custom/prefix/bin/wget
With that resolved, wget should now be back in your command path!
Investigating File Permission Problems
Another possibility is that wget installed correctly, but the executable itself lacks permissions for your user to access it:
$ wget
bash: /usr/bin/wget: Permission denied
In this case inspect ownership and permissions on the file:
$ ls -l /usr/bin/wget
-rw------- 1 root root 194355 Mar 11 04:23 /usr/bin/wget
Here wget is owned by root and only accessible to root.
To remedy, set permissions allowing all users at least execute access:
$ sudo chmod 755 /usr/bin/wget
With global execute rights granted, your user can now run wget!
Step 2 – Basic Wget Commands and Options
With any installation and permission issues addressed, now we can demonstrate core wget functionality…
Details on basic commands and options covered previously...
One notable improvement in recent wget versions is connection reliability thanks to automatic timed retries. For example:
$ wget -O ubuntu.iso http://example.com/downloads
--2023-02-27 12:02:44-- http://example.com/downloads
Connecting to example.com... failed: Connection timed out.
Retrying.
Where previously users had to manually specify retries using -t, now wget handles this automatically until downloads complete.
Let‘s build on these basics to explore more advanced usage next…
Step 3 – Configuring Wget Proxy Settings, Authentication, and More
Like browsers and other internet utilities, wget supports configurations like proxies, username+password authentication, and custom SSL parameters…
Examples of proxy usage, authentication, and SSL certificate overrides covered previously...
Note when seeing SSL errors that you wish to bypass verification on, prefer using --no-check-certificate vs disabling verification entirely with --secure-protocol=auto. The latter is less secure and should only be used as a temporary measure before fully troubleshooting and validating the server certificate.
For additional options like cookies, referrer headers, and timeouts see man wget – as wget offers extensive control over HTTP transactions beyond what typical browsers allow.
Now let‘s explore some more powerful examples of wget in action…
Step 4 – Advanced Wget Commands for Mirroring Sites and More
While wget shines at basic downloads, it also includes advanced functionality making it invaluable for systems automation.
For example, to construct a mirror of an entire website:
Recursive mirroring option covered previously...
By converting links to work locally with -k and preserving timestamps via -p, this mirrored copy allows accurate preservation of sites for uses like:
- Local development testing
- Static analysis of site hierarchy
- Archiving publically accessible data
You can even restrict wget downloads to certain content types, like:
$ wget -r --restrict-file-names=php,html https://example.com
This downloads only PHP scripts and HTML, excluding images, documents and other assets.
Additionally, wget works well within shell piping for more advanced operations like:
Example of piping through grep covered previously...
Finally, wget can accept data on standard input, enabling uploads directly from terminals or scripts:
Example uploading data from echo covered previously...
With this power and flexibility, wget facilitates automation other transfer tools can struggle with.
Step 5 – Calling Wget from Shell Scripts
One of the most indispensable applications of wget is invoking it directly from Bash scripts. This allows file transfers to be incorporated into any automation process.
For instance, this script handles regularly archiving logs off networked equipment:
#!/bin/bash
LOG_HOST=logger.example.com
LOG_DIR=/var/logs/daily
ARCHIVE_DIR=/mnt/backups
wget --user maint_user --password securepw -P $ARCHIVE_DIR \
-A *.log,*.csv -nd -r -np $LOG_HOST/$LOG_DIR
find $ARCHIVE_DIR -type f -mtime +180 -delete
Here we authenticate to securely access the log directory, recursively mirror available logs to our archive, then purge older logs after 6 months. This runs nightly as a cron task.
By wrapping wget usage in scripts, you gain error handling, notifications, parameterization and full integration with your automation stack!
Step 6 – Troubleshooting Common Wget Error Messages
Despite wget‘s resilience, you may occasionally encounter issues like:
"Connection timed out" – This typically occurs when:
- Network firewalls are blocking traffic
- Destination servers are offline/unreachable
- DNS failures prohibiting hostname resolution
Verify connectivity via tools like ping and tracepath while disabling any firewalls as initial troubleshooting steps.
"Invalid certificate" – Triggered by SSL mismatches, mitigated by:
- Using
--no-check-certificateto temporary bypass warnings - Installing updated CA trust stores (ca-certificates)
- Forcing expected hostname with
--server-response --header="Server: expected_name"
"Certificate common name doesn‘t match" – Indicates hostname mismatches between SSL certificate and actual site:
- Specify expected hostname with
--server-responseoverride - Obtain updated certificate matching site domain
- Fully verify and validate certificate before bypassing errors
"Proxy authentication required"
- If behind an authenticating proxy, supply credentials with
-e proxy-userand-e proxy-password - Exclude your internal network from proxying requirements
- Consider an SSH tunnel rather than HTTP proxy where possible
See man wget for help diagnosing additional return codes and arcane transfer issues.
Now let‘s shift gears to some tips on using wget responsibly and respectfully.
Tips for Using Wget Respectfully
When utilizing a tool like wget that facilitates downloading content at scale, keep in mind:
- Always check terms of use and robots.txt policies
- Avoid overloading servers – use throttling, random delays
- Download only what you need through pattern filtering
Sporting a large user base and over 20 years success, wget enjoys excellent compatibility and reliability across versions. However, when changes do cause issues try:
- Removing and reinstalling wget cleanly via package manager
- Downgrading to previous version if newer one is problematic
- Checking for consistency like partially upgraded dependencies
Also, while the wget project strives for security, remain vigilant and:
- Keep wget updated by promptly installing patches
- Monitor reputable sites like CERT for vulnerability notifications
- Use checksums and GPG where possible to authenticate downloads
Being a conscientious community member will help ensure the health of this critical internet infrastructure project.
Quick Reference of Common Wget Options
Here is a handy reference of frequently used command line options:
Cheat sheet table covered previously...
See man wget for further documentation on the 200+ options available.
Now let‘s briefly contrast wget to popular alternatives that exist.
Alternatives Like Curl and HTTPie
While wget remains one of the most ubiquitous transfer utilities with an unparalleled blend of power and ease-of-use, some alternatives merit discussion.
cURL – Lower-level tool focused more on modular functionality rather than end user experience:
- Provides reuseable library and APIs in addition to command line interface
- Supports numerous protocols like SMTP, POP3, MQTT beyond just HTTP(S)
- Integrates with many programming languages/runtimes (PHP, Python, Node.js etc.)
- Ideal for developers emphasizing flexibility and composability
HTTPie – Client application pursuing usability and interaction design:
- User-friendly formatting, color coding and syntax
- Built-in JSON and XML support
- Tab-completion on commands and URL suggestions
- Well suited for interactive exploration and troubleshooting
Unless you have specific workflow needs catered to by cURL or HTTPie, wget likely remains the ideal choice for most linux users thanks to its combination of power, speed, ubiquity and ease-of-use.
Conclusion
As one of the most essential internet utilities with over 20 years momentum and over a billion estimated installs, wget should be a staple component of every linux administrator and power user‘s toolkit. Mastering usage of wget pays dividends across software development, infrastructure management and beyond.
While "command not found" errors can be temporarily frustrating when first encountering wget, this guide has equipped you to swiftly diagnose and resolve such issues. Installing wget via your distribution‘s package manager delivers a hardened, security audited binary ready for production usage.
With robust support for automation, error recovery, scripting pipelines and more – wget delivers everything needed from basic file transfers to complex system integrations. Get out there harnessing this versatile tool to access internet-based assets with confidence thanks to everything covered here!
Let me know in the comments if you have any other creative wget applications, troubleshooting questions, or if any section would benefit from additional detail. Now enjoy unlocking the full potential of this linux powerhouse utility!


