linux一鍵換源腳本,centos,debian,ubuntu通用腳本
國內(nèi)使用
bash <(curl -sSL https://linuxmirrors.cn/main.sh)
教育網(wǎng)
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --edu
github地址
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh)
gitee地址
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
海外使用
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --abroad
github地址
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh) --abroad
gitee地址
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) --abroad
命令選項
名稱 | 含義 | 選項值 |
---|---|---|
--abroad |
使用海外軟件源 | 無 |
--edu |
使用中國大陸教育網(wǎng)軟件源 | 無 |
--source |
指定軟件源地址(域名或IP) | 地址 |
--source-security |
指定 Debian 的 security 軟件源地址(域名或IP) | 地址 |
--source-vault |
指定 CentOS/AlmaLinux 的 vault 軟件源地址(域名或IP) | 地址 |
--branch |
指定軟件源分支(路徑) | 分支名 |
--branch-security |
指定 Debian 的 security 軟件源分支(路徑) | 分支名 |
--branch-vault |
指定 CentOS/AlmaLinux 的 vault 軟件源分支(路徑) | 分支名 |
--codename |
指定 Debian 系操作系統(tǒng)的版本名稱 | 版本名 |
--web-protocol |
指定 WEB 協(xié)議 | http 或 https |
--intranet |
優(yōu)先使用內(nèi)網(wǎng)地址 | true 或 false |
--install-epel |
安裝 EPEL 附加軟件包 | true 或 false |
--only-epel |
僅更換 EPEL 軟件源模式 | 無 |
--close-firewall |
關(guān)閉防火墻 | true 或 false |
--backup |
備份原有軟件源 | true 或 false |
--ignore-backup-tips |
忽略覆蓋備份提示(即不覆蓋備份) | 無 |
--updata-software |
更新軟件包 | true 或 false |
--clean-cache |
清理下載緩存 | true 或 false |
--print-diff |
打印源文件修改前后差異 | true 或 false |
--help |
查看幫助菜單 | 無 |
軟件源格式
<指定WEB協(xié)議>://<軟件源地址>/<軟件源分支>
示例
指定軟件源地址
若不想通過交互選擇默認提供的軟件源,你可以使用該命令選項指定軟件源地址
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--source mirror.example.com
指定軟件源分支
使用場景:目標(biāo)軟件源有對應(yīng)系統(tǒng)鏡像但是不符合本腳本關(guān)于軟件源分支設(shè)置的默認規(guī)則
本腳本為了適配大的環(huán)境不會針對某一鏡像站獨特的鏡像分支名稱而單獨定制,最開始是為了更換國內(nèi)軟件源而設(shè)計適配的,默認使用的分支名稱如下
Ubuntu | ubuntu/ubuntu-ports |
Kali Linux | kali |
Red Hat Enterprise Linux | centos/rocky |
Fedora | fedora |
CentOS | centos/centos-stream/centos-altarch/centos-vault |
Rocky Linux | rocky |
AlmaLinux | almalinux/almalinux-vault |
OpenCloudOS | opencloudos |
openEuler | openeuler |
openSUSE | opensuse |
Arch Linux | archlinux/archlinuxarm |
使用阿里云的 Rocky Linux 軟件源
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--source mirrors.aliyun.com \
--branch rockylinux
阿里云鏡像站的 Rocky Linux 鏡像分支名稱為 rockylinux
,不符合默認規(guī)則,但是可以通過命令選項繞過腳本默認規(guī)則來實現(xiàn)。
什么是默認規(guī)則?參考這幾個例子: Debian GNU/Linux => debian
、Rocky Linux => rocky
、AlmaLinux => almalinux
單獨更換 EPEL 源
有些時候你會發(fā)現(xiàn)想使用的鏡像站沒有 epel 鏡像倉庫,那么你可以在第一次運行腳本時不安裝或不更換 epel 源然后再單獨執(zhí)行下面的命令
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --only-epel
自定義 Debian Security 源
如果你想盡可能提高服務(wù)器的安全性則建議使用官方源,因為鏡像同步存在延遲
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--source-security security.debian.org \
--branch-security debian-security
指定 Debian 系操作系統(tǒng)的版本名稱#
你可以自定義該版本名稱,大多數(shù)情況下用于升級系統(tǒng)版本,請看下面的例子
升級 Debian 至最新 12 版本 Bookworm
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--codename bookworm
更換軟件源后還需要執(zhí)行系統(tǒng)更新命令才能實現(xiàn)更新操作,并且建議在更新完成并重啟系統(tǒng)后重新執(zhí)行本換源腳本,因為僅更換軟件源配置中的系統(tǒng)版本名稱可能會在后期使用時產(chǎn)生一些兼容性問題
無人值守
不通過交互完成換源操作,需要使用大量命令選項來實現(xiàn),建議熟悉后再使用
參考命令
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--source mirror.example.com \
--web-protocol http \
--intranet false \
--install-epel true \
--close-firewall true \
--backup true \
--updata-software false \
--clean-cache false \
--ignore-backup-tips
記錄自:https://linuxmirrors.cn/use/
真假及是否存在后門請自行辨別