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
Table of Contents
- 1 Keytool error - solution map
- 2 What is Keytool?
- 3 Why Keytool is not working?
- 4 1. How to fix "keytool command not found error" in Linux
- 5 2. Setup the PATH for Keytool correctly
- 6 3. How to fix "Keytool is not recognised as an internal or external command in Windows"
- 7 4. Fix the Keytool command issue in Android studio/Google Firebase
- 8 5. Keytool issue inside Docker image
- 9 Summary
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.
|Java is not installed in your system||Install JRE or JDK in your system. For Debian-based Linux like Ubuntu, follow Solution1|
|Java is installed but PATH is not setup correctly||For Debian-based Linux like Ubuntu, follow Solution 2 and For Windows follow Solution 3|
|The Keytool issue in Android studio||Read Solution 4 in this tutorial|
|Keytool error in Docker||Read 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 -
- Allows users to manage their own public/private key pairs and associated certificates
- Administer secret keys used in symmetric encryption/decryption (e.g. DES)
- 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
- Java (JRE/JDK) is not installed
- PATH for keytool is not correctly setup
- In the case of Docker, Path is not correct for keytool in Dockerfile
- The Java version was wrong
- 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.
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.
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
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*
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.
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
keytoolcommand. If you get an error, then as a next step check whether you have Java installed or not.
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.
- 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.
To run keytool command from bin folder -
- Open command prompt
- Change directory to
- Run keytool.exe as shown in the image.
Step3.3 - Set the
PATH variable permanently (Windows)
- Search for "Environment variable" in Windows 10
- Click "Open" on Edit the system environment variable option
- Click Advanced, then Environment Variables.
Now add Java installation path till /bin folder in your system variable as shown in the following steps.
- Click on "New" to add a new variable
- 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.
- Click "OK"
- Hit "OK" again and close all the open dialogue boxes
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.
RUN cd ../.. && find / -name keytoolto find the correct path, where keytool exists
- Now provide this path it in Dockerfile. Also, these debugging steps will be applicable to the cacert file
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.