Ubuntu 20.04: Download package source code with apt source

This article will describe enabling deb-src and download package source code with apt source.

1 Before deb-src is enabled

The apt source will be failed by default. This is because deb-src is comment out in /etc/apt/sources.list.

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

2 Enable deb-src

#!/bin/sh -e

grep '^deb ' /etc/apt/sources.list | \
  sed 's/^deb /deb-src /g' | \
  sudo tee /etc/apt/sources.list.d/deb-src.list

sudo apt update -y
sudo apt install -y dpkg-dev

3 After deb-src is enabled

$ apt source linux
Reading package lists...
NOTICE: 'linux' packaging is maintained in the 'Git' version control
system at:
<snip>