How do I find out what version of Linux I'm running?

409,848

Solution 1

The kernel is universally detected with uname:

$ uname -or
2.6.18-128.el5 GNU/Linux

There really isn't a cross-distribution way to determine what distribution and version you're on. There have been attempts to make this consistent, but ultimately it varies, unfortunately. LSB tools provide this information, but ironically aren't installed by default everywhere. Example on an Ubuntu 9.04 system with the lsb-release package installed:

$ lsb_release -irc
Distributor ID: Ubuntu
Release:        9.04
Codename:       jaunty

Otherwise, the closest widely-available method is checking /etc/something-release files. These exist on most of the common platforms, and on their derivatives (i.e., Red Hat and CentOS).

Here are some examples.

Ubuntu has /etc/lsb-release:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.04
DISTRIB_CODENAME=jaunty
DISTRIB_DESCRIPTION="Ubuntu 9.04"

But Debian has /etc/debian_version:

$ cat /etc/debian_version
5.0.2

Fedora, Red Hat and CentOS have:

Fedora: $ cat /etc/fedora-release
Fedora release 10 (Cambridge)

Red Hat/older CentOS: $ cat /etc/redhat-release
CentOS release 5.3 (Final)

newer CentOS: $ cat /etc/centos-release
CentOS Linux release 7.1.1503 (Core)

Gentoo:

$ cat /etc/gentoo-release
Gentoo Base System release 1.12.11.1

I don't have a SUSE system available at the moment, but I believe it is /etc/SuSE-release.

Slackware has /etc/slackware-release and/or /etc/slackware-version.

Mandriva has /etc/mandriva-release.

For most of the popular distributions then,

$ cat /etc/*{release,version}

will most often work. Stripped down and barebones "server" installations might not have the 'release' package for the distribution installed.

Additionally, two 3rd party programs you can use to automatically get this information are Ohai and Facter.

Note that many distributions have this kind of information in /etc/issue or /etc/motd, but some security policies and best practices indicate that these files should contain access notification banners.

Related: How to find out version of software package installed on the node?, .

Solution 2

You could also try:

$ cat /etc/issue

It usually (not always, though) will tell you what distribution you are using. /etc/issue is the file used for the login screen.

Solution 3

Kernel: uname -a

Solution 4

cat /etc/os-release

at a minimum for Ubuntu, Fedora and OpenSUSE.

Does not work for OS X at least until 10.9 (Mavericks). Use sw_vers instead.

OpenSUSE had cat /etc/SuSE-release up until 13.1 but is deprecated in favour of os-release.

Redhat 6.1 has cat /etc/redhat-release

Solution 5

lsb_release -a, when available, is useful.

Share:
409,848

Related videos on Youtube

stereoscott
Author by

stereoscott

Father of three, husband, computer programmer (Pythonista), skeptic, atheist, podcast listener, baseball fan, Canadian (in the United States).

Updated on September 17, 2022

Comments

  • stereoscott
    stereoscott over 1 year

    Is there a way to determine what version (distribution & kernel version, I suppose) of Linux is running (from the command-line), that works on any Linux system?

  • Ivo Flipse
    Ivo Flipse almost 15 years
    Lol here I was thinking to suggest: look for About!
  • Ken Keenan
    Ken Keenan almost 15 years
    Slackware has /etc/slackware-version
  • jtimberman
    jtimberman almost 15 years
    Thanks Ken, I don't have a slackware system either.
  • freiheit
    freiheit almost 15 years
    IOW: ls /etc/*{release,version} and examine whatever comes back...
  • stereoscott
    stereoscott almost 15 years
    freiheit, you ought to put that in a separate answer.
  • erichui
    erichui almost 15 years
    Mandriva has /etc/mandriva-release
  • Drew Stephens
    Drew Stephens almost 15 years
    Most also have /etc/issue
  • jtimberman
    jtimberman almost 15 years
    @dinomite Indeed, and many put that information there, but it shouldn't be considered definitive, and is often used for access banners as I had added to the answer earlier.
  • Peter Mortensen
    Peter Mortensen almost 12 years
    +1. For similar systems, like MinGW, the "-a" is required to get the version information, for example, "MINGW32_NT-5.1 LAP065 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys".
  • TryTryAgain
    TryTryAgain about 11 years
    This is the only one that nailed it for me on a shared Media Temple server. Thanks!!
  • vjalle
    vjalle about 9 years
    Ha, on RedHat, that's just \S[newline]Kernel \r on an \m
  • pevik
    pevik over 7 years
  • fixer1234
    fixer1234 about 6 years
    This might be more appropriate as a comment on Albert Z's answer.
  • B.Kocis
    B.Kocis about 6 years
    mighty answer to conclude all answers! I must upvote for the effort :)
  • kol
    kol almost 6 years
    SuSE: cat /etc/SuSE-release (just tested, it works)
  • questionto42standswithUkraine
    questionto42standswithUkraine over 3 years
    For example for Linux Mint