I want to check whether python 3 is installed on my Ubuntu. I'm using this script:
#!/usr/bin/env sh
#install firefox if does not exist
if ! command -v python3 >/dev/null 2>&1
then
echo "not installed"
else
echo "installed"
fi
When I run this script, the output is installed, but when I check my python using python --version, I get this output:
Python 2.7.17
Which, as far as I know, means that the latest version of python on my Ubuntu is 2.7 not 3.x. What's wrong?
The output of command -v python3; echo $?:
/usr/bin/python3
0
The output of ls -l /usr/bin/python3:
lrwxrwxrwx 1 root root 9 Nov 14 09:13 /usr/bin/python3 -> python3.7
The output of ls -l /usr/bin/python3.7:
-rwxr-xr-x 2 root root 5102632 Oct 27 11:43 /usr/bin/python3.7
The output of which python:
/usr/bin/python
The output of ls -l /usr/bin/python:
lrwxrwxrwx 1 root root 7 Jan 19 08:04 /usr/bin/python -> python2
The output of ls -l /usr/bin/python2:
lrwxrwxrwx 1 root root 9 Jan 19 08:04 /usr/bin/python2 -> python2.7
Also I have another Ubuntu on a separate VM, the output of python --version, returns command 'python' not found, but when I execute the above commands for this VM as well, it returns similar responses (indicating that python is installed).
command -v python3; echo $?to your question.ls -l /usr/bin/python3to your question.ls -l /usr/bin/python3.7andwhich pythonto your question.python3 --versioninstead ofpython --versionls -l /usr/bin/python.