自学内容网 自学内容网

Linux_CentOS学习笔记

YUM源

yum命令

  1. 语法
    yum [options] COMMAND
    
  2. command 列表
    命令功能说明
    check检查 RPM 数据库问题
    check-update检查是否有可用的软件包更新
    clean删除缓存数据
    deplist列出软件包的依赖关系
    distribution-synchronization已同步软件包到最新可用版本
    downgrade降级软件包
    erase从系统中移除一个或多个软件包
    groups显示或使用、组信息
    help显示用法提示
    history显示或使用事务历史
    info显示关于软件包或组的详细信息
    install向系统中安装一个或多个软件包
    list列出一个或一组软件包
    load-transaction从文件名中加载一个已存事务
    makecache创建元数据缓存
    provides查找提供指定内容的软件包
    reinstall覆盖安装软件包
    repo-pkgs将一个源当作一个软件包组,这样我们就可以一次性安装/移除全部软件包。
    repolist显示已配置的源
    search在软件包详细信息中搜索指定字符串
    shell运行交互式的 yum shell
    swapSimple way to swap packages, instead of using shell
    update更新系统中的一个或多个软件包
    upgrade更新软件包同时考虑软件包取代关系
    version显示机器和/或可用的源版本
  3. options 列表
    选项说明
    -h, --help显示此帮助消息并退出
    -t, --tolerant忽略错误
    -C, --cacheonly完全从系统缓存运行,不升级缓存
    -c [config file], --config=[config file]配置文件路径
    -R [minutes], --randomwait=[minutes]命令最长等待时间
    -d [debug level], --debuglevel=[debug level]调试输出级别
    –showduplicates在 list/search 命令下,显示源里重复的条目
    -e [error level], --errorlevel=[error level]错误输出级别
    –rpmverbosity=[debug level name]RPM 调试输出级别
    -q, --quiet静默执行
    -v, --verbose详尽的操作过程
    -y, --assumeyes回答全部问题为是
    –assumeno回答全部问题为否
    –version显示 Yum 版本然后退出
    –installroot=[path]设置安装根目录
    –enablerepo=[repo]启用一个或多个软件源(支持通配符)
    –disablerepo=[repo]禁用一个或多个软件源(支持通配符)
    -x [package], --exclude=[package]采用全名或通配符排除软件包
    –disableexcludes=[repo]禁止从主配置,从源或者从任何位置排除
    –disableincludes=[repo]disable includepkgs for a repo or for everything
    –obsoletes更新时处理软件包取代关系
    –noplugins禁用 Yum 插件
    –nogpgcheck禁用 GPG 签名检查
    –disableplugin=[plugin]禁用指定名称的插件
    –enableplugin=[plugin]启用指定名称的插件
    –skip-broken忽略存在依赖关系问题的软件包
    –color=COLOR配置是否使用颜色
    –releasever=RELEASEVER在 yum 配置和 repo 文件里设置 $releasever 的值
    –downloadonly仅下载而不更新
    –downloaddir=DLDIR指定一个其他文件夹用于保存软件包
    –setopt=SETOPTS设置任意配置和源选项

搭建并配置Yum软件仓库的大致步骤

  1. 搭建并配置Yum软件仓库的大致步骤
    1. 进入到/etc/yum.repos.d/目录中(因为该目录存放着Yum软件仓库的配置文件)。
    2. 使用Vim编辑器创建一个名为rhel7.repo的新配置文件(文件名称可随意,但后缀必须为.repo),逐项写入下面加粗的配置参数并保存退出(不要写后面的中文注释)。
      • [rhel-media] :Yum软件仓库唯一标识符,避免与其他仓库冲突。
      • name=linuxprobe:Yum软件仓库的名称描述,易于识别仓库用处。
      • baseurl=file:///media/cdrom:提供的方式包括FTP(ftp://…)、HTTP(http://…)、本地(file:///…)。
      • enabled=1:设置此源是否可用;1为可用,0为禁用。
      • gpgcheck=1:设置此源是否校验文件;1为校验,0为不校验。
      • gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release:若上面参数开启校验,那么请指定公钥文件地址。
    3. 按配置参数的路径挂载光盘,并把光盘挂载信息写入到/etc/fstab文件中。
    4. 使用“yum install httpd -y”命令检查Yum软件仓库是否已经可用。

