更换Ubuntu源的简单脚本
Ubuntu系统自带的源都是国外的网址,国内用户在使用的时候网速比较慢。一般建议更换成国内的源
直接上脚本代码
#!/bin/sh
echo "*********************************"
echo "当前系统版本:"
lsb_release -a
echo "*********************************"
sudo echo "选择当前安装系统的版本:"
echo " Ubuntu 14.04 请输入 1"
echo " Ubuntu 16.04 请输入 2"
echo " Ubuntu 18.04 请输入 3"
echo "*********************************"
read SystemIndex
if [ -z $SystemIndex ];then
echo "输入格式错误"
exit
else
index=`echo "$SystemIndex*1" | bc `
if [ $index -eq 1 ];then
System=14.04
elif [ $index -eq 2 ];then
System=16.04
elif [ $index -eq 3 ];then
System=18.04
fi
fi
echo "*********************************"
echo "选择需要更新源:"
echo " 阿里源请输入 1"
echo " 清华源请输入 2"
echo " 网易源请输入 3"
echo "*********************************"
read SourceIndex
if [ -z $SystemIndex ];then
echo "输入格式错误"
exit
else
index=`echo "$SourceIndex*1" | bc `
if [ $index -eq 1 ];then
echo 1111
Source=ali
elif [ $index -eq 2 ];then
echo 222
Source=qinghua
elif [ $index -eq 3 ];then
Source=163
fi
fi
echo $Source
filename="source_${Source}_ubuntu${System}.list"
echo "开始下载安装git..."
sudo apt-get install git
sudo apt-get -f install
sudo apt-get install git
echo "安装完成"
echo "开始下载库文件..."
git clone https://github.com/kaikai136/Ubuntu-China-Source.git
cd Ubuntu-China-Source
ls
echo "备份原链接..."
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list
echo "设置链接..."
sudo cp $filename /etc/apt/sources.list
echo "更新源..."
sudo apt-get update
echo "修复软件..."
sudo apt-get -f install
echo "更新软件..."
sudo apt-get upgrade
echo "清理文件..."
cd ..
sudo rm -rf Ubuntu-China-Source
echo "国内源清理完毕"
rm -rf $(basename $0)
创建脚本添加权限执行即可
【树莓派】为Ubuntu Mate for ARM 更换中国软件源
更换步骤
以root身份打开 /etc/apt/sources.list ,至于用什么打开随意
1. 将 http://ports.ubuntu.com/ 全部替换为 http://mirrors.ustc.edu.cn/ubuntu-ports/ ,这是中科大的
2. 执行 sudo apt-get update 和 sudo apt-get upgrade 测试
参考博客https://blog.csdn.net/wr132/article/details/56700479
参考博客https://blog.csdn.net/qq_35451572/article/details/79516563