系统相关
首页 > 系统相关> > Linux 发行版添加软件源

Linux 发行版添加软件源

作者:互联网

 简介: Linux系统的软件包通常存放在软件源(Repository)中,添加软件源之后,您可使用Linux系统提供的包管理工具查找、安装或更新软件源中包含的软件。本文以阿里云软件源为例,分别介绍在不同Linux发行版本上添加软件源的操作步骤。

vcg_VCG21408988869_RF.jpg

一、背景信息

阿里云软件源对阿里云用户和非阿里云用户均免费开放。您可前往阿里巴巴开源镜像站获取相应Linux发行版本的软件源。

二、在CentOS上添加软件源

本节示例步骤使用的操作系统为CentOS 7。实际操作中,请以您的系统版本为准。

1.连接Linux实例。详情请参见连接方式介绍
2.运行以下命令备份原软件源。

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

3.运行以下任一命令添加CentOS 7软件源。

sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

说明

4.运行以下命令生成本地缓存,加快搜索、安装软件的速度。

sudo yum clean all && sudo yum makecache

5.运行sudo yum repolist查看软件源是否添加成功。CentOS 7系统添加阿里云软件源后,如下图所示。

5.png

三、在Ubuntu上添加软件源

本节示例步骤使用的操作系统为Ubuntu 18.04。实际操作中,请以您的系统版本为准。

1.连接Linux实例。详情请参见连接方式介绍
2.运行以下命令备份原软件源。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bakup

3.运行sudo vim /etc/apt/sources.list命令打开文件后,添加以下信息。添加步骤,请参见Vim教程

deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-backports main restricted universe multiverse

说明

4.运行sudo apt-get update更新软件包信息库。

四、在Debian上添加软件源

本节示例步骤使用的操作系统为Debian 8.9。实际操作中,请以您的系统版本为准。

1.连接Linux实例。详情请参见连接方式介绍
2.运行以下命令备份原软件源。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bakup

3.运行sudo vim /etc/apt/sources.list命令打开文件后,添加以下信息。添加步骤,请参见Vim教程

deb http://mirrors.cloud.aliyuncs.com/debian/ jessie main non-free contrib
deb http://mirrors.cloud.aliyuncs.com/debian/ jessie-proposed-updates main non-free contrib
deb-src http://mirrors.cloud.aliyuncs.com/debian/ jessie main non-free contrib
deb-src http://mirrors.cloud.aliyuncs.com/debian/ jessie-proposed-updates main non-free contrib

说明

4.运行sudo apt-get update更新软件包信息库。

五、在Fedora上添加软件源

1.运行以下命令备份原软件源。

# sudo mv /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.backup
# sudo mv /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.backup

2.运行以下任一命令添加阿里云fedora软件源。

sudo wget -O /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo
sudo curl -o /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo

说明 若您需要添加非阿里云fedora软件源,请将命令中的http://mirrors.aliyun.com/repo/fedora.repo替换为该软件源URL。

3.运行以下任一命令添加阿里云fedora-updates软件源。

sudo wget -O /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo
sudo curl -o /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo

说明 若您需要添加非阿里云fedora-updates软件源,请将命令中的http://mirrors.aliyun.com/repo/fedora-updates.repo替换为该软件源URL。

4.运行以下命令生成本地缓存。

sudo yum clean all && sudo yum makecache

 本文转自:Linux 发行版添加软件源-阿里云开发者社区

标签:http,mirrors,repo,添加,发行版,Linux,软件,com
来源: https://blog.csdn.net/a_small_cherry/article/details/123079512