我如何恢复 sources.list 文件?

我如何恢复 sources.list 文件?

我意外删除了我的/etc/apt/sources.list文件。它是否由 Canonical 托管在某个地方,以便我可以将其重新添加到系统中?这有点紧急,所以我希望有人能快速回答。

答案1

您可以启动 Live CD(虚拟机就足够了)并/etc/apt/sources.list从中复制。或者,准备好 Live CD 映像并按照以下说明操作:

  1. 安装 CD。如果您有文件.iso,请使用以下命令安装它:

    sudo mount -o loop ubuntu-11.04-desktop-amd64.iso /media/cdrom
    
  2. 从 CD 挂载文件系统文件:

    sudo mount -o loop /media/cdrom/casper/filesystem.squashfs /mnt
    
  3. 将 sources.list 文件复制过来:

    sudo cp {/mnt,}/etc/apt/sources.list
    
  4. 如果有必要,更改文件权限:

    sudo chmod 644 /etc/apt/sources.list
    

来自我的 Ubuntu 11.04 Live CD:

deb http://archive.ubuntu.com/ubuntu natty main restricted
deb-src http://archive.ubuntu.com/ubuntu natty main restricted

deb http://security.ubuntu.com/ubuntu natty-security main restricted
deb-src http://security.ubuntu.com/ubuntu natty-security main restricted

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

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
# deb http://archive.ubuntu.com/ubuntu natty universe
# deb-src http://archive.ubuntu.com/ubuntu natty universe
# deb http://archive.ubuntu.com/ubuntu natty-updates universe
# deb-src http://archive.ubuntu.com/ubuntu natty-updates universe
# deb http://security.ubuntu.com/ubuntu natty-security universe
# deb-src http://security.ubuntu.com/ubuntu natty-security universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
# deb http://archive.ubuntu.com/ubuntu natty multiverse
# deb-src http://archive.ubuntu.com/ubuntu natty multiverse
# deb http://archive.ubuntu.com/ubuntu natty-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu natty-updates multiverse
# deb http://security.ubuntu.com/ubuntu natty-security multiverse
# deb-src http://security.ubuntu.com/ubuntu natty-security multiverse

为了获得最佳的下载速度,您需要重新选择您附近的镜像:

  1. 打开 Ubuntu 软件中心
  2. 打开编辑->软件源...
  3. 单击旁边的选择框下载自:
  4. 选择您喜欢的服务器

你可能还想启用一些存储库,例如社区维护的开源软件(宇宙)受版权和法律问题限制的软件(多元宇宙)

答案2

如果你没有使用 Ubuntu 服务器,即没有 GUI。你可以按照以下步骤操作:-

  1. 软件和更新
  2. 选择Ubuntu 软件
  3. 选择您想要的来源。
  4. 点击关闭。它会要求您重新加载并更新缓存。
  5. 点击重新加载

等待并放松;它将自动为您创建 sources.list 文件。

答案3

对于 16.04

以下是您可以使用的列表/etc/apt/sources.list

只需运行以下命令:

sudo nano /etc/apt/sources.list

然后将以下内容复制并粘贴到文件中(这些应该是文件中唯一的行!):

deb http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse

deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner

CTRL+o然后按ENTER保存文件。按CTRL+x退出nano

答案4

我使用了漂亮的 sources.list 生成器http://repogen.simplylinux.ch/- 这可能并不适合所有人,但如果您知道要选择哪些选项,它可以快速而简单地发挥作用。

相关内容