创建光盘Yum源实例

Centos7实例
  1. 编辑光盘Yum源文件
  2. 挂载ISO文件
  3. 命令
    cat > /etc/yum.repos.d/rhel7_cdrom.repo << EOF
    ##文件内容
    [rhel7_cdrom]
    name=rhel7_cdrom
    baseurl=file:///media/cdrom/
    gpgcheck=0
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    EOF
    #挂载光驱
    mkdir /media/cdrom
    mount /dev/sr0 /media/cdrom
    yum clean all
    yum makecache
    
Centos8实例
  1. 编辑光盘Yum源文件
  2. 挂载ISO文件
  3. 命令
    cat > /etc/yum.repos.d/rhel8_cdrom.repo << EOF
    ##文件内容
    [rhel8_cdrom_BaseOS]
    name = rhel8_cdrom_BaseOS
    baseurl = file:///mnt/cdrom/BaseOS
    gpgcheck = 0
    enable = 1
    
    [rhel8_cdrom_AppStream]
    name = rhel8_cdrom_AppStream
    baseurl = file:///mnt/cdrom/AppStream
    gpgcheck = 0
    enable = 1
    EOF
    #挂载光驱
    mkdir /media/cdrom
    mount /dev/sr0 /media/cdrom
    yum clean all
    yum makecache
    

仅从光盘YUM源安装软件

  1. 参考: 创建光盘Yum源实例
  2. 清除缓存和重新缓存都是必须的
  3. –enablerepo可以使用多次,以使用多个源
  4. 从光盘Yum源安装,以光盘yum源为rhel7_cdrom为例
    yum --disablerepo=\* --enablerepo=rhel7_cdrom clean all#清除缓存
    yum --disablerepo=\* --enablerepo=rhel7_cdrom makecache#缓存本地yum源包信息
    yum --disablerepo=\* --enablerepo=rhel7_cdrom install  tigervnc#使用镜像源安装软件
    

利用priorities插件安装多个yum源

  1. 安装priorities插件
    yum -y install yum-priorities
    
  2. 安装rpmforge软件源
    sudo yum localinstall -y --nogpgcheck sudo yum localinstall -y --nogpgcheck http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el7/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
    
  3. 安装RPM Fusion软件源
    RPM Fusion同时提供了一些自由和非自由的软件,同样的它也需要先启用EPEL
    sudo yum localinstall -y --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm 
    sudo yum localinstall -y --nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
    
  4. 安装ELRepo软件源
    ELRepo提供了一些硬件驱动相关的包
    sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
    sudo rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
    
  5. 安装NUX-dextop 软件源
    NUX-dextop提供了一些桌面和多媒体软件包,它也需要先启用EPEL仓库
    sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
    
  6. 设置/etc/yum.repos.d/ 目录下的.repo相关文件(如CentOS-Base.repo),在这些文件[base]段中插入顺序指令:priority=N (N为1到99的正整数,数值越小越优先)
    vi /etc/yum.repos.d/CentOS-Base.repo 
    priority=2
    vi /etc/yum.repos.d/CentOS-aliyun.repo 
    priority=5
    vi /etc/yum.repos.d/epel.repo
    priority=10
    vi /etc/yum.repos.d/rpmforge.repo
    priority=15
    vi /etc/yum.repos.d/nux-dextop.repo
    priority=20
    vi /etc/yum.repos.d/rpmfusion-free-updates.repo
    priority=25
    vi /etc/yum.repos.d/rpmfusion-free-updates-testing.repo
    priority=30
    vi /etc/yum.repos.d/rpmfusion-nonfree-updates.repo
    priority=35
    vi /etc/yum.repos.d/rpmfusion-nonfree-updates-testing.repo
    priority=40
    sudo yum clean all && yum makecache && yum update
    

第三方软件源

清华大学软件源

