Try the command lsb-release
, It should return the release version of the distribution. You should be able to extract the version from the output.
Running just
lsb_release --release --short
will return the ubuntu version number
Question
I'm working on java web application where logic will be different based on the os version.
Currently we deploy our application both on Ubuntu 12.04 and Ubuntu 10. The Web App allows to change DNS nameservers through its UI. The application deployed in Ubuntu 10 keeps DNS name servers on etc/resolv.conf
but Ubuntu 12.04 keeps them in etc/network/interfaces
.
When storing DNS nameservers logic would be like
if(ubuntuVersion < ubuntu 12.04) then
store it in etc/resolv.conf
else
store it in etc/network/interfaces.
System.getProperty("os.name")
or System.getProperty("os.arch")
or any other system properties don't output Ubuntu package information.
How can the if
part be implemented?
Solution
Try the command lsb-release
, It should return the release version of the distribution. You should be able to extract the version from the output.
Running just
lsb_release --release --short
will return the ubuntu version number
OTHER TIPS
You can get the OS version with:
lsb_release -a|grep Release|cut -f2