Time for action – installing JDK and configuring the environment variables
To configure the JAVA_HOME
and PATH
variables, follow these steps:
Installing on a LINUX environment:
- Install JDK 1.7. You can go to the official Java website (www.java.com), download the installer file and then execute it in your operating system. Or you can execute the following commands in a terminal:
shell> sudo add-apt-repository ppa:webupd8team/java shell> sudo apt-get update shell> sudo apt-get install oracle-java7-installer
- Write the following command in the terminal:
shell> sudo gedit /etc/environment
- Add a line in this file that contains the following (or similar, depending on each environment):
JAVA_HOME="/usr/lib/jvm/java-7-oracle"
- To the beginning of the value of the
PATH
variable, add the/usr/lib/jvm/java-7-oracle/bin:
string.Note
The separator for the
PATH
entries in Linux environments is ":"
. - The
/etc/environment
file should look like this: - Restart the session.
In Windows environments:
- Install JDK 1.7. Go to the official Java website (www.java.com), download the installer file, and then execute it in your operating system.
- Click on the Environment Variables... option:
- To add the
JAVA_HOME
system variable, click on the New... button that is found in the System variables section: - This action will open a new window, where we must fill in the following values:
- In Variable name:, type
JAVA_HOME
. - In Variable value:, type the path that corresponds to the JDK installation. For example, add a system variable with the name
JAVA_HOME
and complete its value with the corresponding path, say, C:\Program Files\Java\jdk1.7.0_04, as shown in the following screenshot:
- In Variable name:, type
- Click on OK to save the changes and exit.
- In the System variables section, select the
PATH
variable and click on the Edit... button. - At the beginning of the value of the
PATH
variable, add the%JAVA_HOME%\bin;
string. - The separator for
PATH
entries in the Windows environment is ; as shown in the following screenshot: - Press OK to save changes and exit.
- Restart your computer.
To confirm the correct installation in Linux as well as in Windows, we can execute the following command in a terminal:
shell> java -version
We should obtain a result similar to the following:
java version "1.7.0_04" Java(TM) SE Runtime Environment (build 1.7.0_04-b20) Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)
Note
In 2009, Oracle acquired Sun Microsystems, which gave Oracle Java technology the MySQL RDBMS and the Solaris operating system. This is why in Linux environments, the package corresponding to Java Version 1.6 is called sun-java6-jdk
, and in Version 1.7, it's called oracle-java7-installer
.
What just happened?
We installed JDK and configured the JAVA_HOME
and PATH
environment variables. Configuration was performed for both the Linux and Windows operating systems. We defined the JAVA_HOME
environment variable that points to a local Java installation. We also added the Java bin
directory to the PATH
variable so that we can call Java from anywhere.