centos8自带DNF插件,无需安装
常用命令
检查DNF软件版本
dnf --version
列举dnf 软件库。
dnf repolist
列举所有安装源
dnf repolist all
显示所有软件列表
dnf list
显示已安装软件可用
dnf list installed
搜索软件包可用
dnf search 软件名
安装软件包
dnf install vim
卸载软件
dnf remove vim
升级系统和软件分别为
dnf update systemd
dnf update 或 # dnf upgrade
删除未使用软件包
dnf autoremove
报错
一、No module named _conf
问题描述:CentOS7安装DNF后,运行dnf –-version会报以下错误:
Traceback (most recent call last):File "/usr/bin/dnf", line 57, in <module>from dnf.cli import mainFile "/usr/lib/python2.7/site-packages/dnf/__init__.py", line 30, in <module>import dnf.baseFile "/usr/lib/python2.7/site-packages/dnf/base.py", line 29, in <module>import libdnf.transactionFile "/usr/lib64/python2.7/site-packages/libdnf/__init__.py", line 3, in <module>from . import confFile "/usr/lib64/python2.7/site-packages/libdnf/conf.py", line 17, in <module>_conf = swig_import_helper()File "/usr/lib64/python2.7/site-packages/libdnf/conf.py", line 16, in swig_import_helperreturn importlib.import_module('_conf')File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module__import__(name)
ImportError: No module named _conf
其实最主要的错误就是最后一条:ImportError: No module named _conf
解决办法
先升级python:
yum update python*
再安装以下软件:
yum install dnf-data dnf-plugins-core libdnf-devel libdnf python2-dnf-plugin-migrate dnf-automatic -y
重新运行dnf。
二、python编码问题
问题描述:‘ascii’ codec can’t decode byte 0xe5 in position 4
~ $ dnf --version
4.0.9
Traceback (most recent call last):File "/usr/bin/dnf", line 58, in <module>main.user_main(sys.argv[1:], exit_code=True)File "/usr/lib/python2.7/site-packages/dnf/cli/main.py", line 179, in user_mainerrcode = main(args)File "/usr/lib/python2.7/site-packages/dnf/cli/main.py", line 64, in mainreturn _main(base, args, cli_class, option_parser_class)File "/usr/lib/python2.7/site-packages/dnf/cli/main.py", line 95, in _maincli.configure(list(map(ucd, args)), option_parser())File "/usr/lib/python2.7/site-packages/dnf/cli/cli.py", line 868, in configureself.base.output)File "/usr/lib/python2.7/site-packages/dnf/cli/cli.py", line 137, in print_versionssm_ui_time(pkg.installtime)))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 4: ordinal not in range(128)
解决方法:
这是由于python2中的编码bug,需要在python目录/lib/python2.7/site-packages/
(系统pyhton目录:/usr/lib/python2.7/site-packages/
)中新建一个文件:sitecustomize.py
,其中包含下列代码
import sys
sys.setdefaultencoding('utf-8')
验证:
dnf --version
常用软件安装
wget
dnf install wget
mysql
centos7先去官网找npm,配置yum,配置命令
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
dnf下载或yum下载
dnf install mysql-server
yum install mysql-server
reids
dnf install redis
nginx
dnf install nginx