How to Set Java Path in Windows and Linux?
Last Updated :
17 May, 2024
PATH is an environment variable that is used by Operating System to locate the exe files (.exe) or java binaries ( java or javac command). The path once it is set, cannot be overridden. The PATH variable prevents us from having to write out the entire path to a program on the Command Line Interface every time we run it. Moreover, the path is just a variable that stores a bunch of shortcuts.
To execute Java console-based programs in Windows or Linux environments, we have to use Java and javac commands. The commands java and javac are not known to the operating system as we don't specify where the executables reside. Hence, we need to specify the path where the executables are located. This is the reason we set the path and specify the path of the bin folder because the bin contains all binary executable files. After setting the path, it can load all necessary items in the program including the compiler or interpreter itself.
Below is the procedure for how to set Java Path in both Windows and Linux?
To Set Java Path in Windows
Step 1: Go to the Search box and type Advanced System settings in it. Now click on the View Advanced System settings.

Step 2: Select the Advanced tab and then click environment variables.

Step 3: In the system, variables click the New button. Now in the edit System variable, type variable name as JAVA_HOME and variable path as the path where the JDK folder is saved and click on OK button Usually the path of the JDK file will be C:\Program Files\Java\jdk1.8.0_60.

Step 4: Now in the system variables go to the path and click the Edit button.

Step 5: Click the New button.

Step 6: Now add the following path: %JAVA_HOME%\bin

To Find Java Path in Windows:
Here are the simple steps to find your Java path in Windows:
Step 1: Open a Command Prompt window.
Type the following command and press Enter:
where java
Step 2: You should see the path to your Java installation printed in the Command Prompt. It will typically look something like this:
C:\Program Files\Java\jdk1.8.0_291\bin\java.exe
That's it! You've found your Java path in Windows.
To Set Java Path in Linux
Follow the given steps to set Java Path in Linux -
- Open the terminal and enter the following command:
sudo nano /etc/environment.
- A file will be opened and add the following command to that file:
JAVA_HOME = "YOUR_PATH".
- Replace YOUR_PATH with the JDK bin file path.
- Now restart your computer or virtual machine that you are using (or) reload the file: source /etc/environment
- You can test the path by executing
echo $JAVA_HOME
- If you get the output without any error, then you've set the path correctly.
- If you get any errors, try repeating the procedure again.
To Find Java Path in Linux:
Here are the steps to find Java Path in Linux System -
Step 1: Open a Terminal window.
Step 2: Type the following command and press Enter:
which java
Step 3: You should see the path to your Java installation printed on the terminal. It will typically look something like this:
/usr/bin/java
That's it! You've found your Java path in Linux.
Conclusion
So, this was all about how you can find and set Java path in Windows and Linux. If you also have other queries regarding setting Java Path, Java_Home variable and default Java path, You can also refer to the following frequently asked questions.
Similar Reads
How to Install Java on Windows, Linux and macOS?
Java is a versatile programming language widely used for building applications. To start coding in Java, you first need to install the Java Development Kit (JDK) on your system. This article provides detailed steps for installing Java on Windows 7, 8, 10, 11, Linux Ubuntu, and macOS.Download and Ins
5 min read
How to Set Java SDK Path in Android Studio?
The Java SDK for Android is a sophisticated suite of tools for managing, monitoring, profiling, and debugging Java code written in Android Studio. But sometimes as software is unpredictable you might be caught in an error that Android Studio stopped compiling projects and says that it can't locate t
4 min read
How to Fix npm path in Windows 8 and 10 ?
Node Package Manager (npm) is a package manager for managing dependencies and packages in Node.js projects. However, users often encounter issues with npm commands not being recognized in Windows 8 and 10 due to path configuration problems. In this article, we'll discuss the following approaches to
2 min read
How to Setup Sublime Text 3 for Java in Windows?
Java is one of the most popular and widely-used object-oriented programming languages. Java syntax is similar to C/C++. But Java does not provide low-level programming functionalities like pointers. Also, Java codes are always written in the form of classes and objects. The Java codes are first comp
2 min read
How to add Python to Windows PATH?
Python is a great language! However, it doesnât come pre-installed with Windows. Hence we download it to interpret the Python code that we write. But wait, windows donât know where you have installed the Python so when trying to any Python code, you will get an error. We will be using Windows 10 and
2 min read
How to Install Apache Maven on Windows, macOS, and Linux?
Apache Maven is a comprehensive build automation tool widely used for managing and building Java projects. It simplifies the process of managing project dependencies and building projects through a standardized approach. This article provides step-by-step instructions to install Apache Maven on Wind
4 min read
How to Update the Java Version in Windows?
Java is a high-level, robust, object-oriented, and secure programming language that was developed in the year 1995 by Sun Microsystems (which is now part of Oracle group), and James Gosling is known as the father of Java. Â It is a general-purpose programming language intended to let programmers writ
4 min read
How to Install Jmespath in Python in Windows?
Jmespath is known as the JSON query language for Python. It is used to get the required data from the JSON document or dictionary easily. This library is available for Python as well as other programming languages so you can use it in many places according to the need. In this article, we will be lo
2 min read
How to set Temporary and Permanent Paths in Java
In Java, the most important task is to set the environment variable on the system. If the Java source file is inside the jdk/bin folder, the path is not required to be set because tools like javac, and java can be accessed globally on the system. If the Java source file is outside the jdk/bin folder
3 min read
How to Use Linux Commands in Windows with Cygwin
Cygwin is a collection of tools that provide a Linux Operating System's terminal look, feel, and some of its basic functionality for users of Windows OS who want to have a go over the basic commands of Linux without worrying about installing a Linux OS. To use this tool, first of all, we need to dow
3 min read