tencent cloud

TencentOS Server

Software Package Management

ダウンロード
フォーカスモード
フォントサイズ
最終更新日: 2026-10-19 17:10:33
AI翻訳
Package management on TencentOS Server involves various operations such as querying, installing, updating, removing software packages, and configuring software sources. This document describes how to use dnf (Dandified YUM) and rpm to complete these tasks, helping you efficiently manage the entire lifecycle of software packages.
Note: TencentOS Server 4 uses dnf by default, while TencentOS Server 3 supports both yum and dnf.

Prerequisites

Permission requirements: Installing or removing software packages requires root permissions, while query operations can be performed by ordinary users.
Network requirements: Online installation requires network access to software sources on the public network or private network.

Introduction to Software Repositories

TencentOS Server provides the following two types of software sources:
Base software source: contains [BaseOS] and [AppStream], provides core system components and application packages, and is configured by default.
EPOL source (Extra Packages for TencentOS Linux): provides additional enhanced feature packages and is configured by default.
By default, only [BaseOS] and [AppStream] are enabled. To use other sources such as debuginfo or source, set enabled to 1 in the corresponding configuration section.
cat /etc/yum.repos.d/TencentOS.repo
Return sample:
[BaseOS]
name=BaseOS $releasever - $basearch
baseurl=https://mirrors.tencent.com/tlinux/$releasever/BaseOS/$basearch/os/Packages/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS
[AppStream]
name=AppStream $releasever - $basearch
baseurl=https://mirrors.tencent.com/tlinux/$releasever/AppStream/$basearch/os/Packages/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS
[BaseOS-debuginfo]
name=BaseOS-debuginfo $releasever - $basearch
baseurl=https://mirrors.tencent.com/tlinux/$releasever/BaseOS/$basearch/debug/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS
[AppStream-debuginfo]
name=AppStream-debuginfo $releasever - $basearch
baseurl=https://mirrors.tencent.com/tlinux/$releasever/AppStream/$basearch/debug/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS
[BaseOS-source]
name=BaseOS-source $releasever
baseurl=https://mirrors.tencent.com/tlinux/$releasever/BaseOS/source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS
[AppStream-source]
name=AppStream-source $releasever
baseurl=https://mirrors.tencent.com/tlinux/$releasever/AppStream/source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS
If the EPOL source configuration is missing, install it by running the following command:
dnf install -y epol-release
After the installation is complete, you can access the rpm packages in EPOL.

Setting Up a Local Software Repository

For scenarios where software sources need to be used offline, you can build a local software source yourself. The detailed steps are as follows:
1. Creating directories
mkdir -p /mnt/myiso # Create a directory for the iso. You can customize the directory. Ensure that there is sufficient storage space.
mkdir -p /mnt/my_yum # Create a directory for mounting the iso. You can customize the directory. Ensure that there is sufficient storage space.
2. Download the ISO image file (using x86_64 as an example here).
cd /mnt/myiso
wget https://mirrors.tencent.com/tlinux/4.0/isos/x86_64/TencentOS-Server-4.0-everything-x86_64.iso
Note: The version numbers in the examples are for demonstration only. Replace them with the actual version paths as needed.
3. Mount the ISO.
Temporary mount (invalid after restart)
mount -o loop /mnt/myiso/TencentOS-Server-4.0-everything-x86_64.iso /mnt/my_yum/
Permanent mount (automatically mounted after restart)
Edit the configuration file vim /etc/fstab, and add the following content.
echo "/mnt/myiso/TencentOS-Server-4.0-everything-x86_64.iso /mnt/my_yum iso9660 loop,ro 0 0" >> /etc/fstab
After mounting, you can access the rpm packages in the ISO through the /mnt/my_yum directory:
cd /mnt/my_yum/
tree -L 2 .
Output example:
.
├── AppStream
│ ├── Packages
│ └── repodata
├── BaseOS
│ ├── Packages
│ └── repodata
├── boot
│ └── grub2
├── EFI
│ └── BOOT
└── images
├── efiboot.img
├── eltorito.img
├── install.img
└── pxeboot

12 directories, 3 files
4. To configure a local repo source, refer to the following:
# View the repo file: cat /etc/yum.repos.d/local.repo
[AppStream]
name=AppStream
baseurl=file:///mnt/my_yum/AppStream
priority=1
enabled=1
[BaseOS]
name=BaseOS
baseurl=file:///mnt/my_yum/BaseOS
priority=1
enabled=1
5. Verify. You can try installing a software package or querying the software packages in the repository for verification.

Setting Up a Temporary Local Repository

