3 Quick Ways to Fix the “wget command not found” Error

Written by

Reviewed by

Last updated: July 24, 2024

Expert verified

SVG Image

TL;DR

To fix the “wget command not found” error in Linux, you should follow these steps:

  1. Checking if wget is Installed: Open your terminal, type which wget, and press Enter to see if wget is installed.
  2. Installing wget: Run sudo apt-get update && sudo apt-get install wget in the terminal to install wget.
  3. Verifying wget Installation: Type wget –version to check if wget is correctly installed.
  4. Configuring the PATH Environment Variable: Use echo $PATH to check your PATH, which wget to find wget’s location, export PATH=$PATH:/usr/local/bin to add it for the session, and edit ~/.bashrc to make it permanent.
  5. Fixing Permission Issues: Run ls -l $(which wget) to check permissions and sudo chmod +x /path/to/wget to grant execute permissions if needed.

Learn more about fixing the “wget command not found” error in Linux and its effective uses in the article below.

Running into the “wget command not found” error can be annoying, especially when you need to download files quickly. But there’s a simple fix. In this post, I’ll show you how to check if wget is installed, fix the PATH variable, and resolve permission issues. I’ll also introduce you to alternative tools like cURL and aria2. By following these easy steps, you’ll have wget up and running in no time. Plus, I’ll share tips on using wget effectively and securely to get the most out of this handy tool.

What is wget?

Wget is a command-line tool that helps you download files from the internet. It’s very useful for getting files quickly and efficiently, especially when you need to automate downloads.

Key Features

  • Downloading Files: You can download single files or multiple files from the web.
  • Mirroring Websites: Wget can copy entire websites to your local machine for offline browsing.
  • Resuming Downloads: If your download gets interrupted, wget can pick up where it left off.

Example

To download a file, you simply use:

wget http://example.com/file

This command saves the file from the URL to your current directory.

Understanding the “wget command not found” Error

The “wget command not found” error means your system can’t find the wget tool. This is a common issue when wget is not installed or not set up correctly.

Why It Happens

  • Permission Issues: You might not have permission to use wget.
  • Wget Not Installed: Your system doesn’t have wget installed.
  • Incorrect PATH: Your system can’t find wget because its location isn’t listed in the PATH environment variable.

How to Fix “wget command not found” Error in 3 Easy Ways

To fix the “wget command not found” error, first, check if wget is installed by typing which wget in the terminal. If it’s not installed, run sudo apt-get update && sudo apt-get install wget to install it. Verify the installation with wget --version.

If wget is installed but not found, add its path to the PATH environment variable by using export PATH=$PATH:/usr/local/bin and make this change permanent by adding the line to your shell configuration file, such as .bashrc. If there are permission issues, fix them by running sudo chmod +x /path/to/wget to ensure wget has execute permissions.

Continue reading for detailed steps to fix the “wget command not found” error:

1. Checking if wget is Installed

Before you can fix the “wget command not found” error, you need to determine whether wget is actually installed on your system. 

  1. Open your terminal.
  2. Type the following command and press Enter:
which wget

If wget is installed and in your PATH, this command will return the path to the wget binary (e.g., /usr/bin/wget). If not, it will return nothing.

viewing path of wget

2. Installing wget

The easiest way to fix the “wget command not found” error is to install wget on your Linux system. Here are two different methods you can use to install wget:

a. Using Package Manager

To install wget on your Linux system, you can use the package manager that comes with your Linux distribution. Here’s the step-by-step process to do it:

  1. Launch the Terminal and execute the command below to update the package manager and install wget:
sudo apt-get update && sudo apt-get install wget
  1. Enter your user password if prompted and wait for the installation to complete.
update the package manager and install wget
  1. Finally, you can run the command which wget to confirm if wget is installed on your Linux system. This command will display the path to the directory where the wget command is located. Once confirmed, you should no longer encounter the “wget command not found” error.
to check if wget is installed on your linux system

b. Compiling wget from Source

Another way to install wget and resolve the “wget command not found” error is to compile its code from the source. To do so, follow the steps below:

  1. Download the wget source code from the official website.
download the wget source code
  1. Navigate to the wget source code directory location using the cd command in the Terminal app.
cd ~/download-folder-name
  1. Extract the downloaded file by running the following command:
tar -xvf wget-<version>.tar.gz
extract the downloaded wget source file
  1. Configure the source code with the following command:
wget-<version>/configure
  1. Execute the command below to compile the wget source code:
make
  1. Install wget with the following command to fix the “wget command not found” error on your Linux system:
sudo make install

3. Verifying wget Installation

After installing wget, it’s important to verify the installation to ensure it’s correctly set up and ready to use. 

  1. Type the following command and press Enter:
wget --version

If wget is installed correctly, you will see output displaying the version of wget and some additional information. This output confirms that wget is installed and ready to use.

verifying wget installation

4. Configuring the PATH Environment Variable

The PATH environment variable tells your system where to look for executables. If wget is installed but the system can’t find it, you may need to add wget’s directory to your PATH. Follow these steps to configure your PATH environment variable:

  1. In your command prompt enter the following command and press Enter:
echo $PATH

This command displays the current directories in your PATH.

viewing current directories in your path
  1. To determine where wget is installed, run:
which wget

Note the directory path returned (e.g., /usr/local/bin).

viewing path of wget
  1. Now update PATH for the current session:
export PATH=$PATH:/usr/local/bin
updating path for current session
  1. Verify by typing:
echo $PATH

The new PATH should include wget’s directory.

veriffying that the path is updated for current session
  1. To make PATH changes permanent, edit your shell configuration file (e.g., .bashrc, .bash_profile, or .zshrc). For example, using nano for .bashrc:
nano ~/.bashrc
opening shell configuration file in nano editor
  1. Add the following line at the end of the file ():
