1

When I was installing it asked me to set up my internet connection, but because the PC I'm installing it on doesn't have a WiFi card, and my Ethernet cable wasn't in, I didn't set up a network. It's installed now but when I try to install anything or when I do apt-get update, it doesn't work it just says

 Failed to fetch: http://...

Does anyone know how I can fix this? I thought it was the repositories so I had a look at them to add/update them and they're fine. My friend told me to reinstall with the Ethernet cable in, but I don't want to do that unless its a last resort.

Zanna
  • 70,465
  • 2
    You have to connect to the Internet to make the connection work. Unless you have manually configured all the wireless stuff your server won't have connectivity to the network and won't be able to fetch updates. Since you set up no networking, that's the problem - apt needs to update and has no networking. You will need to reconnect to Ethernet then to update if you don't have wifi set up. – Thomas Ward Aug 18 '16 at 02:04

1 Answers1

4

When you install offline, it can happen that a bunch of outdated repositories get added to your sources. Assuming you have connected via ethernet now, all you have to do is fix the sources. Remove the broken contents of the sources.list.d directory, making a backup first (and typing carefully!)

cd /etc/apt 
sudo cp sources.list.d sources-d-bak
sudo rm sources.list.d/*

Now try to update again. If you still have problems, you need to edit the sources.list itself and comment out (by inserting a # at the start of the line) the problematic entries

sudo cp sources.list sources-bak
sudoedit sources.list

Leave uncommented at least the lines that mention main and security updates repositories, and most likely you also want to keep universe/multiverse repositories. Comment out the deb-src lines if you do not want to enable downloading source code. The things to keep look something like this (depending on your location):

deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted

deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

deb http://us.archive.ubuntu.com/ubuntu/ xenial universe
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial universe
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe

deb http://us.archive.ubuntu.com/ubuntu/ xenial multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

deb http://security.ubuntu.com/ubuntu xenial-security universe
deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

Comment out any lines that mention sourceforge or other external repositories as the links are most likely outdated. Save and exit and you will be able to update.

Alternatively, @Anwar suggests, based on his own experience, that changing your mirror from the regional to the main Ubuntu mirror could solve the problem.

To do this, remove the region labels in the sources.list, replacing, for example, this:

http://us.archive.ubuntu.com/ubuntu

with this

http://archive.ubuntu.com/ubuntu

Some suggestions to do this quickly: Make a backup copy as before, then use Vim or Vi: sudo vi /etc/apt/sources.list and type (replace us. with your region):

:%s/us.//gc

This deletes instances of us. but is interactive so you can press y to proceed or n to skip and move to the next instance. (When that is done type :wq to save and exit)

or if you prefer (back up first!):

sudo sed -i 's/\/us./\//g' /etc/apt/sources.list

This replaces all occurrences of /us. with / (matching an extra character just in case there is a us. anywhere we don't want to delete)

Zanna
  • 70,465
  • 1
    I always install offline but never faced this problem. I typically select main ubuntu mirror, may be that is the reason. I think a suggestion to try changing mirror would be good. – Anwar Aug 18 '16 at 18:55
  • I'm on a mobile device and can't use proper formatting tools thus can't edit. – Anwar Aug 18 '16 at 19:12
  • @Anwar edited, but let me know (whenever) if it needs improvement – Zanna Aug 18 '16 at 19:42