Ever tried upgrading your system or installing some new package in Ubuntu, but it just keeps popping up with this annoying error?
You’re not alone! This “Failed to Fetch” error happens to many Ubuntu users. But don’t worry, in this guide, we’ll break down what causes this error and how you can easily fix it.
Do you know the causes of this error: "Failed to Fetch"?
It generally happens while APT, the package manager, can't pull packages from the repositories. Some of the possible reasons are here:
1. Outdated or Incorrect Repositories
2. Network Issues
3. Repository Server is Down
4. Proxy/DNS Settings
5. Firewall Blocking
Now that you know what could be causing the issue, let’s dive into how to fix it. 😃
Check Your Internet Connection
Run a simple command to check your Internet connection. i.e;
ping google.com
This would output the response if everything is okay with your network, like below:
Otherwise, you fix up the network and move on.
Update Your Repository List
Run the below command to clean cache and update the list of available packages:
sudo apt clean -y
sudo apt update -y
Sometimes, the repositories just need to be refreshed. The above command will refresh it!
If you are still facing issues like before for updating too. Relax and try updating the correct repositories in your Ubuntu sources.list file. To do it, refer to the blog: https://www.veeble.org/kb/sources-list-file-urls-ubuntu/
Go to the next step if the issue is not solved by now. 🥺
Fix DNS Issues
Try changing your DNS to a public DNS server like Google’s. To do it, just open the /etc/resolv.conf file in a text editor and then update Google nameservers in it, and save it.
sudo nano /etc/resolv.conf
Google nameservers were 8.8.8.8 and 8.8.4.4. Just update them as you can see from the below screenshot:
Now, update again with the command: apt update
-y
This should solve the issue if DNS was the problem.
If you’re behind a proxy (e.g., in a corporate environment), the proxy could be causing the issue. If the proxy is not configured properly, it can block access to repositories. Set the correct proxy settings by editing your environment variables in ~/.bashrc
Refer: Ubuntu Forums
If none of the above solutions work, try rebooting the system and also check the firewall for any blocks to the configured repository servers.
The ‘Failed to Fetch’ error in Ubuntu can seem like a huge headache, but most of the time, it’s a simple fix. If you found this guide helpful, share it with others! And happy package managing!