12

The following command worked fine on Ubuntu 15.10:

sudo apt-get build-dep emacs24

However, on Ubuntu 16.04 I get the following error when running it:

Reading package lists... Done
E: You must put some 'source' URIs in your sources.list

In 15.10 all lines (around 10 in number) with deb-src in /etc/apt/sources.list where uncommented, whereas in 16.04 the corresponding lines where commented out. For example, here are 4 lines from my current sources.list:

## Major bug fix updates produced after the final release of the
## distribution.
deb http://no.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://no.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

What is the reason for this change?

Next, I would like to avoid manually edit /etc/apt/sources.list each time I do a reinstallation of Ubuntu. How can this (uncommenting the deb-src lines) be done automatically?

4
  • The reason is probably that for most users it's useless time/bandwidth wasting to update the database of available source packages every time. From the GUI where you configure the used repositories, you can easily disable/enable (comment/uncomment) those lines. There are also some sed scripts around.
    – JanC
    Apr 23 '16 at 17:30
  • The python3-software-properties package might be useful to write a Python script too.
    – JanC
    Apr 23 '16 at 17:43
  • @JanC Thanks, I wrote my own script. See answer below. Apr 23 '16 at 17:55
14

I had this same issue on a server install of Ubuntu 16.04, so no GUI. All that I needed was a couple of sed commands.

sudo sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && sudo sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list

Then sudo apt-get update and continue on.

1
  • This worked on 18.04
    – Matthew
    Aug 24 at 16:11
10

Open Software & Updates and enable "Source code".

1
  • 16
    Useless if your ubuntu is a server with just shell Sep 1 '16 at 9:26
2

Here is a (currently untested) Bash script that could be used to uncomment deb-src lines in sources.list :

tempdir=$(mktemp -d)
cd "$tempdir"
source_file=/etc/apt/sources.list
new_file=sources.list.new
perl -pE 's/^#\s+(deb-src)/$1/' "$source_file" > "$new_file"
sudo cp "$new_file" "$source_file"
sudo apt-get update
1
1

simpler solution that does what the others have posted more succinctly:

sudo perl -p -i -n -e "s/# *deb-src/deb-src/"  /etc/apt/sources.list

Key distinctions: Perl has the -i inplace option which modifies files in place; I did not add a suffix for backup files because I didn't want the backup files to accidentally be treated as data files. And " *" deals with optional whitespace. "perl -p -n -e" is mostly the same as "sed -e", though watch out for greedy regex matching.

It has the same limitations the others do: it enables sources even if the original wasn't enabled (i.e. partners), and it doesn't work on /etc/apt/sources.list.d. The following will also process /etc/apt/sources.list.d* but makes a backup first.

(cd /etc/apt/; sudo tar cvf sources.list.tar sources.list sources.list.d);  for i in /etc/apt/sources.list /etc/apt/sources.list.d/*; do sudo perl -p -i -n -e "s/# *deb-src/deb-src/" $i; done
0

Here is a simplification of @Tobi's result that does it on a single call to sed:

sed -i -- 's/#\s\?deb-src/deb-src/g' /etc/apt/sources.list

This adds \s\? which is an optional white space (note the ? needs to be escaped).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.