apt build-dep fails, unable to locate source package, despite deb-src lines present in the /etc/apt/sources.list.d folder

You need to uncomment the deb-src lines in the main sources file /etc/apt/sources.list, not the extra files in /etc/apt/sources.list.d

For example, change:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial main restricted
#deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial main restricted

to

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial main restricted

Then update the local database:

sudo apt update

and proceed :)


software-properties-gtk option "Source code"

From the GUI, you can run:

software-properties-gtk

then under the "Ubuntu Software" tab click "Source code":

enter image description here

This has added some deb-src lines under /etc/apt/sources.list, and now I can do sudo apt-get build-dep <package>.

Tested on Ubuntu 16.04 to 18.04.

CLI method

sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update

Tested on the Ubuntu 18.04 Docker image. After this change, I can successful do for example:

sudo apt-get build-dep hello

and before the change it failed with the error:

E: You must put some 'source' URIs in your sources.list