系统干净,只安装和更新。问题是:我清理了 /etc/apt/sources.list
:>/etc/apt/sources.list
当尝试添加 repo 时:
add-apt-repository -s "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main restricted"
或者
add-apt-repository -s "deb http://archive.ubuntu.com/ubuntu/ jammy main restricted"
我已经在 sources.list.d 中添加了,但没有在 sources.list 中添加。
root@testu22:~# add-apt-repository -s "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main restricted"
Repository: 'deb http://archive.ubuntu.com/ubuntu/ jammy restricted main'
Description:
Archive for codename: jammy components: restricted,main
More info: http://archive.ubuntu.com/ubuntu/
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_-jammy.list
Adding deb-src entry to /etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_-jammy.list
Reading package lists... Done
添加 apt-repository 之后的 sources.list:
root@testu22:~# cat /etc/apt/sources.list
## See sources.list(5) for more information, especialy
# Remember that you can only use http, ftp or file URIs
# CDROMs are managed through the apt-cdrom tool.
和/etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_jammy.list是空的
第二次运行
root@testu22:~# add-apt-repository -s "deb http://archive.ubuntu.com/ubuntu/ jammy main restricted"
Repository: 'deb http://archive.ubuntu.com/ubuntu/ jammy main restricted'
Description:
Archive for codename: jammy components: main,restricted
More info: http://archive.ubuntu.com/ubuntu/
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.^[[A
Adding deb entry to /etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_-jammy.list
Adding deb-src entry to /etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_-jammy.list
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/restricted Sources [23,7 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main Sources [1 340 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy/main i386 Packages [1 040 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1 395 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/main Translation-en [510 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 DEP-11 Metadata [423 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/main DEP-11 48x48 Icons [100,0 kB]
Get:9 http://archive.ubuntu.com/ubuntu jammy/main DEP-11 64x64 Icons [148 kB]
Get:10 http://archive.ubuntu.com/ubuntu jammy/main DEP-11 64x64@2 Icons [15,8 kB]
Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 c-n-f Metadata [30,3 kB]
Get:12 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [129 kB]
Get:13 http://archive.ubuntu.com/ubuntu jammy/restricted i386 Packages [30,4 kB]
Get:14 http://archive.ubuntu.com/ubuntu jammy/restricted Translation-en [18,6 kB]
Get:15 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 c-n-f Metadata [488 B]
Fetched 5 475 kB in 3s (1 733 kB/s)
Reading package lists... Done
在那之后:
root@testu22:~# cat /etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_-jammy.list
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted
是否可以添加 repo来源列表?
更新: 我发现问题出在空的 sources.list 中。例如,如果在 sources.list 中添加空行或 # 的大小不是 0b。问题部分已修复,但现在 sources.list 中的所有 deb 源和 sources.list.d 中的 deb-src
解决方案:
#!/bin/bash
# clear sources.list but shouldn't be empty
echo " " > /etc/apt/sources.list
# adding repos to sources.lis.d folder
add-apt-repository -n -y "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main restricted universe multiverse"
add-apt-repository -n -y "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-updates main restricted universe multiverse"
add-apt-repository -n -y "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-backports main restricted universe multiverse"
add-apt-repository -n -y "deb http://security.ubuntu.com/ubuntu $(lsb_release -sc)-security main restricted universe multiverse"
# The second run for System indentify it as template:
### Found existing deb entry in /etc/apt/sources.list.d/archive_uri-http_archive_ubuntu_com_ubuntu_-jammy.list
### Archive has template, updating /etc/apt/sources.list
add-apt-repository -n -y "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main restricted universe multiverse"
add-apt-repository -n -y "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-updates main restricted universe multiverse"
add-apt-repository -n -y "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-backports main restricted universe multiverse"
add-apt-repository -n -y "deb http://security.ubuntu.com/ubuntu $(lsb_release -sc)-security main restricted universe multiverse"
# All commented deb-src repo stay in sources.list.d and all deb repo will be in sources.list
apt update
答案1
不行。查看 Ubuntu wiki,没有命令行选项可以更改它的位置。不过你仍然可以这样做
echo “deb http://archive.ubuntu.com/ubuntu/jammy main restricted” >> /etc/apt/sources.list
这会将以下行添加到 /etc/apt/sources.list