We need to install Java and add JAVA_HOME in the Operating System user environment variable to work with software like Maven, Jenkins, React Native, Gradle, Tomcat and develop mobile apps with SDK. The path is required to be set for using tools such as javac, java, etc. If you have Java file outside the JDK/bin folder, it is necessary to set the path of JDK.
If you keep the Java source file inside the JDK/bin directory, the path is not required to be set because all the tools will be available in the current directory.
In this article, we going to share simple steps to add the Java JAVA_HOME environment variable in Windows, Linux, and Mac. First of all, download JDK of Java from the official link for your Operating System.
Temporary in Window
To set the temporary path of JDK, you need to follow the following steps:
- Open the command prompt
- Copy the path of the JDK/bin directory
- Write in command prompt: set path=copied_path
For Example:
set path=C:\Program Files\Java\jdk1.6.0_23\bin
Permanent in Window
For setting the permanent path of JDK, you need to follow these steps:
1. Go to My Computer properties.
4. Click on the new tab of the user variable.
Java Path In Mac
Here, we going to share Java installation and add JAVA_HOME in the Mac machine.
1. Open terminal to check Java install or not. Run java -version command to check it.
If above window open. It's means Java not install in your Mac machine. So, click on OK button. It will open official Java download web page to download it.
2. After that complete installation and you can delete (Click on Move to Trash button) pkg file from the system if the installation completed. Now you can check Java install or not with help of the above-given command (java -version). You will see the version of installed Java.
- Start the Terminal.
- Type cd ~/ to go t your home folder.
- Type touch .base_profile to create your new file.
- Type source .base_profile to reload and update it.
- Go to user folder and press ⌘ + Shift + . from the keyboard. You will see all hidden files of the system. So, simply find .base_profile and double click to open it
- You can open it vim ~/ .base_profile command.
Tips for Mac machine path setup
- Go to user folder and press ⌘ + Shift + . from the keyboard. You will see all hidden files of the system. So, simply find the .zshrc file and double-click to open it
Setting Java Path in Linux
Setting path in Linux OS is the same as setting the path in the Windows OS. But, here we use the export tool rather than set. Let's see how to set path in Linux OS:
export PATH=$PATH:/home/jdk1.6.01/bin/
Conclusion
I hope the approach shown in this post have been helpful to setup the environment variable of Java JDK and if you are facing any problem to implement it and you have any quires, please feel free to ask it from comment section below.