![在 Debian 8 中切换存储库](https://linux22.com/image/102593/%E5%9C%A8%20Debian%208%20%E4%B8%AD%E5%88%87%E6%8D%A2%E5%AD%98%E5%82%A8%E5%BA%93.png)
寻找一种解决方案,将存储库从 CD 切换到镜像存储库,而无需访问/etc/apt/sources.list
Internet 镜像列表并将内容更改为 Internet 镜像列表。
恕我直言,仅针对 CD 存储库中未包含的一两个应用程序执行此操作绝对是浪费时间...
类似于yum
,例如
yum install --enablerepo=repository_name_here package_name
Debian 中有类似的东西吗?
答案1
Debian Jessie 有八 (8) 张 CD:,除非您碰巧拥有全部,否则很可能不止一两个应用程序在 CD 上找不到。此外,使用网络镜像可以更轻松地访问点版本,并且无论如何您都应该从网络存档中获取安全更新。
另外,如果安装时使用网络镜像,则无需编辑sources.list
即可添加。
但是,另请参阅:如何在 Debian 中从 shell 添加存储库?
答案2
您可以使用sed
命令禁用/启用您的 urlsources.list
禁用全部urls
:
sed -i '/debian.org/s/^/#/g' /etc/apt/sources.list
要启用全部urls
:
sed -i '/debian.org/s/^#//g' /etc/apt/sources.list
用你的改变debian.org
字符串。
答案3
这个脚本应该可以,它将支持您当前的存储库文件并创建一个别名,因此您可以通过命令启用禁用存储库:
要启用 cd 存储库:
cd-repo-enable
要启用网络代表:
net-repo-enable
脚本:
# backing up
if [ ! -f "/etc/apt/_back.sources.list_back" ]; then
cp /etc/apt/sources.list /etc/apt/_back.sources.list_back
fi &&
# creating repo file for net
cat <<"EOF" >> /etc/apt/sources.list_net
deb http://httpredir.debian.org/debian jessie main contrib
deb-src http://httpredir.debian.org/debian jessie main contrib
deb http://httpredir.debian.org/debian jessie-updates main contrib
deb-src http://httpredir.debian.org/debian jessie-updates main contrib
deb http://ftp.debian.org/debian/ jessie-updates main contrib
deb-src http://ftp.debian.org/debian/ jessie-updates main contrib
EOF
# creating cd repo file
cp /etc/apt/sources.list cp /etc/apt/sources.list_cd
# enable cd-repo
cat <<"EOF">> /usr/local/bin/cd-repo-enable.sh
rm -fr /etc/apt/sources.list
cp /etc/apt/sources.list_cd /etc/apt/sources.list
apt-get update
EOF
chmod +x /usr/local/bin/cd-repo-enable.sh
# enabling net repo
cat <<"EOF">> /usr/local/bin/net-repo-enable.sh
rm -fr /etc/apt/sources.list
cp /etc/apt/sources.list_net /etc/apt/sources.list
apt-get update
EOF
chmod +x /usr/local/bin/net-repo-enable.sh
# Removing old alias "net-repo-enable" if detected
sed -i 's/alias net-repo-enable=.*//g' /root/.bashrc
cat <<"EOF">> /root/.bashrc
alias net-repo-enable='/usr/local/bin/net-repo-enable.sh'
EOF
# Removing old alias "cd-repo-enable" if detected
sed -i 's/alias cd-repo-enable=.*//g' /root/.bashrc
cat <<"EOF">>/root/.bashrc
alias cd-repo-enable='/usr/local/bin/cd-repo-enable.sh'
EOF
# Applying changes
source ~/.bashrc
echo "Installation sucess"