Ubuntu 24.04 出现错误:发出 apt-get build-dep 时,您必须在 sources.list 中放入一些“deb-src”URI

Ubuntu 24.04 出现错误:发出 apt-get build-dep 时,您必须在 sources.list 中放入一些“deb-src”URI

在全新安装的 Ubuntu 24.04(不是升级版)上,运行时出现此错误

$ sudo apt-get build-dep -y vlc  
Reading package lists... Done
E: You must put some 'deb-src' URIs in your sources.list

在 24.04 之前的修复是对 进行编辑/etc/apt/sources.list,但现在在 24.04 上:

$ cat /etc/apt/sources.list
# Ubuntu sources have moved to /etc/apt/sources.list.d/ubuntu.sources

这是 24.04 的新文件

$ cat /etc/apt/sources.list.d/ubuntu.sources 
Types: deb
URIs: http://us.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg



Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

我如何添加deb-src新文件/etc/apt/sources.list.d/ubuntu.sources

答案1

与之前的 Ubuntu 版本不同,24.04 版的配置文件位置有了新的变化,文件格式也发生了变化

将以下代码片段添加到新的配置文件中/etc/apt/sources.list.d/ubuntu.sources

Types: deb-src
URIs: http://us.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

笔记如果机器在控制之下cloud-init(对于在家的观众,请忽略这一点,这涉及一些远程云 Ubuntu VM,而不是您的家用笔记本电脑),而是deb-src按照以下方式在模板文件中进行类似的添加

$ cat /etc/apt/sources.list.d/ubuntu.sources 
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
##
## If you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add supplemental sources in /etc/apt/sources.list.d
## c.) make changes to template file
##      /etc/cloud/templates/sources.list.ubuntu.deb822.tmpl
##

如果你想使用一行命令执行此操作:

sed -i 's/^Types: deb/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources

最终更新的文件将成为

cat /etc/apt/sources.list.d/ubuntu.sources 

Types: deb deb-src
URIs: http://us.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg



Types: deb deb-src 
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

相关内容