Normally we download Sun JDK installation binaries and install them. Then we configure the PATH environment variable to point to our JDK installation. But some times there will be conflicts between the native gcj and Sun JDK. So it is always better to install Sun JDK through debian repositories.
But unfortunately, the Debian repositories have Sun JDK in non-free repositories and do not always have the latest JDK.
So this is how we can install the latest JDK natively on Debian.
Steps to be followed:
1. We have to download the JDK or JRE binaries (a .bin file) appropriate for our architecture.
2. Then we have to create a .deb package from the Sun JDK binaries we have downloaded
a.Install java-package which will help us to convert the Sun JDK .bin file to a .deb file installable on Debian.
b. Install fakeroot.
3. Then do as non-root user,
fakeroot make-jpkg <Sun JDK binary filename>
If there is an error like ‘Plugins not found’ or similar errors, it means that the version of the Sun JDK you are trying to install may not be supported by ‘java-package’. Fortunately, there is a work-around for this:
Edit usr/share/java-package/sun-j2sdk.sh like this:
Add the following to that file:
"<Your Sun JDK/JRE bin file name") # SUPPORTED
at the end of the list of similar directives for various versions of JDK/JRE and save the file.
Now repeat step 3 and it will not give the ‘Plugins not found error’ and a .deb package will be created with some warnings which you can ignore safely.
4. Then install the .deb file as a root user by the command:
dpkg -i <generated .deb file name>
5. After the JDK is installed, we have to configure the installed Sun JDK as the default JDK. So we use the following commands:
update-alternatives –config java
This command will show a list of Java installations available (including gcj) and prompt for a choice.
Choose the choice which corresponds to your Sun JDK installation. In my case it was something like this:
Now your Sun JDK installation will be the default JDK. 🙂