Home > Article > System Tutorial > Check the version of Linux system you are running
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.
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
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
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
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/"
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"
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
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
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
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
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
The output is the Linux kernel version information:
$ uname -r 5.4.43-1-virt
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!