Knowing the name and version of a distro is vital for users and administrators. The information is important in numerous situations like installing new apps or features, troubleshooting, etc. This guide will demonstrate how to check the OS version from the command line on Linux.
Checking the operating system version
Here are some of the simplest ways of checking the operating system version. Almost all of these methods should apply to any Linux distro. These methods utilize the built-in tools and feature Linux comes with.
Checking OS version from /etc/os-release
In Linux, the os-release file contains various information about the system. There are two copies of the file at two different locations.
Interestingly, the file located at /etc/os-release will take precedence over /usr/lib/os-release.
It contains information in the format of a newline-separated list of various variables. It contains info like OS name, version, version ID, builds ID, etc.
To check the content of the os-release file, run the following command.
Note that the output will vary from one Linux distro to another. This file will only be available if the OS uses the systemd as the init system.
Here are some examples that fine-tune the content of os-release to print only specific details. The following command will print only the version and name of the OS.
To check the version of the OS only, run the following command instead.
Checking OS version using lsb_release
The lsb_release tool provides certain LSB (Linux Standard Base) and distro-specific info. Generally, lsb_release is used in the following format.
Here, the flag “-a” tells lsb_release to print all the info about the OS it can provide. Alternatively, you can print a minimal report using the flag “-s” or “–short”. It will omit the headers in the output.
This tool also supports printing one specific piece of information at a time. For example, to print only the OS description, use the flag “-d” or “–description”.
To display the codename of the current OS, use the flag “-c” or “–codename”.
The man page contains an in-depth description of all the available options.
Checking OS version using hostnamectl
The hostnamectl command is responsible for managing the Linux system hostname and related settings. It can also print a host of info on the system and operating system.
Checking OS version using uname
Similar to lsb_release and hostnamectl, uname is another tool to report various info about the machine and operating system. However, the output is a bit more disorganized compared to hostnamectl output.
To print all the information about the system, run the following uname command. Here, the flag “-a” tells uname to print all the supported info.
We can also tell uname to print only specific detail. For example, the flag “-v” or “–kernel-version” will print the kernel version.
The following uname command will print the operating system label.
For all the available options and their explanations, check the man page.
Checking OS version from /etc/issue
The file /etc/issue stores system identification information. It’s generally shown before you’re prompted to log in to your account. Check the content of the file.
Checking OS version using /proc/version
It’s a text file that includes information about the Linux kernel.
Checking OS version using /etc/*release
If none of the aforementioned methods succeeded, then it’s highly likely that you’re running a very old Linux system. If that’s the case, then we have to take advantage of a very rudimentary method of checking OS information.
Run the following command.
Here, cat will read and print the content of all the files that match the pattern. You can check what files we’re reading from.
This guide demonstrates how to check the version of the Linux operating system running on the machine. Although there are many third-party tools, we can achieve it using the built-in tools and features only.
The version of a Linux operating system is an important piece of information. Generally, Linux packages are built to work with a particular Linux version in mind. Knowing the Linux version can help in troubleshooting unexpected behaviors or errors. It’s also important when a new version of the Linux distro is released. It’s simple yet crucial info to keep track of.