Home > System Tutorial > LINUX > Check the version of Linux system you are running

Check the version of Linux system you are running

王林
Release: 2024-02-11 20:50:33
forward
1052 people have browsed it

For Linux systems, if you installed it yourself, you will know which distribution is installed and the version number. But if it is a remote Linux server connected using ssh, then its version is not so obvious and you need to use some method to check it.

查看正在运行的 Linux 系统版本

Free operation system. The word “Linux” is lined with gold letters on wooden planks. 3D illustration graphics

The simplest method is to check the file /etc/os-release, which records system-related information:

cat /etc/os-release
Copy after login
Copy after login

The output is similar to the following:

NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
Copy after login

As you can see from the above output, the system release version is Ubuntu and the version number is 20.04.1.

The above is one way to check the Linux system version. In addition, there are other ways. Let’s take a closer look below.

View Linux distribution information

Method 1: View the /etc/os-release file

If you are familiar with the Linux directory structure, you should know that the directory /etc contains the core configuration files of the system.

The os-release file records information related to the Linux distribution, including the distribution name, version number or ID, etc.

To view this file, you can use the cat command in the terminal, as shown below:

cat /etc/os-release
Copy after login
Copy after login

The following is the display content of the Alpine Linux server running on the Linode infrastructure:

$ cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.12.0
PRETTY_NAME="Alpine Linux v3.12"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
Copy after login

In the above output, the name of the Linux distribution is Alpine Linux and the version number is 3.12.

Based on different Linux distributions, the contents of the file /etc/os-release are usually different. It is usually used to record some additional information about the system, including how to obtain support, bugs, etc.

For example, in CentOS, the contents of /etc/os-release are as follows:

NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
Copy after login

However, no matter which release it is, the system version name and version number will be recorded in the file /etc/os-release. For this reason, viewing this file to obtain version information is the most reliable method.

Method 2: Use hostnamectl command

Most Linux distributions now use systemd. Based on this, you can also use the hostnamectl command to view the system version information.

hostnamectl
Copy after login

For example, in CentOS system, the output information is as follows:

[root@li2498-99 ~]# hostnamectl 
   Static hostname: localhost.localdomain
Transient hostname: li2498-99.members.linode.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: e3fe2be3e17be3e1763bf43e8337e68b
           Boot ID: 33d3052bbffd44b1869bbffd4b00d26c
    Virtualization: kvm
  Operating System: CentOS Linux 8 (Core)
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-147.8.1.el8_1.x86_64
      Architecture: x86-64
Copy after login

In the line starting with "Operating System", the system information is displayed.

The hostnamectl command is mainly used to handle hostname-related operations, but because it also provides other information about the system, it is also a way to view system version information.

Method 3: Use the lsb_release command

lsb_release command is not available in all Linux distributions. It is mainly used in Debian/Ubuntu-based systems.

Use the lsb_release command together with the -a option to view system release information:

lsb_release -a
Copy after login

In its output, the message "No LSB modules are available" can be ignored, this is not an error. As follows:

linux@handbook:~$ lsb_release -a
No LSB modules are available.
Distributor ID:Ubuntu
Description:Ubuntu 20.04.1 LTS
Release:20.04
Codename:focal
Copy after login

Check Linux kernel version

Above we introduced the method of checking the system release version. Next, we will briefly introduce the method of checking the Linux kernel version.

To view Linux kernel version information, you can use the uname command, as follows:

uname -r
Copy after login

The output is the Linux kernel version information:

$ uname -r
5.4.43-1-virt
Copy after login

As shown in the above output, its kernel version is 5.4.43.

The above is the entire content of this sharing, welcome to discuss.

The above is the detailed content of Check the version of Linux system you are running. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template