export PATH=$PATH:/usr/local/bin

Replace /usr/local/bin with the actual path

adding path permanently in configuration file
  1. Save and close the file.
saving and exiting the configuration file
  1. Reload the configuration file:
source ~/.bashrc
reloading the configuration file
  1. Verify the PATH change:
echo $PATH
verifying the path changes

5. Fixing Permission Issues

Permission issues can prevent wget from running correctly, even if it’s installed. Here, I will guide you through checking and fixing permissions for wget to ensure it has the appropriate access rights.

  1. To view a file’s permissions, use:
ls -l /path/to/wget

The output format shows permissions, owner, and group (e.g., -rwxr-xr-x).

  1. To check wget permissions, first find wget’s location:
which wget
  1. Check permissions:
ls -l $(which wget)
  1. Verify that the permissions include an x (execute) for the user, group, or others.
checking wget permissions
  1. If necessary, grant execute permissions to wget.
sudo chmod +x /path/to/wget

Replace /path/to/wget with the actual path obtained from which wget.

granting execute permissions to wget

Using Alternative Tools to wget

If the above methods don’t fix the “wget command not found” error, try using alternative tools to get wget. Here are some options:

  1. cURL: cURL is a command-line tool used for transferring data to and from servers. It is similar to wget and can be used as an alternative to it.
  2. aria2: aria2 is a command-line tool used for downloading files from the internet. It can simultaneously download files from multiple sources, making it faster than wget.

Here’s how to install and use cURL:

  1. Press Ctrl + Alt + T to open the Terminal app.
  2. Install cURL by running the following command: 
sudo apt-get install curl
to install and fix wget Command Not Found Error in Linux
  1. To download a file using cURL, run the following command:
curl -O <url> 

Replace <url> with the URL of the file you want to download.

And here’s how to install and use aria2:

  1. Head to the Terminal window on your Linux system.
  2. Run the following command to install aria2 on your Linux system :
sudo apt-get install aria2
command to install aria 2 on your linux
  1. To download a file using aria2, run the following command:
aria2c <url>

Replace <url> with the URL of the file you want to download.

8 Best Practices for Using wget in Linux

While wget can be a powerful and useful tool, it’s important to know how to make the most of it. Here are some best practices for using wget in Linux:

  • 🔍 Check the source: Always check the source of the file you’re downloading to ensure it’s legitimate and safe. Don’t download files from untrusted sources or websites you’re unfamiliar with.
  • 💾 Use -i for batch downloads: Use the -i option to download multiple files from a list. This can save you time and effort if you need to download a large number of files. For instance, you can run wget -i list.txt if the list exists in a text file.
  • 💻 Be Mindful of Bandwidth Usage: Be mindful of bandwidth usage when downloading large files or multiple files at once. This is especially important if you’re on a limited bandwidth connection or if you’re downloading files from a server that’s far away. To limit download speed to 1MB/s, use the wget --limit-rate=1m http://example.com/file.zip command line via Terminal.
  • Use -nc to prevent overwriting: Use the -nc option to skip downloading files that are already in the target directory. It lets you prevent overwriting important files and save space on your Linux system. Your command should look like this: wget -nc http://example.com/file.zip
  • ⚠️ Be Caution with Recursive Downloading: Recursive downloading is useful for downloading entire directories or websites. However, it can be resource-intensive and quickly fill up your hard drive if you’re not careful. For example, if you want to limit the recursive depth to 2, use the wget -r -l 2 http://example.com/ command.
  • ↩️ Use -c to resume interrupted downloads: Use the -c option to resume downloading a file from where it left off if the download was interrupted for any reason, such as a lost internet connection. Your command would be similar to wget -c http://example.com/file.zip if you are downloading a file from a URL.
  • 🔇 Suppress output with the -q option: Use the -q option to suppress output from wget. This can be useful if you’re running wget in a script or automated process and don’t want to clutter the output with unnecessary information. An example of this command is: wget -q http://example.com/file.zip
  • 📂 Use -P to specify the download directory: Use the -P option to specify the download directory. This option is helpful when saving downloaded files to a particular directory instead of the current working directory. The command syntax would be: wget -P /path/to/directory http://example.com/file.zip

Key Takeaways

In this article, I walked you through fixing the “wget command not found” error. I have covered checking if wget is installed, configuring your PATH, and fixing permissions. I also introduced alternatives like cURL and aria2, and shared best practices for using wget effectively and securely, so you can get the most out of this powerful tool.

To expand your knowledge, check out these suggestions:

Frequently Asked Questions

What is wget Command?

wget is a command-line utility used for downloading files from the internet. You can download entire websites or specific files from websites. Here are some common use cases of the wget command:
Downloading files from a website
Downloading entire websites for offline browsing
Retrieving files from FTP or HTTP servers
Downloading files recursively

Can wget download files recursively from a website?

Yes, wget can download files recursively from a website using the -r option. This tells wget to follow links and download all files that it finds on the website. However, it’s important to use this feature responsibly and not download more data than you need or overwhelm the website’s servers with too many requests.

Is wget pre-installed in Linux distributions?

While wget is not pre-installed in all Linux distributions, it is widely used and available for download on most of them. One of the reasons why wget is not pre-installed on some Linux distributions is that it is a relatively specialized tool. Not all users need to download files from the command line, so some distributions opt not to include it by default.

How can I check if wget is installed on my system?

To check if wget is installed on your system, open a terminal window and enter the command which wget. If the wget is installed, it will show the path to the wget executable. If it’s not installed, you’ll get an error message saying, “wget command not found.”

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

[7 Proven Fixes] “gpg: no valid OpenPGP data found”

Next Post

How to Check Memory in Linux [8 Easy Ways]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next