Centos 7 或 8配置国内yum源及epel源-1

官方教程

Yum工具详解

bash 复制代码
清理Yum缓存:
	[root@qfedu.com ~]# yum clean all

缓存软件包信息:    
    提高搜索/安装软件的速度
    [root@qfedu.com ~]# yum makecache
      
查询yum源信息:   
  [root@qfedu.com ~]# yum repolist     
        
查找软件:
	[root@qfedu.com ~]# yum search  mysql   
	此命令会搜索到系统已经安装和yum源里没有安装的软件信息,可以用他简单测试yum是否好用
 
查看软件依赖性关系:                 
  [root@qfedu.com ~]# yum  deplist  

查看文件属于哪个软件
  [root@qfedu.com ~]#  yum provides ld-linux.so.2      

查看系统已经安装好的软件和没有安装的软件:
	[root@qfedu.com ~]# yum list	

查看系统已经安装好的软件组和没有安装的软件组:
	[root@qfedu.com ~]# yum grouplist

查看软件组包含的具体软件:
  [root@qfedu.com ~]# yum  groupinfo    
    
安装软件组:
	[root@qfedu.com ~]# yum groupinstall  '软件组名称'   
	如果软件或者软件组名称内有空格,要给空格转义或者加引号

安装软件:
	[root@qfedu.com ~]# yum install 软件名称
	[root@qfedu.com ~]# yum install mysql mysql-server -y
	-y跳过确认提示直接安装

重装:
  [root@qfedu.com ~]# yum  reinstall    软件名        
    
卸载软件:
	[root@qfedu.com ~]# yum erase  mysql-server 
	[root@qfedu.com ~]# yum remove mysql-server 

Linux配置国内源的步骤

对于基于Debian的系统(如Ubuntu)
  1. 备份原始的源列表文件

    在进行任何更改之前,建议备份原始的源列表文件,以防止配置过程中出现问题。可以使用以下命令备份 /etc/apt/sources.list 文件:

    复制代码
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 修改源列表文件

    使用文本编辑器打开 /etc/apt/sources.list 文件,并添加国内源。例如,可以添加清华大学的源:

    复制代码
    sudo vim /etc/apt/sources.list

    然后添加以下内容(请根据您的Ubuntu版本调整版本号):

    复制代码
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

    其中 focal 是Ubuntu 20.04 LTS的版本代号,请根据您的实际版本进行替换。

  3. 更新软件包列表

    完成源列表的修改后,运行以下命令来更新软件包列表:

    复制代码
    sudo apt update
对于基于Red Hat的系统(如CentOS)
  1. 备份原始的源配置文件

    在进行任何更改之前,建议备份原始的源配置文件,以防止配置过程中出现问题。可以使用以下命令备份 /etc/yum.repos.d/ 目录下的所有文件:

    复制代码
    sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup-$(date "+%Y.%m.%d-%H.%M.%S")
  2. 修改源配置文件

    使用文本编辑器打开 /etc/yum.repos.d/CentOS-Base.repo 文件,并添加国内源。例如,可以添加阿里云的源:

    复制代码
    sudo vim /etc/yum.repos.d/CentOS-Base.repo

    然后添加以下内容(请根据您的CentOS版本调整版本号):

    复制代码
    [base]
    name=CentOS-$releasever - Base - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    [updates]
    name=CentOS-$releasever - Updates - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    其中 $releasever 会被替换为您的CentOS版本号,例如 78

  3. 清理和重新创建缓存

    完成源配置的修改后,运行以下命令来清理旧的缓存并重新创建缓存:

    复制代码
    sudo yum clean all
    sudo yum makecache

epel-release源

[root@localhost ~]``# yum install epel-release -y

[root@localhost ~]``# yum clean all

以上步骤是通用的配置方法,具体的源地址和配置细节可能会根据不同的Linux发行版和版本有所变化。在配置过程中,请确保使用最新的源地址,并根据您的系统环境进行适当的调整。

相关推荐
热爱生活的猴子2 分钟前
阿里云服务器正确配置 Docker 国内镜像的方法
服务器·阿里云·docker
物联网老王2 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
艾伦_耶格宇3 小时前
【ACP】阿里云云计算高级运维工程师--ACP
运维·阿里云·云计算
一位摩羯座DBA4 小时前
Redhat&Centos挂载镜像
linux·运维·centos
学习3人组4 小时前
CentOS配置网络
linux·网络·centos
weixin_307779135 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
漫步企鹅5 小时前
【蓝牙】Linux Qt4查看已经配对的蓝牙信息
linux·qt·蓝牙·配对
cui_win5 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
梦在深巷、5 小时前
MySQL/MariaDB数据库主从复制之基于二进制日志的方式
linux·数据库·mysql·mariadb
风清再凯5 小时前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible