How to Fix “wget: command not found” in Linux: A Complete Guide

Fix “wget: command not found” in Linux with this step-by-step guide for RHEL, Ubuntu & more. Learn installation, troubleshooting & best practices.

The wget command is a powerful command-line utility used for downloading files from the internet. It is widely utilized by IT professionals, Linux administrators, and developers to retrieve large files, mirror websites, and automate data transfers using various protocols like HTTP, HTTPS, and FTP.

wget: command not found

However, users may sometimes encounter the error message:

wget: command not found

This error typically occurs when wget is not installed or is missing from the system’s PATH. In this comprehensive guide, we will cover how to fix this issue by installing wget on Linux, specifically for Red Hat-based (RHEL 8/9, Oracle Linux) and Debian-based (Ubuntu) distributions. We will also explore best industry practices for using wget effectively.


Checking if wget is Installed

Before installing wget, check if it is already installed by running the following command:

which wget

If wget is installed, the output will show its location, for example:

/usr/bin/wget

If no output is returned or you receive the error message wget: command not found, it means wget is not installed or is not in the system’s PATH.


Installing wget on Linux

1. Installing wget on Red Hat-Based Distributions (RHEL 8/9, Oracle Linux)

For Red Hat-based systems, use dnf to install wget:

sudo dnf install wget -y

2. Installing wget on Debian-Based Distributions (Ubuntu)

For Ubuntu and other Debian-based systems, use apt to install wget:

sudo apt-get install wget -y

Verifying the Installation

After installation, confirm that wget is available by running:

wget --version

Example output:

GNU Wget 1.21.2 built on linux-gnu.

This output confirms that wget is installed and ready for use.

See also  How to Verify Linux System on SSD or HDD

Real-World Examples of Using wget

  1. Downloading a File
    wget https://example.com/file.zip
    

    This command downloads file.zip from example.com.

  2. Downloading Multiple Files
    wget -i urls.txt
    

    This command downloads multiple files listed in urls.txt.

  3. Downloading Files in the Background
    wget -bqc https://example.com/largefile.iso
    

    This command downloads largefile.iso in the background.

  4. Resuming an Interrupted Download
    wget -c https://example.com/largefile.iso
    

    This command resumes a previously interrupted download.


Troubleshooting wget Installation Issues

1. Command Not Found Even After Installation

  • Run hash -r to refresh the shell’s command cache.
  • Check if wget is in /usr/bin/ by running:
    ls /usr/bin/wget
    
  • If not found, reinstall wget using the installation steps above.

2. Permission Denied Error

  • Run wget with sudo:
    sudo wget https://example.com/file.zip
    

3. SSL Certificate Issues

  • If you encounter SSL-related issues, use:
    wget --no-check-certificate https://example.com/file.zip
    

    However, this should only be a temporary fix.


Best Industry Practices When Using wget

  1. Use HTTPS Whenever Possible
    Always download files over HTTPS to ensure data integrity and security.
  2. Use the -q or -nv Option for Silent Execution in Scripts
    When running wget in automated scripts, use:

    wget -q https://example.com/file.zip
    
  3. Limit Download Speed to Avoid Overloading Servers
    wget --limit-rate=500k https://example.com/file.zip
    

    This limits download speed to 500 KB/s.

  4. Set User-Agent to Avoid Blocking by Servers
    wget --user-agent="Mozilla/5.0" https://example.com/file.zip
    

    Some servers block automated downloads, so setting a user-agent can help.


Conclusion

The wget: command not found error can be easily resolved by installing wget using dnf (for RHEL 8/9, Oracle Linux) or apt (for Ubuntu). This guide has provided step-by-step installation instructions, real-world examples, troubleshooting tips, and best practices to optimize your usage of wget in Linux environments.

By following these best practices, IT professionals, Linux administrators, and developers can efficiently download and manage files on their servers. If you encounter any issues, refer back to the troubleshooting section to resolve them quickly.


Leave a Comment