Is ‘java’ Not Recognized As An Internal Or External Command In Java?

The error message you are seeing indicates that the java command is not recognized in your system’s command prompt or terminal. This error commonly occurs when the Java Development Kit (JDK) is not properly installed or the system’s environment variables are not configured correctly.

To resolve this issue, you should follow these steps:

  1. Make sure you have the Java Development Kit (JDK) installed on your computer. You can download the latest JDK from the official Oracle website: https://www.oracle.com/java/technologies/javase-jdk11-downloads.html

  2. Once the JDK is installed, open a new command prompt or terminal window.

  3. Check the JAVA_HOME environment variable. This variable should point to the root directory of your JDK installation. You can do this by typing echo %JAVA_HOME% in the command prompt or terminal window. If nothing is printed or the path is incorrect, you need to set the JAVA_HOME environment variable. The steps for setting the JAVA_HOME variable depend on your operating system.

  • For Windows:

    • Open the System Properties window by right-clicking on the Computer icon and selecting Properties.
    • Click on the "Advanced system settings" link on the left side of the window.
    • In the System Properties window, click on the "Environment Variables" button.
    • In the Environment Variables window, under "System variables", click on the "New" button.
    • Enter JAVA_HOME as the variable name and the path to your JDK installation as the variable value (e.g., C:\Program Files\Java\jdk-11.0.9).
    • Click "OK" to save the changes.
  • For macOS or Linux:

    • Open a terminal window.
    • Type sudo nano /etc/environment and press Enter.
    • Enter your password if prompted.
    • At the end of the file, add a new line with JAVA_HOME=/path/to/your/jdk. Replace /path/to/your/jdk with the actual path to your JDK installation.
    • Press Ctrl+X, then Y, and finally Enter to save the file.
  1. After setting the JAVA_HOME environment variable, close and reopen the command prompt or terminal window.

  2. Test the java command by typing java -version in the command prompt or terminal. It should print the Java version information without any error.

If you still encounter issues, verify that the java executable is located in the bin directory of your JDK installation and that the bin directory is included in the system’s PATH environment variable.

About the Author Rex

I'm a passionate tech blogger with an insatiable love for programming! From my early days tinkering with code, I've delved into web dev, mobile apps, and AI. Sharing insights and tutorials with the world is my joy, connecting me to a global community of like-minded tech enthusiasts. Python holds a special place in my heart, but I embrace all challenges. Constantly learning, I attend tech conferences, contribute to open-source projects, and engage in code review sessions. My ultimate goal is to inspire the next generation of developers and contribute positively to the ever-evolving tech landscape. Let's code together!