Wget is a nifty tool available to install on all types of Linux systems. It is a command-line utility that allows Linux users to download files, scripts, and even entire websites from the internet using various protocols, such as HTTP, HTTPS, and FTP. In this tutorial, we will learn the commands required for the installation of Wget on Ubuntu 22.04 or 20.04.
Use Terminal to Install wget on Ubuntu
Just like any other version of Ubuntu, we can also easily install most of the common software directly using the Terminal on Ubuntu 22.04 or 20.04 as well. The same is true for Wget as well, just follow the given steps.
Step 1: Open the Terminal
If you are using the Ubuntu server version with only the Command line interface then you already have the Terminal window; whereas GUI Desktop users can use the keyboard shortcut
T to open it… Alternatively, we can click on the “Show Applications” icon available in the bottom-left corner of Ubuntu Dock, after that type “Terminal” into the search bar, and select its icon to open it.
Step 2: Update Ubuntu Package Lists
Not only in Ubuntu even if you are using any other Linux distro it is recommended to run the system update command before installing some software or package. It is because this not only installs the latest available updates on the system but even refreshes the package manager index cache so that it can recognize the latest application versions available to install.
sudo apt update
Step 3: Installing wget on Ubuntu 22.04 or 20.04
As we have updated the package lists, now we use the APT package manager to download and install Wget using the following command:
sudo apt install wget
Press “Y“, when the command asks for that, and enter your password to complete the installation.
Step 4: Verify the Installation
By now, if you have followed the above-given steps in the right way, Wget will be on your system. To verify that we can check its version on our command terminal.
You should see information about the wget version installed on your system, indicating that the installation was successful.
Commands to use Wget
Here are some common commands that we can use to perform various tasks using the Wget command line utility:
1. To only download
For example, to download a file named “example.txt” from a website, you would use a command like this:
wget will retrieve the file and save it to the current directory.
2. Download a File and Rename It
This command will download “oldfile.txt” from the given URL and save it as “newfile.txt” in the current directory.
wget -O newfile.txt https://example.com/oldfile.txt
3. Download Files Recursively
To download all files from a website recursively, including files from subdirectories, you can use the -r option:
wget -r https://example.com/
4. Limit Download Speed
You can limit the download speed using the –limit-rate option. For example, to limit the download speed to 1 Mbps:
wget --limit-rate=1M https://example.com/largefile.zip
5. Download Multiple Files
To download multiple files in one command, list the URLs separated by spaces. For example: To download “file1.zip” and “file2.txt” to the current directory.
wget https://example.com/file1.zip https://example.com/file2.txt
6. Download Files in the Background
If you want to download a file in the background and continue using the terminal, you can use the -b option:
wget -b https://example.com/largefile.zip
7. Download via FTP
wget can also download files via FTP. For example:
Replace “ftp.example.com/file.txt” with the actual FTP URL.
8. Download with User Authentication
If you need to download a file that requires authentication, you can use the –user and –password options:
Replace “username” and “password” with your credentials.
wget --user=username --password=password https://example.com/securefile.zip
9. Continue an Interrupted Download
If a download gets interrupted, you can resume it using the -c option. Wget will check the existing file’s size and download only the missing part.
wget -c https://example.com/largefile.zip
So, we have seen not only the commands that can be used to install Wget and confirm the same but even a few examples around the usage of Wget. That will help users to download files and resources from the internet.