如何恢复sources.list文件?

我不小心删除了我的/etc/apt/sources.list文件。 它是由Canonical托管的,所以我可以将它重新添加到系统中吗? 这有点紧急,所以我希望有人可以快速回答。

您可以启动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. ## NB 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 ## NB 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. 根据您的选择选择服务器

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

如果您不在Ubuntu服务器上,即没有GUI。 您可以按照以下步骤操作: –

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

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

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

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