CentOS7 清华大学软件源
  1. 代码
    # 备份文件
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    mv /etc/yum.repos.d/CentOS-fasttrack.repo /etc/yum.repos.d/CentOS-fasttrack.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    mv /etc/yum.repos.d/CentOS-x86_64-kernel.repo /etc/yum.repos.d/CentOS-x86_64-kernel.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    # 生成CentOS-Base.repo
    cat > /etc/yum.repos.d/CentOS-Base.repo << 'EOF'
    [base]
    name=CentOS-$releasever - Base
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    EOF
    # 生成/etc/yum.repos.d/CentOS-fasttrack.repo
    cat > /etc/yum.repos.d/CentOS-fasttrack.repo << 'EOF'
    [fasttrack]
    name=CentOS-7 - fasttrack
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=fasttrack&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/fasttrack/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    EOF
    # 生成/etc/yum.repos.d/CentOS-x86_64-kernel.repo
    cat > /etc/yum.repos.d/CentOS-x86_64-kernel.repo << 'EOF'
    [centos-kernel]
    name=CentOS LTS Kernels for $basearch
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=kernel&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/altarch/7/kernel/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    [centos-kernel-experimental]
    name=CentOS Experimental Kernels for $basearch
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=experimental&infra=$infra
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/altarch/7/experimental/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    EOF
    # 生成epel源
    cat > /etc/yum.repos.d/epel.repo << 'EOF'
    [epel]
    name=Extra Packages for Enterprise Linux 7 - $basearch
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=1
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Source
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=1
    EOF
    # 重新生成缓存
    yum clean all
    yum makecache
    

阿里云软件源

CentOS7源信息
源ID源名源文件名大小
base/7/x86_64CentOS-7 - Base - mirrors.aliyun.com/etc/yum.repos.d/CentOS-Base.repo8.9G
epel/x86_64Extra Packages for Enterprise Linux 7 - x86_64/etc/yum.repos.d/epel.repo16G
extras/7/x86_64CentOS-7 - Extras - mirrors.aliyun.com/etc/yum.repos.d/CentOS-Base.repo950M
updates/7/x86_64CentOS-7 - Updates - mirrors.aliyun.com/etc/yum.repos.d/CentOS-Base.repo22G
CentOS7配置阿里软件源
  1. 常用软件源安装
    1. 备份系统软件源
    2. 下载阿里源
    3. 下载阿里EPEL源
    4. 重新生成缓存
      mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup.$(date "+%Y-%m-%d_%H:%M")
      mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup.$(date "+%Y-%m-%d_%H:%M")
      curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
      curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
      yum clean all
      yum makecache
      

中国科技大学 USTC软件源

CentOS7 USTC软件源
  1. 代码
    # 备份文件
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    # 新建文件
    cat > /etc/yum.repos.d/CentOS-Base.repo << 'EOF'
    [base]
    name=CentOS-$releasever - Base
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    EOF
    # 生成epel文件
    cat > /etc/yum.repos.d/epel.repo << 'EOF'
    [epel]
    name=Extra Packages for Enterprise Linux 7 - $basearch
    baseurl=https://mirrors.ustc.edu.cn/epel/7/$basearch
    #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
    baseurl=https://mirrors.ustc.edu.cn/epel/7/$basearch/debug
    #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=1
    [epel-source]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Source
    baseurl=https://mirrors.ustc.edu.cn/epel/7/SRPMS
    #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=1
    EOF
    # 重建缓存
    yum clean all
    yum makecache
    
CentOS 8 Stream USTC软件源
  1. 代码
    # 备份文件
    mv /etc/yum.repos.d/CentOS-Stream-BaseOS.repo /etc/yum.repos.d/CentOS-Stream-BaseOS.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    mv /etc/yum.repos.d/CentOS-Stream-Extras.repo /etc/yum.repos.d/CentOS-Stream-Extras.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    mv /etc/yum.repos.d/CentOS-Stream-AppStream.repo /etc/yum.repos.d/CentOS-Stream-AppStream.repo.backup.$(date "+%Y-%m-%d_%H:%M")
    # 生成/etc/yum.repos.d/CentOS-Stream-BaseOS.repo文件
    cat > /etc/yum.repos.d/CentOS-Stream-BaseOS.repo << 'EOF'
    [baseos]
    name=CentOS Stream $releasever - BaseOS
    #mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=BaseOS&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$stream/BaseOS/$basearch/os/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    EOF
    # 生成/etc/yum.repos.d/CentOS-Stream-Extras.repo文件
    cat > /etc/yum.repos.d/CentOS-Stream-Extras.repo << 'EOF'
    [extras]
    name=CentOS Stream $releasever - Extras
    #mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=extras&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$stream/extras/$basearch/os/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    EOF
    # 生成/etc/yum.repos.d/CentOS-Stream-AppStream.repo文件
    cat > /etc/yum.repos.d/CentOS-Stream-AppStream.repo << 'EOF'
    [appstream]
    name=CentOS Stream $releasever - AppStream
    #mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=AppStream&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$stream/AppStream/$basearch/os/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    EOF
    # 生成/etc/yum.repos.d/CentOS-Stream-PowerTools.repo文件,默认禁用
    cat > /etc/yum.repos.d/CentOS-Stream-PowerTools.repo << 'EOF'
    [powertools]
    name=CentOS Stream $releasever - PowerTools
    #mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=PowerTools&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$stream/PowerTools/$basearch/os/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    EOF
    # 重新生成缓存
    yum clean all
    yum makecache
    

