一、配置国内镜像源加速下载
Rocky Linux 默认使用国外软件源,国内用户可通过替换为阿里云镜像提升下载速度:
备份原配置文件:
cp -r /etc/yum.repos.d /etc/yum.repos.d.backup
修改镜像源:
sed -e 's|^mirrorlist=|#mirrorlist=|g' \-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \-i.bak \/etc/yum.repos.d/rocky*.repo
更新缓存:
dnf clean all && dnf makecache
说明:此操作适用于 Rocky Linux 8 和 9 系列78。
二、使用 DNF 包管理器安装软件
Rocky Linux 使用 dnf
(YUM 的升级版)管理软件包:
安装常用工具:
dnf install -y net-tools wget curl vim tree
搜索软件包:
dnf search <软件名> # 如 dnf search nginx
安装开发工具组(编译环境):
dnf groupinstall "Development Tools"
适用场景:需编译源码或开发 C/C++ 程序时8。
三、安装 EPEL 扩展仓库
EPEL(Extra Packages for Enterprise Linux)提供官方仓库未包含的额外软件:
安装 EPEL 源:
dnf install -y epel-release
更新缓存:
dnf makecache
示例:通过 EPEL 安装 htop
:
dnf install -y htop
```:cite[7]
四、添加第三方仓库安装特定软件
某些软件(如 Docker、MySQL)需添加专用仓库:
安装 Docker:
dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io
systemctl enable --now docker
安装 MySQL:
dnf module enable mysql:8.0
dnf install -y @mysql
systemctl enable --now mysqld
```:cite[7]
五、常见问题与解决
依赖冲突:
-
使用
dnf history undo <事务ID>
回滚操作。 -
手动安装缺失依赖:
dnf provides <缺失文件>
。
网络代理配置:
若需通过代理下载软件,可在 /etc/profile
中添加:
export http_proxy=http://代理IP:端口
export https_proxy=http://代理IP:端口
重启服务或终端生效8。
SELinux 或防火墙干扰:
-
临时禁用 SELinux:
setenforce 0
-
关闭防火墙:
systemctl stop firewalld
68。
六、其他下载方式
源码编译安装:
wget https://example.com/software.tar.gz
tar -zxvf software.tar.gz
cd software
./configure --prefix=/usr/local/software
make && make install
适用场景:官方仓库无预编译包时18。
总结
-
基础操作:优先通过
dnf
安装,配置阿里云镜像加速。 -
扩展软件:启用 EPEL 或第三方仓库。
-
特殊需求:源码编译或容器化部署(如 Docker)。
-
问题排查:关注依赖、网络和权限限制。