5 Ways to fix the “Keytool command not found” error in Linux or Windows

Let’s learn 5 easy ways to fix the Keytool command not found error for different operating systems. To solve Keytool related errors, make sure you have Java (JRE/JDK) installed or PATH is set up correctly. These are the primary reasons for getting above mentioned error. If you will follow this article step by step, you will be able to run the keytool command successfully.

If you are getting any of the below-mentioned errors, this tutorial will help you to fix these errors

  • Keytool: command not found
  • Keytool is not recognised as an internal or external command in Windows
  • Keytool command not working

Keytool error solution map

To make your life easy, I have provided the keytool issues and solution mapping in the following table. So that you can relate to your issue and quickly jump to the solution without wasting your precious time.

IssueSolution reference
Java is not installed in your systemInstall JRE or JDK in your system. For Debian-based Linux like Ubuntu, follow Solution1
Java is installed but PATH is not setup correctlyFor Debian-based Linux like Ubuntu, follow Solution 2 and For Windows follow Solution 3
The Keytool issue in Android studioRead Solution 4 in this tutorial
Keytool error in DockerRead Solution 5

What is Keytool?

Keytool is a key and certificate management tool. It helps you to manage the Keystore (database) of cryptographic keys, X.509 certificate chains, and trusted certificates. In a nutshell, it allows you to do the following tasks –

  1. Allows users to manage their own public/private key pairs and associated certificates
  2. Administer secret keys used in symmetric encryption/decryption (e.g. DES)
  3. Manage data integrity and authentication services e.g

If you want to build an Android APK binary that can be distributed to the play store, You require a keytool to generate a SHA1 fingerprint for your signing certificate. Keytool is also needed when configuring the Firebase SDK for your android or Flutter application.

Why Keytool is not working?

There may be many reasons why Keytool is not working. Below mentioned are a few commonly found

  1. Java (JRE/JDK) is not installed
  2. PATH for keytool is not correctly setup
  3. In the case of Docker, Path is not correct for keytool in Dockerfile
  4. The Java version was wrong
  5. You are typing the command incorrect with space between key and tool.

1. How to fix “keytool command not found error” in Linux

Keytool is part of Java, If you have JDK or at least JRE installation and Java_home setup correctly, then you won’t get Keytool command issues.

Keytool command not found error

If you are getting the command ‘keytool’ not found error, then you first need to check whether Java is installed in your system or not. Follow the instructions step by step to resolve the keytool command issue.

Step1.1 – Run Java -version command to check the Java version installed in your Linux

$ Java -version

The image shows the Java and JRE (Java Runtime Environment) version details.

Check java version in ubuntu

If you have Java installed and running the keytool command is still throwing an error, It means you don’t have $PATH correctly set up for keytool, Just skip to solution 2 for further steps.

If you are getting a Java command not found error, then keep following the next steps.

Step1.2 – If you get Java command not found error. Try searching for the Java installation directory

$ sudo find / -iname java
Find java installation in Linux

If you are still unable to find the Java installation directory. The probability is, that you don’t have Java installed. Go ahead and install JRE or JDK in your system. JRE installation is a minimal requirement.

  • In the case of the Ubuntu operating system, run the following commands to install java –
$ sudo apt update
$ sudo apt install openjdk-18-jre-headless

I am showing an example of JRE version 18. You can install it as per your requirement.

Step1.3 (Optional) – You can replace the OpenJDK-18-jre-headless with the latest version available. To check the latest OpenJDK version in the Ubuntu repository, run the following command

$ sudo apt update
$ sudo apt list openjdk*

Check out my post to install the latest JRE in your Linux or Windows system. It covers all the steps and different JRE installation methods in detail.

2. Setup the PATH for Keytool correctly

Now you know Java is already installed in your system. The keytool command must work perfectly, but in case it doesn’t work, then run the keytool command immediately from the java /bin directory, follow these steps to achieve this.

Step2.1 – Move to JRE/bin directory.

The default path for keytool in my case is /usr/lib/jvm/jdk-18/bin/.

$ cd /usr/lib/jvm/jdk-18/bin

$ ls keytoo*
change to Keytool directory

You can see in the image, that the keytool is available.

Step2.2 – Run keytool directly from the /bin directory

Now we have found the keytool, we can run it directly from here.

$ keytool
Run keytool command from /bin folder

Step3.3 – Setup variable to Keytool to run it globally

To run the “keytool” command globally or from any directory. Add the Java /bin directory to the $PATH.

$ export PATH=$PATH:/path/to/jre/bin

For example in my case, it would be

$ export PATH=$PATH:/usr/lib/jvm/jdk-18/bin/

To make the above entry persistent, so that you don’t lose it in case you close the session. Add it into the .bashrc file or .zshrc file depending upon your shell.

3. How to fix “Keytool is not recognised as an internal or external command in Windows

  • Open the command prompt in Windows and run the keytool command. If you get an error, then as a next step check whether you have Java installed or not.
Error keytool is not recognized as internal or external command, operable program or batch file

Step3.1 – Run Java –version command to check whether you have Java installed or not.

C:\> Java --version
  • If you get output similar to this, you have java installed.
Run java version command from Windows
  • Else you can download it from oracle.com and install it in your Windows operating system like any other software.

if you have Java (JDK or JRE installed) and still keytool is not working, Either you can run the keytool command directly or set up the environment variable to run it globally.

Step3.2 – Run the Keytool command directly from Java /bin folder

To run the keytool command from the folder, check the keytool.exe exist in your Java installation folder i.e. C:\Program Files\Java\jdk1.8.0_66\bin. In your case, the JDK version may be different.

locate keytool.exe in Windows

To run keytool command from bin folder –

  1. Open command prompt
  2. Change directory to C:\Program Files\Java\jdk1.8.0_66\bin.
  3. Run keytool.exe as shown in the image.
Run keytool command in Windows command prompt

Step3.3 – Set the PATH variable permanently (Windows)

  • Search for “Environment variable” in Windows 10
  • Click “Open” on Edit the system environment variable option
open system environment variable
  • Click Advanced, then Environment Variables.

Now add Java installation path till /bin folder in your system variable as shown in the following steps.

  1. Click on “New” to add a new variable
  2. Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable: “C:\Program Files\Java\jdk1.8.0_66\bin” as shown in the image. Replace jdk1.8.0_66 with your JDK version.
  3. Click “OK
  4. Hit “OK” again and close all the open dialogue boxes
Add path to keytool /bin directory

4. Fix the Keytool command issue in Android studio/Google Firebase

Keytool is bundled with Android Studio, just extract the zip and you will find keytool in the android-studio/jre/bin folder.

5. Keytool issue inside Docker image

if you are facing this issue inside the docker image, follow these steps to fix it.

  1. RUN cd ../.. && find / -name keytool to find the correct path, where keytool exists
  2. Now provide this path it in Dockerfile. Also, these debugging steps will be applicable to the cacert file

Summary

I hope you would have been able to fix your keytool command not found error after following this article. The majority of errors are due to either Java is not installed or the path is not correctly set up.

Let me know, in case you still face any issues, and I will try to help you to fix them. If you want to read more on keytool usage with examples, refer to this guide.

Dev

I'm Dev, your friendly neighbourhood Tech Savy. I spend my days with gadgets, servers, and the occasional laugh-inducing software mishap. Think of me as your tech-savvy, glitch-prone buddy. If you've got questions, feedback, or just need someone to blame when your Wi-Fi goes haywire, I'm your guy!