Linux国内镜像源详细修改教程

Linux系统下,CentOS和Ubuntu的镜像源修改教程因版本不同而有所差异。以下是针对CentOS 7至9以及Ubuntu 16.04至22.04的国内外镜像源修改教程:

CentOS

CentOS 7
  1. 备份原有的YUM源文件

    sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  2. 选择并下载国内镜像源

    • 阿里云源:

      sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    • 网易源:

      sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
  3. 清理原有缓存并生成新缓存

    sudo yum clean all
    sudo yum makecache
  4. 更新系统

    sudo yum update -y
CentOS 8
  1. 备份原有的YUM源文件

    sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  2. 选择并下载国内镜像源

    • 阿里云源:

      sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
  3. 清理原有缓存并生成新缓存

    sudo yum clean all
    sudo yum makecache
  4. 更新系统

    sudo yum update -y
CentOS 9
  1. 备份原有的YUM配置文件

    sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base-backup.repo
  2. 选择并添加国内镜像源

    • 阿里云源:

      打开编辑器(如vi或nano):

      sudo vi /etc/yum.repos.d/CentOS-Base.repo

      在文件末尾追加阿里云的CentOS镜像源配置:

      [aliyun]
      name=阿里云CentOS mirror
      baseurl=https://mirrors.aliyun.com/repo/CentOS-$releasever/
      gpgcheck=0
      enabled=1

      注意:$releasever需要替换为你的CentOS 9版本(例如"stream")。

  3. 清理原有缓存并生成新缓存

    sudo yum clean all
    sudo yum makecache fast
  4. 更新系统

    sudo yum update -y

Ubuntu

Ubuntu 16.04
  1. 备份源文件

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 修改源文件

    使用文本编辑器(如gedit、vi、nano等)打开/etc/apt/sources.list文件,将原有的所有源注释掉,并添加国内源。例如,添加阿里云源:

    deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
  3. 更新源文件

    sudo apt update
Ubuntu 18.04
  1. 备份源文件

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 修改源文件

    使用文本编辑器打开/etc/apt/sources.list文件,将原有的所有源注释掉,并添加国内源。例如,添加阿里云源:

    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  3. 更新源文件

    sudo apt update
Ubuntu 20.04 和 22.04

对于Ubuntu 20.04和22.04,修改源文件的步骤与18.04类似。只需将源文件中的版本号(如bionic)替换为对应版本的代号(如focal对应20.04,jammy对应22.04),并添加相应的国内源地址即可。

以下是Ubuntu 20.04和22.04国内镜像源修改的详细教程:

Ubuntu 20.04 国内镜像源修改教程

  1. 备份原有的镜像源文件

    打开终端(Ctrl+Alt+T),输入以下命令备份原有的Ubuntu 20.04镜像源文件:

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 编辑镜像源文件

    使用文本编辑器(如nano或vim)打开/etc/apt/sources.list文件,并将原有的镜像源地址替换为国内镜像源地址。例如,使用nano编辑器:

    sudo nano /etc/apt/sources.list

    将文件中的内容替换为以下格式(以清华大学镜像源为例):

    # 默认注释掉的源,如果需要启用,请取消注释并将下面的清华大学源地址替换为官方源地址
    # deb http://archive.ubuntu.com/ubuntu/ focal main restricted
    # deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
    # deb http://archive.ubuntu.com/ubuntu/ focal universe
    # deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
    # deb http://archive.ubuntu.com/ubuntu/ focal multiverse
    # deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
    # deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
    # deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
    # deb http://security.ubuntu.com/ubuntu/ focal-security universe
    # deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
    
    # 替换为清华大学镜像源
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

    保存并退出编辑器。

  3. 更新软件包索引

    输入以下命令更新软件包索引,以确保系统能够识别新的镜像源:

    sudo apt update
  4. 验证新配置的镜像源

    可以通过尝试安装一个软件包来验证新配置的镜像源是否生效。例如,安装curl:

    sudo apt install curl

    如果安装过程顺利且速度较快,说明新配置的镜像源已经生效。

Ubuntu 22.04 国内镜像源修改教程

  1. 安装software-properties-common

    打开终端,输入以下命令安装software-properties-common

    sudo apt update && sudo apt install software-properties-common
  2. 添加国内镜像源

    以添加清华大学源为例,输入以下命令:

    sudo add-apt-repository "deb [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse"
    sudo add-apt-repository "deb-src [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse"

    如果需要添加阿里云源,可以使用以下命令(注意替换为正确的仓库地址):

    sudo add-apt-repository ppa:chenyunkun/aliyun-ubuntu-repo
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E56151AF
    # 然后编辑 /etc/apt/sources.list 文件,将原有的源替换为阿里云源

    或者直接编辑/etc/apt/sources.list文件,将原有的源替换为阿里云源,例如:

    deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
  3. 更新软件包索引

    输入以下命令更新软件包索引:

    sudo apt update
  4. 验证新配置的镜像源

    同样可以通过尝试安装一个软件包来验证新配置的镜像源是否生效。

通过以上步骤,您可以成功在Ubuntu 20.04和22.04中配置国内镜像源,从而提升软件包下载速度。

注意事项

  1. 在修改镜像源之前,请确保网络连接正常,并能够访问所选的国内镜像源。
  2. 修改镜像源可能会影响软件包的可用性和安全性,因此请确保选择可靠的国内源。
  3. 定期检查和更新源列表文件,以确保系统能够获取到最新的软件包和更新。

通过以上步骤,您可以成功修改CentOS 7至9以及Ubuntu 16.04至22.04的国内外镜像源。

原文链接:Linux国内镜像源详细修改教程 - Java程序员_编程开发学习笔记_网站安全运维教程_渗透技术教程

### Kali Linux 安装指南 #### 选择合适的版本 Kali Linux 提供多种版本,包括标准版、轻量级桌面环境版和其他特定用途的版本。对于大多数用户来说,推荐下载带有图形界面的标准版 ISO 文件[^1]。 #### 下载官方镜像文件 为了确保安全性和稳定性,建议从官方网站获取最新稳定版的 Kali Linux 镜像文件。访问[Kali官网](https://www.kali.org/)并找到对应的下载链接来获得最新的ISO映像文件[^2]。 #### 使用国内镜像源加速下载 由于网络原因,直接从国外服务器下载可能较慢。可以考虑使用国内的一些知名Linux社区提供的镜像站点,比如清华大学开源软件镜像站、阿里云等。这些网站通常也会同步维护着Kali Linux 的镜像资源,能够有效提高下载速度。 #### 创建启动介质 创建可引导U盘或光盘用于安装操作系统。可以借助工具如Rufus (Windows平台) 或 Etcher (跨平台),按照提示操作完成USB驱动器写入工作。 #### 开始安装过程 重启计算机进入BIOS设置,调整启动顺序使机器优先读取外部存储设备中的数据;接着跟随屏幕上的向导逐步配置分区方案、设定管理员账户信息等内容直至结束整个流程。 ```bash # 修改root用户密码示例命令 sudo passwd root # 这里需要先输入当前用户的密码再设置新的root密码 ``` #### 设置远程登录权限 如果打算通过SSH客户端(例如Xshell)管理远端主机,则需提前开启相应的服务支持: 编辑`/etc/ssh/sshd_config`文件取消注释或添加如下行: ```bash PermitRootLogin yes PasswordAuthentication yes ``` 保存更改后执行`service ssh restart`重启服务生效。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值