问题

在执行命令“lsb_release -r”以显示当前安装的发行版的版本号时,收到以下错误:

# lsb_release -v
-bash: lsb_release: command not found
on  it road.com

解决方案

要检查 RedHat/CentOS 版本,可以使用“lsb_release”命令。
在大多数情况下,系统上默认不安装提供此命令的软件包。
要检查哪个包提供 lsb_release 命令,请使用以下命令:

对于 CentOS/RHEL 7

# yum whatprovides lsb_release
Loaded plugins: fastestmirror

redhat-lsb-core-4.1-27.el7.centos.1.i686 : LSB Core module support
Repo        : base
Matched from:
Filename    : /usr/bin/lsb_release

对于 CentOS/RHEL 8:

# yum whatprovides lsb_release

Repo        : rhel-8-appstream-rhui-rpms
Matched from:
Filename    : /usr/bin/lsb_release
redhat-lsb-core-4.1-47.el8.i686 : LSB Core module support
Repo        : rhel-8-appstream-rhui-rpms
Matched from:
Filename    : /usr/bin/lsb_release

如上所示,lsb_release 命令由包“redhat-lsb-core”提供。
默认情况下,系统上可能不存在此软件包,我们可能需要先安装它。
在 CentOS/RHEL 7 和 8 系统中使用以下命令安装软件包:

# yum install redhat-lsb-core

或者

# yum install redhat-lsb

我更喜欢安装“redhat-lsb-core”而不是“redhat-lsb-core”,因为它需要较少的包依赖性。
如果我们不是特别需要“redhat-lsb”包,我建议只安装核心包。

对于 CentOS/RHEL 8,我们还可以使用 dnf 来安装软件包:

# dnf install redhat-lsb-core

示例输出:

# dnf install redhat-lsb-core

现在,尝试运行 lsb_release 命令:

# lsb_release
LSB Version:	:core-4.1-amd64:core-4.1-noarch

lsb_release 命令的各种选项是:

# lsb_release --help
FSG lsb_release v2.0 prints certain LSB (Linux Standard Base) and
Distribution information.
Usage: lsb_release [OPTION]...
With no OPTION specified defaults to -v.
Options:
  -v, --version
    Display the version of the LSB specification against which the distribution is compliant.
  -i, --id
    Display the string id of the distributor.
  -d, --description
    Display the single line text description of the distribution.
  -r, --release
    Display the release number of the distribution.
  -c, --codename
    Display the codename according to the distribution release.
  -a, --all
    Display all of the above information.
  -s, --short
    Use short output format for information requested by other options (or version if none).
  -h, --help
    Display this message.
在 CentOS/RHEL中 报错 lsb_release: command not found
日期:2020-09-17 00:14:04 来源:oir作者:oir