Solution 1:

See if there's a proxy set in /etc/apt/apt.conf (or somewhere in /etc/apt/apt/apt.conf.d).

There'll be a file with a line something like: Acquire::http::Proxy "http://155.238.4.87:8080";

Comment the line(s) by putting a # at the beginning of it and try again.

Solution 2:

Could not connect to x.x.x.x:8080

Connection to IP:8080 indicates that you're using proxy.

Here are few suggestions:

  • Check by: apt-config dump | grep -i proxy.
  • If proxy is used, edit /etc/apt/apt.conf file or check for config files in /etc/apt/apt.conf.d/ or find by grep -ri proxy /etc/apt/, then adjust or remove the proxy.
  • To check the direct connection to security.ubuntu.com, run:

    curl http://security.ubuntu.com/ && echo Works
    

    To test the connection through proxy, run:

    curl -x http://PROXYIP:8080/ http://security.ubuntu.com/ && echo Works
    
  • To debug networking for apt-get command, you can run:

    strace -f -e network apt-get update 2>&1 | grep -C10 refused
    
  • Check your firewall rules and network configuration.

Solution 3:

I solve this error by removing network settings.

I do :

cat /etc/apt/apt.conf 

If I see this

Acquire::http::proxy "http://macth-with-your-ip-or-dns-setting:8080/";
Acquire::https::proxy "https://macth-with-your-ip-or-dns-setting:9999/";

I go to network system settings and choose network then select Network Proxy Method see drop-down menu, choose manual then DELETE all settings there. Click Apply to save the setting or configuration that you made.

In the terminal do

cat /etc/apt/apt.conf

if there is no output, you have finished and you can apt-get update