If this happens, you can try this to find out more about what keytool really represents.
keytool -version
if it gives you output like this:
Unrecognized command: -version Usage: keytool [COMMAND] [-- COMMAND]... Manage private keys and public certificates. Available commands: ....
Try this:
update-alternatives --display keytool
And if you have seen this:
keytool - AUTO link best version is /usr/bin/gkeytool-5 link points to /usr/bin/gkeytool-5 link keytool is /usr/bin/keytool slave keytool.1.gz is /usr/share/man/man1/keytool.1.gz /usr/bin/gkeytool-5 - priority 1050 secondary keytool.1.gz:/usr/share/man/man1/gkeytool-5.1.gz
Now you know that the keytool is actually not pointing to $JAVA_HOME/bin/keytool, but to something similar but different, that is native of Ubuntu, named gkeytool, which offers the same functionalities but will fail at this specific case.
So, you can:
To not eliminate the gkeytool, use update-alternatives to change the keyword keytool, to make it point to $JAVA_HOME/bin/keytool, which should be at priority level 0. Use update-alternatives -help to see full syntax.
Or, you can access the real keytool offered by JDK, by:
cd $JAVA_HOME/bin/ And, ./keytool -list -keystore <full/path/to/cacerts>
Note the ./ part is crucial.
Of course, before using the system variable $JAVA_HOME, you have to set it. First, look for it in the existent variables by
env | grep -i java_home
-i means "case insensitive".
if it returns nothing, then
export JAVA_HOME=<path/to/your/jdk/installation/directory/>
(export only sets session-wide environment variables. Once closed this Terminal, values set here is not working any more. For setting
- this-user-only,
- user-wide except
su, - user-wide including
su, - system-wide-and-shell-only,
- system-wide-for-all-applications, and
- system-wide for locale variables,
be sure to read this link: https://help.ubuntu.com/community/EnvironmentVariables)