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:

  1. 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
  2. Write the following command in the terminal:
    shell> sudo gedit /etc/environment
  3. Add a line in this file that contains the following (or similar, depending on each environment):
    JAVA_HOME="/usr/lib/jvm/java-7-oracle"
  4. 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 ":".

  5. The /etc/environment file should look like this:
    Time for action – installing JDK and configuring the environment variables
  6. Restart the session.

In Windows environments:

  1. 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.
  2. Click on the Environment Variables... option:
    Time for action – installing JDK and configuring the environment variables
  3. To add the JAVA_HOME system variable, click on the New... button that is found in the System variables section:
    Time for action – installing JDK and configuring the environment variables
  4. 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 FilesJavajdk1.7.0_04, as shown in the following screenshot:
    Time for action – installing JDK and configuring the environment variables
  5. Click on OK to save the changes and exit.
  6. In the System variables section, select the PATH variable and click on the Edit... button.
  7. At the beginning of the value of the PATH variable, add the %JAVA_HOME%in; string.
  8. The separator for PATH entries in the Windows environment is ; as shown in the following screenshot:
    Time for action – installing JDK and configuring the environment variables
  9. Press OK to save changes and exit.
  10. 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset