Fix Software Sources

Linux manages its software from predefined software sources. These are central repositories, from where all official applications and system components can be accessed, downloaded and/or installed. It's very similar to the various app stores on other platforms, only Linux repositories had been around a lot longer, and usually (although not always) contain software that is free, in most senses of the word (bot freedom-wise, and as in no-cost free).

Unfortunately, the Debian 9 installer often makes a bit of a mess with the sources, but quite fortunately, this mess is very easy to clean up.

In the following steps, and everywhere else in this document, we are going to assume that during installation you have in fact assigned a root password, and that sudo is disabled, as is the default behaviour. If you went with a blank root password, you will have to prefix every root level command with sudo, and use the user's password instead. If this seems too difficult, that is because you should have followed the instructions instead of messing with things you've yet to learn about. Anyway, in a later chapter you will learn how to enable/disable the root account, so you can skip there if these instructions don't work, and come back when you know what's happening.

The below quick fix allows you to deal with this quickly and move along. If you are interested in a more detailed explanation of what means what, and why and how, open the TL;DR; section below it. It has a longer walk-through of the same process, that fully explains each step, and what you should know about what is happening.

Quick fix

  • Open a terminal, and acquire root privileges by typing su, then giving your password when prompted, and pressing Enter.

Acquire root privileges

  • Now type the following command to open the sources.list file
nano /etc/apt/sources.list
  • In the nano editor, change the first lines of the file from this:
# 

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 201$

deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 2017$

to this:

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 201$

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 2017$
  • Press Ctrl+X, then press Y to accept the changes, and Enter to save and exit.

A simpler way to do this would be to use the sed command to comment out the lines in the offending file.

You should either gain root privileges with su, or prefix the following command with sudo if you have enabled that option, then type the following command

sed -e '/deb cdrom:/ s/^#*/# /' -i /etc/apt/sources.list && sed -e '/^# $/d' -i /etc/apt/sources.list

The result will not be as pretty as when you do it by hand but will work just as good. (The outcome could be improved with a more elaborate command, or an even more unreadable regular expression, but quite frankly, that would be somewhat overkill when all we need is to place a # sign in front of a line we'll never even see again.)

  • To fix the sources, open a terminal and type the following command into it: su, then press Enter.

  • That's it, two letters. You should then be prompted to enter the root password. Do it, and press Enter again.
  • The prompt in the terminal should have changed from yourusername@yourhostname$ to root@yourhostname#

Acquire root privileges

Noticed how the $ sign has changed to # at the end of the prompt? This means you have elevated (root) privileges. It also means that you need to be careful, the root account has the power to irreparably break a system.

  • Now, to edit the sources, type the following command, and press Enter:
nano /etc/apt/sources.list

The sources.list file will now open in nano, a simple, but incredibly useful command line text editor. The file's contents would be something like this:

# 

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 201$

deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 2017$

deb http://ftp.hu.debian.org/debian/ stretch main
deb-src http://ftp.hu.debian.org/debian/ stretch main

deb http://security.debian.org/debian-security stretch/updates main contrib
deb-src http://security.debian.org/debian-security stretch/updates main contrib

# stretch-updates, previously known as 'volatile'
deb http://ftp.hu.debian.org/debian/ stretch-updates main contrib
deb-src http://ftp.hu.debian.org/debian/ stretch-updates main contrib

That standalone # character, in the beginning, is the problem. See this character means a "comment" in programming, and it's placed there to "comment out" a line from the sources. When the interpreter reads this lot, it will disregard any line starting with #. Unfortunately, this character is in the wrong place. The first two lines should have been "commented out", but instead an empty line, and the first line was disabled.

What this does is it leaves a reference to the CD-ROM in the sources, so that when you want to install software or update stuff, it will ask you to insert the installation CD. When it's commented out, this would no longer happen.

To fix this problem, just put a # character on the second line, which starts with deb-cdrom:.... optionally, you can delete the stand-alone # character from the first line.

When done, your sources.listfile should look like this:

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 201$

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 DVD Binary-1 2017$

deb http://ftp.hu.debian.org/debian/ stretch main
deb-src http://ftp.hu.debian.org/debian/ stretch main

deb http://security.debian.org/debian-security stretch/updates main contrib
deb-src http://security.debian.org/debian-security stretch/updates main contrib

# stretch-updates, previously known as 'volatile'
deb http://ftp.hu.debian.org/debian/ stretch-updates main contrib
deb-src http://ftp.hu.debian.org/debian/ stretch-updates main contrib
  • Now to save and exit, press Ctrl+X.
  • Press Y to indicate that you accept the changes, or if you made a mistake, and want to start again, press N
  • Finally press Enter. The nano editor will exit, with changes to the sources list file saved.

And that's it, you're done.

Now that you've fixed the sources, you will be able to update your system and install new software without issues.