In addition to using the official ISO to build a local source, you can also prepare rpm packages yourself and create a temporary local source from a specified directory. The detailed steps are as follows:
1. Creating directories
mkdir -p /mnt/local_repo/x86_64/Packages # Customize the directory location. Ensure that there is sufficient storage space.
2. Install the createrepo tool.
dnf install -y createrepo
3. Copy the rpm packages to the local source directory.
cp *.rpm /mnt/local_repo/x86_64/Packages
4. Create repodata.
createrepo /mnt/local_repo/x86_64
After execution, repodata will be created in the /mnt/local_repo/x86_64 directory.
5. To configure a local repo source, refer to the following:

[local]
name=local
baseurl=file:///mnt/local_repo/x86_64
priority=1
enabled=1
6. Verify. You can try installing a software package or querying the software packages in the repository for verification.

Package Management Configuration

By default, the system uses the dnf tool for software package management. The dnf configuration consists of two parts: the dnf configuration itself and the source configuration.

dnf Configuration

The default system configuration is as follows:
cat /etc/dnf/dnf.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
zchunk=False
In addition to the default configuration, you can also adjust the dnf configuration yourself. For a complete description of parameters, run man dnf.conf.

Repository Configuration

The default repo configuration in the environment has been listed above. Common configuration descriptions are as follows, and you can adjust them as needed.
Parameter
Value Type
Default Value
Description
name
string
None
Name of the repo source
baseurl
list
None
List of URLs for the repo source
priority
integer
None
Priority of the repo source, ranging from 0 - 99, with a smaller value indicating a higher priority.
gpgcheck
boolean
1
Whether to perform GPG verification
gpgkey
string
None
URL or local path of the GPG public key, used with gpgcheck
installonly_limit
integer
3
Number of software packages that can be installed in parallel
clean_requirements_on_remove
boolean
True
Whether to remove dependencies that are not used by other software packages when removing a software package
best
boolean
True
Whether to install the highest version when installing a software package, and fail if it cannot be installed.
skip_if_unavailable
boolean
False
When set to True, unavailable sources are skipped. When set to False (default), an error is reported upon encountering an unavailable source.
zchunk
boolean
False
Whether to compress repo metadata in zchunk format.

Software Repository Management

Viewing Software Sources

# List all enabled software sources
dnf repolist
# List all software sources (including disabled ones)
dnf repolist all
# View detailed information about a software source
dnf repoinfo <repo-name>
Example output of dnf repolist all:
repo id repo name status
AppStream TencentOS-4 - AppStream enabled
BaseOS TencentOS-4 - BaseOS enabled
extras TencentOS-4 - Extras enabled

Enabling or Disabling a Software Repository

# Temporarily disable a source (effective only for this command)
dnf install <package-name> --disablerepo=<repo-id>
# Permanently enable a source
dnf config-manager --enable <repo-id>
# Permanently disable a source
dnf config-manager --disable <repo-id>

Add software source

# Add a software source by URL
dnf config-manager --add-repo <repo-url>
# Manually create a .repo file
vi /etc/yum.repos.d/<name>.repo
Example of a software source configuration file format:
[myrepo]
name=My Custom Repository
baseurl=https://example.com/repo/
enabled=1
gpgcheck=1
gpgkey=https://example.com/RPM-GPG-KEY

Common Package Management Commands

Querying Software Packages

List installed software packages:
# List all installed software packages in the current environment
dnf list installed
# List all installed software packages (via rpm)
rpm -qa
Note: rpm -qa lists all packages installed on the system and is typically used with the grep command.
Search for software packages:
# Search for software packages that contain a keyword
dnf search <package-name>
# Search in package names and summaries (more precise)
dnf search --all <package-name>
View software package information:
# View detailed information about a software package
dnf info <package-name>
# Query software package information (via rpm)
rpm -qi <package-name>
# View the file list of a software package
rpm -ql <package-name>
# Find which software package a file belongs to
dnf provides /etc/<package-name>/<package-name>.conf
dnf provides "*.so.1"
# Find which software package a file belongs to (via rpm)
rpm -qf /etc/<package-name>/<package-name>.conf
List software packages:
# List all installable software packages (show only those not installed)
dnf list available
# List all available versions of a specific software package
dnf list <package-name> --showduplicates
Query dependencies:
# Find which packages depend on a specific software package
dnf repoquery --whatrequires <package-name>
# Query dependencies of a specific software package
dnf repoquery --requires <package-name>

Installing Software Packages

# Install software packages from a repository
dnf install -y <package-name>
# Install multiple software packages
dnf install -y <package-name1> <package-name2> <package-name3>
# Install a specific version
dnf install <package-name-1.2.1>
# Install a user-compiled rpm package file
dnf localinstall -y <package-name>.rpm
dnf install /path/to/<package-name>.rpm
# Install a software package group
dnf groupinstall "package-group-name"
# View available software package groups
dnf grouplist

Updating Software Packages

