Fix apt-get: Could not resolve in no time

apt-get is the default choice of package manager on Debian/Ubuntu and their derivatives. Most of the time, it works right out of the box without any problems. But there are a few rare cases, it outputs strange error messages which can cause confusion among new users and even junior developers.

One of the common errors is “apt-get: Could not resolve”. The error indicates that apt-get is having a problem reaching its mirror at Whether it’s something related to the DNS or internet connectivity varies between different setups.

This article is going to show you a few things you can do whenever encountering “apt-get: Could not resolve” error.

apt-get: Could not resolve error

Typically, the error message should look something like below :

[email protected]:~$ sudo apt-get update Hit:1 bionic-security InRelease Err:2 bionic InRelease Could not resolve '' Err:3 bionic-updates InRelease Could not resolve '' Err:4 bionic-backports InRelease Could not resolve '' Reading package lists... Done W: Failed to fetch Could not resolve '' W: Failed to fetch Could not resolve '' W: Failed to fetch Could not resolve '' W: Some index files failed to download. They have been ignored, or old ones used instead.
Code language: PHP (php)

For users who have chosen a preferred Ubuntu mirror earlier, the address apt-get tries to resolve may look a bit different. For example, it could be instead of, or something wildly different such as

Check your DNS settings

Most of the time, the cause lies in your DNS settings. Maybe your preferred DNS server was set to a local address which does not reliably respond to requests at all times. Or you don’t have a preferred DNS server at all, which means all settings are fed to the system by the DHCP server. In either cases, you can try using one of the good, public DNS servers maintained by big companies to solve the problem.

Most Linux distributions store their DNS settings in /etc/resolv.conf file. The settings will then be used globally across all apps installed on the system. All you need to do is edit /etc/resolv.conf using a text editor of your choice. You can do that with nano by running the following command:

sudo nano /etc/resolv.conf

Add the following two lines to the top of the file to use Google DNS as your preferred DNS servers.

nameserver nameserver
Code language: CSS (css)

Once you’re done, save the file and reboot the system so that the changes can take effect afterwards.

Notice: If you need to resolve local addresses inside your network, the aforementioned changes will not allow you to do that. You must either hardcode the IP addresses along with their domain names in /etc/hosts or set up a local DNS server with whitelisting rules for them.

Turn off your VPN

If you’re using a VPN service, try to disable it as some countries (such as China) which do not allow external connections to certain services, including the main Ubuntu servers. In other cases, VPN services can mess up with DNS calls, which can cause a few failed connections to Ubuntu servers. The specific steps to disable VPN varies between services to services, you should consult the official documentation of your provider. If you’re using OpenVPN, follow this guide to disable it.

Check your system-wide proxy settings

If you can browse the address inside the error log (i.e. using another app from the same machine, it’s highly likely that you’re having a problem with proxy settings. Follow the steps below to check if it’s really the root cause:

  • Open Ubuntu Settings app using the Application launcher.
  • Select the Network tab in the left sidebar.
  • Click the cog icon near the Network Proxy label to open up system proxy settings.
  • Try to remove the proxies to see if the problem goes away.

In case you’re behind a proxy, try turning it off or vice versa and then run apt-get update again.

Avoid DNS calls by hard-coding server address

Before requesting DNS servers to resolve domain names to IPs, most major platforms look for their IP address in a local file called hosts. On Ubuntu or Linux based systems, it’s located in /etc/hosts. You can hard-code the IPs of the servers ito hosts file by editing the file and add the following lines to the bottim of the file:
Code language: CSS (css)

Remember to replace the address to IP to fit your specific scenario. You can find out which IP an address translate into by running host -v

Alternatively, you can quickly insert a new line to the file using the command below:

echo "" >> /etc/hosts
Code language: JavaScript (javascript)

We hope that the information above helped you fix apt-get: Could not resolve error message. You may be interested in our guide on other apt errors such as Fix “apt-get : command not found” – everything you need to know (Updated 2022) or apt-get in macOS .

Leave a Comment