How To Install ORACLE Java JDK On Linux
Java Applets are useful on a web page or web site to do things which may not be possible using HTML or Javascript (but keep in mind that not all computers include a Java environment). To build Java applets, you need a Java Compiler (javac), and to compress the applet(s) into a nice neat package, you also need a Java Archiver (jar).
These instructions show you how to install ORACLE's JDK (Java Development Kit) so that you can use it even if your favorite Linux Distro already comes with an existing Java compiler (This makes it possible to keep your distro Java and your development Java separate).
If your Linux Distro already includes a Java compiler and you have no interest in installing or using the ORACLE compiler, then you can skip this web page.
The following 3 example pages show you how you can make Java Applets on the command line or by using scripts.
DOWNLOAD THE ORACLE JDK (JAVA DEVELOPMENT KIT)
To begin, you need to get the JDK package and download it to your Desktop. Just go to the Java JDK website and select the latest JDK.
NOTE: You will notice on the download web page that there are various package versions for Linux. Even if your Linux Distro is capable of using special packages, such as RPM or deb, this How-To uses the simplest method which allows you to have more control over the placement location so that it does not conflict with your existing setup if you have one already. You will want to download the version that ends in .tar.gz
INSTALL THE JDK
Version 7 of the JDK is a simple package to install. Just find a package that ends in .tar.gz. The older 6 JDK packages were wrapped with a binary license and the package ended in .bin. If you are installing the older .bin JDK, then you may want to use these instructions instead.
The following steps assume you downloaded the JDK to your "~/Desktop" and that you want to place the JDK (Java Development Kit) in your "~" (home directory). If you want to place it elsewhere, please modify the appropriate steps to fit your choice.
1.
2.
3.
4.
5.
6. |
|
[you@genesis ~]$ cd ~
[you@genesis ~]$ ls -l ~/Desktop/jdk*
-rw-r--r-- 1 you you 96645974 2011-10-08 12:00 jdk-7-linux-i586.tar.gz
[you@genesis ~]$ tar -xzf ~/Desktop/jdk-7-linux-i586.tar.gz
[you@genesis ~]$ ls -l
drwxr-xr-x 2 you you 97 2011-10-08 12:00 Desktop/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 Documents/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 Download/
drwxr-xr-x 10 you you 424 2011-06-27 02:02 jdk1.7.0/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 Music/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 Pictures/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 temp/
drwx------ 5 you you 54 2011-10-08 12:00 tmp/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 Pictures/
drwxr-xr-x 2 you you 6 2011-10-08 12:00 Videos/
[you@genesis ~]$ rm -f ~/Desktop/jdk-7-linux-i586.tar.gz
[you@genesis ~]$ exit[you@genesis ~]$ |
|
- cd ~ - Change to the directory where you will hold your JDK. This How-To uses "~" (your home directory).
- ls -l ~/Desktop/jdk* - This is optional. Check the location and name of the JDK you downloaded. The "*" (wildcard) saves on typing and possible spelling errors.
- tar -xzf ~/Desktop/jdk-7-linux-i586.tar.gz - The ORACLE JDK (Java Development Kit) is much simpler to install compared to the older version 6 JDKs. Just untar the directories into a usable location. For this example, we chose your "~" home directory.
- ls -l - Optional step. Display the new JDK Compiler directory. It should display you as owner to the directory and files within the JDK directory.
- rm -f ~/Desktop/jdk-7-linux-i586.tar.gz - Cleanup. Remove the JDK you downloaded earlier.
- exit - You are done installing the JDK.
The next step is "MAKE SCRIPTS TO COMPILE YOUR JAVA.
INSTALL THE (OLDER) JDK
If you installed the newer version of JDK that is packaged as a .tar.gz file, you can skip these steps and go down to "MAKE SCRIPTS TO COMPILE YOUR JAVA. The following steps assume you downloaded the older version of JDK to your "~/Desktop" and that you want to place the JDK (Java Development Kit) in your "~" (home directory). If you want to place it elsewhere, please modify the appropriate steps to fit your choice.
1.
2.
3.
|
|
[you@genesis ~]$ cd ~
[you@genesis ~]$ ls -l ~/Desktop/jdk*
-rw-r--r-- 1 you you 78482905 2008-08-08 12:00 jdk-6u7-linux-i586.bin
[you@genesis ~]$ sh ~/Desktop/jdk-6u7-linux-i586.bin
Sun Microsystems, Inc. Binary Code License Agreement
for the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6
SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE
SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION
THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARY
CODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE TERMS
(COLLECTIVELY "AGREEMENT"). PLEASE READ THE AGREEMENT
CAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOU
ACCEPT THE TERMS OF THE AGREEMENT. INDICATE ACCEPTANCE BY
SELECTING THE "ACCEPT" BUTTON AT THE BOTTOM OF THE
AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY ALL THE
TERMS, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THE
AGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL NOT
CONTINUE.
1. DEFINITIONS. "Software" means the identified above in
binary form, any other machine readable materials
(including, but not limited to, libraries, source files,
header files, and data files), any updates or error
corrections provided by Sun, and any user manuals,
programming guides and other documentation provided to you
--More-- |
|
- cd ~ - Change to the directory where you will hold your JDK. This How-To uses "~" (your home directory).
- ls -l ~/Desktop/jdk* - This is optional. Check the location and name of the JDK you downloaded.
- sh ~/Desktop/jdk-6u7-linux-i586.bin - The SUN JDK (Java Development Kit) is wrapped within an EULA (End User License Agreement) before you can expand it. Run the script to see, read, and agree with the EULA before you can expand the JDK into your "~" directory. You need to press the SPACE BAR or ENTER keys to read through the EULA, then answer yes or no before it continues.
CLEANUP
When you reach the end of the EULA (End User License Agreement), the JDK is expanded into "~" and you can then cleanup by removing the downloaded file.
1.
2.
3. |
|
[you@genesis ~]$ ls -l
drwxr-xr-x 2 you you 97 2008-08-08 12:00 Desktop/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 Documents/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 Download/
drwxr-xr-x 10 you you 4096 2008-08-08 12:00 jdk1.6.0_07/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 Music/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 Pictures/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 temp/
drwx------ 5 you you 54 2008-08-08 12:00 tmp/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 Pictures/
drwxr-xr-x 2 you you 6 2008-08-08 12:00 Videos/
[you@genesis ~]$ rm -f ~/Desktop/jdk-6u7-linux-i586.bin
[you@genesis ~]$ exit |
|
- ls -l - Optional step. Display the new JDK Compiler directory.
- rm -f ~/Desktop/jdk-6u7-linux-i586.bin - Cleanup. Remove the JDK you downloaded earlier.
- exit - You are done installing the JDK.
MAKE SCRIPTS TO COMPILE YOUR JAVA
As you can see above, not many steps were used to install the JDK. This allows you to use the JDK even if your Linux install already comes with a Java Compiler.
If your Linux Distro already has an existing Java Compiler and you want to build Java applets using the compiler that came with your Linux Distribution, then follow the steps shown on the following example pages.
If you want to build Java applets using the JDK, then you need to also insert 3 additional "export" lines and use scripts only because you need the exported information. The example shown below shows you the clock script with the additional "export" information required to compile Java programs. Please modify the "export" info to match your choice of JDK toolkit location and the version you downloaded.
#!/bin/sh
export JAVA_HOME=/home/you/jdk1.7.0 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=$CLASSPATH:.
cd ~/temp # Create compiled code from java file. javac -deprecation clock.java
# Create compressed jar archive from compiled file. jar cvf clock.jar clock.class
# Cleanup results; clock.class not needed. rm -f clock.class
# Show results ls -l clock.* |
ADDING JAVA TO YOUR BROWSER
Some web browsers, such as Konqueror, allow you to specify where to search for Java if you want to use ORACLE's Java instead of the Java that came with your Distro. If that is what you want, you can point your browser's options to use the Java inside the JDK, but you should also modify the user's PATH to include this Java instead of the built-in one which may come with the distro. For this example How-To this would be "/home/you/jdk1.7.0/java" (NOTE: your home directory location is specified in full instead of using the "~" shortcut).
INSTALL THE JDK FOR MULTIPLE USERS
The steps given above show you how to install Java for one single user. If you prefer to install Java for use by multiple users, you need to put the JDK in a place that is accessible to multiple users, such as directory "/opt".
These steps assume you downloaded the JDK to your "~/Desktop" and that you want to place the JDK (Java Development Kit) in directory "/opt".
1.
2.
3.
4.
5.
6.
7.
8.
9. |
|
[you@genesis ~]$ cd /opt
[you@genesis opt]$ ls -l ~/Desktop/jdk*
-rw-r--r-- 1 you you 96645974 2011-10-08 12:00 jdk-7-linux-i586.tar.gz
[you@genesis opt]$ su
Password: ********
[root@genesis opt]$ tar -xzf /home/you/Desktop/jdk-7-linux-i586.tar.gz
[root@genesis opt]$ chown root:root -R /opt/jdk1.7.0*
[root@genesis opt]$ exit
[you@genesis opt]$ ls -l
drwxr-xr-x 10 root root 4096 2011-06-27 02:02 jdk1.7.0/
[you@genesis opt]$ rm -f ~/Desktop/jdk-7-linux-i586.tar.gz
[you@genesis opt]$ exit |
|
- cd /opt - Change to the directory where you will hold your JDK.
- ls -l ~/Desktop/jdk* - This is optional. Check the location and name of the JDK you downloaded. The "*" (wildcard) saves on typing and possible spelling errors.
- su - The following command needs to be done in Super User mode. You will need the su password too.
- tar -xzf /home/you/Desktop/jdk-7-linux-i586.tar.gz - Just untar the directories into a usable location. For this example, we use "/opt".
NOTE: You will need to specify your home directory in the path.
- chown root:root -R /opt/jdk1.7.0* - Change the owner to root, and the group ownership to root for all files and sub directories. If you are running an enterprise system that has limited access for security purposes, you will probably change group to a developer group and then remove all other permissions, but for most desktop developers, this is enough as long as other is allowed access too.
- exit - When you finish, exit root super user and return to user you.
- ls -l - Optional step. Display the new JDK Compiler directory. It should display root as owner to the directory and files within the JDK directory.
- rm -f ~/Desktop/jdk-7-linux-i586.tar.gz - Cleanup. Remove the JDK you downloaded earlier.
- exit - You are done installing the JDK.