How to check which Linux version you are running?

In this post I would like to show you how to check which Linux version you are running on your machine. You can find this information from the output of multiple commands.

Gulian Technology

How to check which Linux version you are running
Gulian Technology

Cat /etc/os-release

The first command that you can use is cat /etc/os-release. Below you can find an output from an Ubuntu machine and from a Redhat machine.

petru@petru-ubuntu:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 23.04"
NAME="Ubuntu"
VERSION_ID="23.04"
VERSION="23.04 (Lunar Lobster)"
VERSION_CODENAME=lunar
ID=ubuntu
ID_LIKE=debian
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"
UBUNTU_CODENAME=lunar
LOGO=ubuntu-logo
petru@petru-ubuntu:~$
Ubuntu os-release file
Ubuntu os-release file
 [petru@rhel9 ~]$ cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="9.1 (Plow)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="9.1"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Red Hat Enterprise Linux 9.1 (Plow)"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/9/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_BUGZILLA_PRODUCT_VERSION=9.1
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.1"
[petru@rhel9 ~]$ 
Redhat os-release file
Redhat os-release file

On Redhat there is an additional file that you can check. Its name is redhat-release.

[petru@rhel9 ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux release 9.1 (Plow)
[petru@rhel9 ~]$ 
Redhat redhat-release file

lsb_release -a

Another command that you can run in order to find the Linux version that you are running is lsb_release -a.

petru@petru-ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 23.04
Release:	23.04
Codename:	lunar
petru@petru-ubuntu:~$ 
Output lsb_release -a
Output lsb_release -a

The command lsb_release is not present by default on redhat distribution.

[petru@rhel9 ~]$ lsb_release -a
bash: lsb_release: command not found...
[petru@rhel9 ~]$ 

If you want to find more information about the lsb_release, run the command man lsb_release.

Output of man lsb_release command
Output of man lsb_release command

hostnamectl

Another useful command that can show you the Linux version that you are running is hostnamectl.

petru@petru-ubuntu:~$ hostnamectl
 Static hostname: petru-ubuntu
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 0261e5765b5d4aa5af4277801ffb9350
         Boot ID: 4f6ab7007c034c7fae3055ae1bb911d5
  Virtualization: vmware
Operating System: Ubuntu 23.04                    
          Kernel: Linux 6.2.0-20-generic
    Architecture: x86-64
Firmware Version: 6.00
petru@petru-ubuntu:~$ 
Output of hostnamectl command
Output of hostnamectl command
[petru@rhel9 ~]$ hostnamectl
 Static hostname: rhel9
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 72c31626f96a45cebc790ae7ee9d0e7a
         Boot ID: 59ad19bd3dba415198cf1f11fc9106c8
  Virtualization: vmware
Operating System: Red Hat Enterprise Linux 9.1 (Plow)     
     CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
          Kernel: Linux 5.14.0-162.23.1.el9_1.x86_64
    Architecture: x86-64
 Hardware Vendor: VMware, Inc.
  Hardware Model: VMware Virtual Platform
[petru@rhel9 ~]$ 
Output of hostnamectl command
Output of hostnamectl command

In addition to finding out what version of Linux you are running, you can change the system hostname with the hostnamectl command.

To change the system hostname run a similar command.

[petru@rhel9 ~]$ sudo hostnamectl hostname newrhel
[petru@rhel9 ~]$ hostnamectl
 Static hostname: newrhel
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 72c31626f96a45cebc790ae7ee9d0e7a
         Boot ID: 42069f8f5ed74a9f92d657a746bc9ac8
  Virtualization: vmware
Operating System: Red Hat Enterprise Linux 9.1 (Plow)     
     CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
          Kernel: Linux 5.14.0-162.23.1.el9_1.x86_64
    Architecture: x86-64
 Hardware Vendor: VMware, Inc.
  Hardware Model: VMware Virtual Platform
[petru@rhel9 ~]$ 
Change the system name with the hostnamectl command
Change the system name with the hostnamectl command

After opening a new terminal you can confirm the new system name in the prompt. For more information about the hostnamectl command, run man hostnamectl or hostnamectl –help.

[petru@newrhel ~]$ hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...

Query or change system hostname.

Commands:
  status                 Show current hostname settings
  hostname [NAME]        Get/set system hostname
  icon-name [NAME]       Get/set icon name for host
  chassis [NAME]         Get/set chassis type for host
  deployment [NAME]      Get/set deployment environment for host
  location [NAME]        Get/set location for host

Options:
  -h --help              Show this help
     --version           Show package version
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host
  -M --machine=CONTAINER Operate on local container
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname
     --json=pretty|short|off
                         Generate JSON output

See the hostnamectl(1) man page for details.
[petru@newrhel ~]$ 
Output of hostnamectl --help command
Output of hostnamectl –help command

How to check which kernel version you are running

You learned how to check the Linux version that you are running. Now maybe you ask yourself, but how do I check the Kernel version on my Linux machine.

For this you will need to run the command uname -r.

petru@petru-ubuntu:~$ uname -r
6.2.0-20-generic
petru@petru-ubuntu:~$
Output of uname -r
Output of uname -r

For additional information, like node name, kernel name, kernel-release, you can run the command uname -a.

[petru@newrhel ~]$ uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type (non-portable)
  -i, --hardware-platform  print the hardware platform (non-portable)
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/uname>
or available locally via: info '(coreutils) uname invocation'
[petru@newrhel ~]$ uname -a
Linux newrhel 5.14.0-162.23.1.el9_1.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 23 20:08:28 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux
[petru@newrhel ~]$ 

That’s it! You have learned how to check the Linux version of your machine and the kernel version. If you found this blog post helpful, please like and subscribe for more Linux tutorials. Thank you for reading it!

Processing…
Success! You're on the list.

Leave a Reply