1、简介
1.1 介绍
????很多时候,为了方便 操作,条件允许的情况下,直接 联网 进行安装,但是 系统 所配置的 apt源 配置的 url 地址 并非 国内的,获取资源很慢,所以 需要 配置成 国内的 源,本人 喜欢 163网易源,根据个人喜好 自行选择
????
1.2 操作系统
## 本文操作系统 Ubuntu 16.04 amd64
## 发行版本号 xenial
# lsb_release -a
????
2、apt 源
2.1 源备份
## 备份原有的源配置文件
# cd /etc/apt
# mv -v source.list{,.bak}
????
2.3 设置 163源
## 设置本地源,baseurl中file路径对应挂载的路径
# cat /etc/apt/source.list
deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
????
3、apt 源操作
3.1 清除原有记录
# apt-get clean all
????
3.2 更新apt源
# apt-get update
????
3.3 获取安装列表
# apt-cache dump | grep Package
????
4、自动化配置脚本
????本人 测试环境 需要 不断的恢复纯净 环境 进行 相关 测试操作,所以 每次 都手动 配置 实在 难受,简单的写了一个 配置脚本,可优化 之处 还望 留言 提示,嘿嘿!
????
4.1 解压
# tar -zxvf set_apt_source.tar.gz -C .
????
4.2 安装
## 安装完成之后,即可 直接 联网 安装 所需的 软件包
# cd set_apt_source/
# ./modify_apt_source.sh
????
4.3 代码
# cat modify_apt_source.sh
#!/bin/bash
# file name :
# date :
# description :
deb_1="deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse"
deb_2="deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse"
deb_3="deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse"
deb_4="deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse"
deb_5="deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse"
deb_src1="deb-src http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse"
deb_src2="deb-src http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse"
deb_src3="deb-src http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse"
deb_src4="deb-src http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse"
deb_src5="deb-src http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse"
DEB_SOURCE="${deb_1}\n${deb_2}\n${deb_3}\n${deb_4}\n${deb_5}\n${deb_src1}\n${deb_src2}\n${deb_src3}\n${deb_src4}\n${deb_src5}\n"
APT_FILE="/etc/apt/sources.list"
[ -f ${APT_FILE} ] && mv ${APT_FILE}{,.bak}
printf "${DEB_SOURCE}" >> ${APT_FILE} && apt-get update
????
原文地址:http://blog.51cto.com/11495268/2333692
时间: 2024-10-06 22:48:07