Software & AppsOperating SystemLinux

Fixing ‘Command not found’ Error for Javac Package in Ubuntu Gnome

Ubuntu 1

In the world of Ubuntu Gnome, one of the most common issues that developers face is the ‘Command not found’ error for the Javac package. This error typically arises when the Java Development Kit (JDK) package has not been correctly installed or is missing from the system. This article will guide you through the process of resolving this issue, ensuring that you can compile your Java code smoothly.

Understanding the ‘Command not found’ Error

Before we dive into the solutions, it’s crucial to understand what the ‘Command not found’ error signifies. This error message appears when the system cannot find the ‘javac’ command. The ‘javac’ command is part of the JDK and is used to compile Java source code. If the JDK package is not correctly installed, the ‘javac’ command will be missing, and you will encounter this error.

Solution 1: Installing OpenJDK 7 JDK Package

The first solution involves installing the OpenJDK 7 JDK package. OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). To install this package, you need to run the following command in the terminal:

sudo apt-get install openjdk-7-jdk

In this command, sudo allows you to run commands with the security privileges of the superuser. apt-get is the package handling utility in Ubuntu, and install is the command to install a new package. openjdk-7-jdk is the package that we want to install.

Solution 2: Removing the Incorrect Package

If you have installed the wrong package, you need to remove it before installing the correct one. To do this, you can use the purge command as follows:

sudo apt-get purge java-1.7.0-openjdk-devel

In this command, purge is used to remove a package and its configuration files. After running this command, you can proceed to install the correct package as mentioned in Solution 1.

Solution 3: Checking the ‘javac’ Compiler Location

Another solution is to check if the ‘javac’ compiler is included in the development package. You can do this by running the whereis command:

whereis javac

This command will return the directory where ‘javac’ is located. Once you have this directory, navigate to it using the cd command:

cd <directory>

Then, compile your source code using the following command:

/usr/bin/javac <>

In this command, /usr/bin/javac is the path to the ‘javac’ compiler, and <> is the name of the Java file you want to compile.


The ‘Command not found’ error for the Javac package in Ubuntu Gnome can be a stumbling block for many developers. However, with the solutions provided in this article, you can easily overcome this issue. Remember to check the OpenJDK website for more information on installing Java on your system.

By following these steps, you should be able to resolve the ‘Command not found’ error and continue with your Java development work smoothly. Happy coding!

What is the difference between JDK and JRE?

JDK stands for Java Development Kit, which includes tools for developing and compiling Java applications. JRE stands for Java Runtime Environment, which includes the necessary components to run Java applications. In simpler terms, JDK is used for development, while JRE is used for running Java programs.

How can I check if Java is installed on my Ubuntu Gnome system?

You can check if Java is installed on your Ubuntu Gnome system by running the following command in the terminal: java -version. If Java is installed, it will display the version information. If it is not installed, you will see an error message.

Can I have multiple versions of Java installed on my system?

Yes, you can have multiple versions of Java installed on your system. However, you need to make sure to set the correct version as the default one. You can use the update-alternatives command to manage multiple Java installations and choose the default version.

How can I set the Java version as the default one on my system?

To set the Java version as the default one on your system, you can use the update-alternatives command. Run the following command in the terminal: sudo update-alternatives --config java. This command will display a list of available Java versions. Type the number corresponding to the desired version and press Enter to set it as the default.

Is it necessary to restart the system after installing Java?

In most cases, it is not necessary to restart the system after installing Java. However, if you encounter any issues or if the changes are not taking effect, you can try restarting your system to ensure that all the necessary configurations are applied.

Can I use a different JDK package instead of OpenJDK?

Yes, you can use a different JDK package instead of OpenJDK. OpenJDK is a popular choice, but there are other options available, such as Oracle JDK. The installation process might vary depending on the package you choose, so make sure to follow the specific instructions provided by the package provider.

Leave a Comment

Your email address will not be published. Required fields are marked *