# Check available updates (without installing them)
dnf check-update
# Update all software packages (automatically confirm)
dnf update -y
# Update a specific software package
dnf update <package-name>
# Upgrade installed rpm packages
dnf upgrade <package-name>
# Update a software package group
dnf groupupdate "package-group-name"
Warning: Updating software packages may introduce dependency changes or compatibility issues. It is recommended to verify updates in a test environment before applying them to production. Before updating, you can use dnf update --downloadonly to pre-download packages or use dnf history to keep a record for rollback.

Downgrading Software Packages

# Downgrade installed rpm packages
dnf downgrade <package-name>
Warning: Downgrading may cause dependency conflicts. It is recommended to verify the compatibility between the target version and dependent packages before proceeding.

Uninstalling Software Packages

# Uninstall a software package (keep dependencies)
dnf remove <package-name>
# Uninstall a software package and its dependencies that are not used by other packages
dnf autoremove <package-name>
# Remove dependency packages that are no longer needed
dnf autoremove
Warning: Uninstalling a software package may affect other software or services that depend on it. During uninstallation, a list of packages to be removed will be displayed. Review the list carefully before proceeding to avoid accidentally removing critical system components and causing system exceptions. Before uninstalling, use dnf repoquery --whatrequires <package name> to check the impact scope.

Downloading Software Packages

# Download rpm packages from the source (without installing)
dnf download <package-name>

Viewing Operation History

# View dnf operation history
dnf history
# View details of an operation
dnf history info <id>
# Roll back an operation
dnf history undo <id>

Basic RPM Operations

The rpm command can directly operate on RPM packages without connecting to a software source:
# Check whether a software package is installed
rpm -q <package-name>
# Query all installed software packages
rpm -qa
# Query the installation files of a software package
rpm -ql <package-name>
# Find which software package a file belongs to
rpm -qf /etc/<package-name>/<package-name>.conf
# View detailed information about a software package
rpm -qi <package-name>
# Query the version of a software package
rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\\n" <package-name>
# Install RPM packages (without resolving dependencies, suitable for offline scenarios)
rpm -ivh <package-name>.rpm
# Force install (ignore dependency checks)
rpm -ivh --force --nodeps <package-name>.rpm
# Uninstall
rpm -e <package-name>

Module Stream Management (TencentOS Server 3)

TencentOS Server 3 supports installing multiple versions of the same software through module streams:
# View available modules
dnf module list
# View information about a specific module
dnf module info python3
# Enable a specific version stream
dnf module enable python3:3.8
# Install modules
dnf module install python3:3.8/default
# Reset module (restore default stream)
dnf module reset python3

Cache management

# Clean up software package cache
dnf clean packages
# Clear all caches
dnf clean all
# Regenerate metadata cache
dnf makecache

Verifying Software Packages

# Verify that the software package is installed
dnf list installed | grep <package-name>
# Verify software package integrity
rpm -V <package-name>
# View dnf logs
cat /var/log/dnf.log | tail -50

Troubleshooting Common Errors

Installation Failure

Issue 1: GPG Key Not Installed

Problem description: The following error is reported when a software package is installed:
You have enabled checking of packages via GPG keys. This is a good thing.
However, you do not have any GPG public keys installed. You need to download
the keys for packages you wish to install and install them.
You can do that by running the command:
rpm --import public.gpg.key
Solution: Import the system GPG public key:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS-*

Issue 2: RPM Database Corruption

Problem description: The following error is reported when a software package is installed or queried:
error: cannot open Packages database in /var/lib/rpm
Solution: This issue is often caused by force-terminating yum/dnf processes, which damages the rpm database. To resolve it, follow these steps:
1. Delete the corrupted rpmdb file:
rm -f /var/lib/rpm/__db.*
2. Rebuild the rpm database:
rpm --rebuilddb
dnf clean all

Issue 3: Error Message "No match for argument"

Problem description: The No match for argument error is reported when a software package is installed, which is usually caused by an expired cache or an incorrect package name.
Solution: Troubleshoot and fix the issue by following these steps:
# Clear the cache and retry
dnf clean all
dnf makecache
dnf install <package-name>
# Confirm that the software source is enabled
dnf repolist
# Try searching for the correct package name
dnf search <keyword>

Issue 4: Error Message "GPG key check failed"

Problem description: A GPG check failure is reported when a software package is installed.
Solution: You can import the GPG key or temporarily skip the check:
# Method 1: Import the GPG key
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-TencentOS-*
# Method 2: Temporarily skip the GPG check (not recommended for production environments)
dnf install <package-name> --nogpgcheck

Slow dnf update Speed

Problem description: The download speed is slow when dnf update is run.
Solution: Check and optimize the software source configuration:
# Confirm that a mirror source is used
dnf repolist -v | grep Repo-baseurl
# Change the software source (edit /etc/yum.repos.d/*.repo to modify baseurl)

Inconsistency Between dnf and rpm Databases

Problem description: The query results from dnf and rpm are inconsistent.
Solution: Rebuild the RPM database and clear the dnf cache:
# Rebuild the RPM database
rpm --rebuilddb
dnf clean all


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック