keytool error bash: keytool: command not found

233,364

Solution 1

These are the steps which solved my problem:

  • Search the path where my java was installed

    find / -name jre
    
  • Move to java directory (where jre was installed on my server)

    cd /path/to/jre/bin
    
  • Create SSL certificate with keytool command

    ./keytool -genkey -alias [mypassword] -keyalg [RSA]
    

Solution 2

Use

./keytool -genkey -alias mypassword -keyalg RSA

Solution 3

Ensure jre is installed.

cd /path/to/jre/bin/folder

As keytool file is present in the bin folder of jre, give path till bin as in the command above.

Then you can do:

keytool -genkey -alias aliaskeyname -keyalg RSA -keystore C:\mykeystore

The additional option -keystore will help you to specify the path where you want the generated self signed certificate.

Solution 4

find your jre location ::sudo find / -name jre And then :: sudo update-alternatives --install /usr/bin/keytool keytool /opt/jdk/<jdk.verson>/jre/bin/keytool 100

Solution 5

If you are looking for keytool because you are working with Android studio / Google Firebase, there is a keytool bundled with Android Studio. After extracting the zip file, the path to keytool is android-studio/jre/bin.

Share:
233,364
Admin
Author by

Admin

Updated on September 01, 2020

Comments

  • Admin
    Admin almost 4 years

    I have tried to execute keytool from Java bin directory but I get an error with warning bash: keytool: command not found.

    root@xxxxxx]# keytool -genkey -alias mypassword -keyalg RSA
    
    bash: keytools: command not found
    
  • qualebs
    qualebs about 7 years
    @user217929 how can we solve this problem by adding keytool to $PATH so that the command can be executed from any directory?
  • Daniel Gray
    Daniel Gray almost 7 years
    Add export PATH=$PATH:/path/to/jre/bin to your .bashrc file.
  • deva11
    deva11 over 6 years
    Where will be the generated file location?
  • Allie
    Allie over 4 years
    note that the keytool is not in the jre folder, but in the bin folder
  • Moksh
    Moksh over 2 years
    People who are facing this issue inside docker image( I faced it in logstash 7.16.1), can use RUN cd ../.. && find / -iname keytool to find the correct path of it and change it in Dockerfile. Also, these debugging steps will be applicable to cacert file.
  • madebydavid
    madebydavid about 2 years
    alias keytool=$JAVA_HOME/bin/keytool