系统安装

使用安装选项

  1. 方式1
    1. 进入光盘启动菜单界面
    2. 光标在安装系统选项上,按"TAB"键
    3. 前面有些代码,不用管,输入空格加选项,每个选项之间使用空格分隔,回车
  2. 方式2
    1. 进入光盘启动菜单界面
    2. 按"Esc"键
    3. 输入linux 选项,每个选项之间使用空格分隔,回车
  3. 选项
    选项|说明
    -|-|-
    text|文本界面安装
    graphical|图形界面安装(内存需大于1G)
    asknetword|提示用户配置网络功能
    dd|指定设备驱动程序位置(本地、光驱、网络)|
    ks|ks文件路径(本地、光驱、网络)|
    repo|安装树路径(本地、光驱、网络)|
    ip netmask gateway dns noipv6 device|配置网络参数|
    1. ks示例
      1. 网络位置
        ks={http|https|ftp}://ip/path/ks.cfg
        ks=nfs:ServerIP:/path/ks.cfg
        
    2. repo示例
      1. 网络位置
        repo={http|https|ftp}://ip/path
        repo=nfs:ServerIP:/path
        
    3. ip示例
      ip=192.168.1.2 netmask=255.255.255.0 gateway=192.168.1.1 dns=8.8.8.8 noipv6 device=eth0
      

软件安装

CentOS7安装Python3.8

  1. 系统版本:CentOS7.9_2009;Python版本:Python3.8.13
  2. 安装依赖包
    yum install -y wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
    
  3. 下载解压源码包;编译安装
    wget https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz
    tar zxvf Python-3.8.13.tgz
    cd Python-3.8.13
    ./configure prefix=/usr/local/python3
    make
    make install
    
  4. 添加软连接
    ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
    
  5. 添加环境变量
    echo 'export PATH="${PATH}:/usr/local/python3/bin"' >> /etc/profile
    source /etc/profile
    

常见问题

CentOS7 安装软件包时报错

  1. 报错信息:获取 GPG 密钥失败:[Errno 14] curl#37 - “Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7”
  2. 解决方法:
    sudo curl -Lo /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
    

CentOS6 软件源不可用

  1. CentOS 6已经随着2020年11月的结束进入了EOL(Reaches End of Life)。所以在2020年12月2日,CentOS官方停止了对CentOS 6的所有更新,并且下架了包括官方所有的CentOS6源,目前阿里、163、清华等CentOS6源已无法使用。
  2. 还要继续使用CentOS6的话,可以使用vault.centos.org作为更新源.
    1. CentOS官方
    2. 阿里云镜像
  3. 解决步骤
    1. 关闭fastestmirror
      vi /etc/yum/pluginconf.d/fastestmirror.conf
      #修改参数
      enable=0
      
    2. 将原来的源改名,养成良好的备份习惯
      mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak1
      
    3. 更换源
      1. 替换为官方Vault源
        curl -o /etc/yum.repos.d/CentOS-Base.repo https://static.lty.fun/%E5%85%B6%E4%BB%96%E8%B5%84%E6%BA%90/SourcesList/Centos-6-Vault-Official.repo
        
      2. 替换为阿里云Vault镜像
        curl -o /etc/yum.repos.d/CentOS-Base.repo https://static.lty.fun/%E5%85%B6%E4%BB%96%E8%B5%84%E6%BA%90/SourcesList/Centos-6-Vault-Aliyun.repo
        

原文地址:https://blog.csdn.net/liujinbao8000/article/details/137566906

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!