Contents of page :
- What is a path?
- Why we need to set PATH variable?
- Setting the JDK path >
- 1. To set the environment variables, type in shell >
- 2. You have to source the file you just created by typing >
- 3. Testing whether java is successfully installed >
- Setting JAVA_HOME and JRE_HOME permanently >
In this post we will discuss setting JDK path in Linux and Unix temporarily and permanently, What is a path?Why we need to set PATH variable?
What is a path?
A path is a unique location of a file/ folder in a OS.
PATH variable is also called system variable or environment variable.
Why we need to set PATH variable?
PATH is used to store commands location so that we no need to type complete path in shell to execute the commands.
If Java PATH variable is not set and we type java in cmd>
Error > (java is not recognized as an internal or external command)
If Java PATH variable is set and we type java in cmd>
Success > (java is not recognized as an command)
Setting the JDK path >
Follow these 3 steps >
1. To set the environment variables, type in shell >
echo ‘export JAVA_HOME=/opt/jdk1.7.0_51′ > /etc/profile.d/jdk.sh
echo ‘export PATH=$JAVA_HOME/bin:$PATH’ >> /etc/profile.d/jdk.sh
2. You have to source the file you just created by typing >
3. Testing whether java is successfully installed >
3a) $ java -version
java version “1.7.0_51″
Java(TM) SE Runtime Environment (build 1.7.0_51-b07)
Java HotSpot(TM) Server VM (build jdk 1.7.0_51-b07, mixed mode)
3b) which java command >
$ which java
Setting JAVA_HOME and JRE_HOME permanently >
put the exports directly at the end of the /etc/profile file..
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */