How to Install Java on Linux

Jun 27, 2012, by admin

Install-Java-on-LinuxJava allows you run cross-platform applications that can run on Mac OS-X, Linux, and Windows (among other OSs) without modification. Here’s how to install it on a GNU/Linux machine.

linux

Steps

How to Install Java on Linux via Manual Non-RPM Method

This is the generic way that also works with GNU/Linux clones that do not support RPM. It does not need administrator rights and allows installing multiple Java versions on the same computer.

1.Download the JDK

Click on the “Download” link under Java Platform (JDK) 7u4.

Accept the license and continue.

2.Select the right download. Under the “Product/File Description” you should pick your corresponding Linux option. For example, if you’re running Linux x86 (32-bit), you need to choose the corresponding “*.tar.gz” version.

Install-Java-on-Linux-13.Download the file as a .gz. Save it to your GNU/Linux machine.

4.Switch to the directory where you saved the file. You do not need to be a root and only must have the write access to the folder where you wish to install Java. If your administrator is not supportive, you may need to place Java into your home folder or (even better) on some shared network location

5.Uncompress the file. For example, you could do this in your home folder. Uncompressing will create a folder called “jdk1.7.0_04”. Java is now installed.

The installed Java jre is rather independent and can be easily moved into another place just by copying all its files.

You can install multiple different jre’s this way: they coexist together and can be used if some software requires the older version to run.

6.Launch Java. The Java executable you need to launch is located in a subfolder, called “bin.” This way of installation will not configure a default Java command for you — you must do this manually or always include the full path in your startup script.

How to Install Java on Linux via Manual RPM Method

This seems like a “more civilized” method to install Java because it allows the installer to check the dependencies on some system libraries that may be missing. However, it does not support versioning simply and may fail even in some systems that do support RPMs. (Though the current Java installations are rather self-dependent and the required minimal requirements are usually satisfied anyway.)

1.Download the JDK.

Click on the “Download” link under Java Platform (JDK) 7u4.

Accept the license and continue.

2.Select the right download. Under the “Product/File Description” you should pick your corresponding Linux option. For example, if you’re running Linux x86 (32-bit), you need to choose the corresponding “*.rpm” version, for example “jdk-7u4-linux-i586.rpm”.

Install-Java-on-Linux-23.Download the .rpm file. Save it to your GNU/Linux machine.

4.Log in as root and switch to the directory where you saved the file. Or, become root by running su and entering the super-user password.

5.Install the rpm file by executing ‘rpm -ivh filename.rpm’, where filename is the name of your .rpm file. (Such as jdk-7u4-linux-i586.rpm).

You may receive a message telling that program “rpm” is not installed.

If that is the case the program “rpm” is not installed. You need to install it writing: sudo apt-get install rpm. Enter your password, and you’re finished.

6.Create symbolic links. If you want to be able to implement this version of Java interpretor or compiler from any directory on your GNU/Linux system, you will have to create a few symbolic links:

sudo ln -s -v jdk1.7.0_04/bin/java /usr/bin/java

sudo ln -s -v jdk1.7.0_04/bin/javac /usr/bin/javac

Note that by installing using this method there could be dependencies that fail. It is better to use the package installer that handles all dependencies for you, since you will not be able to use Java correctly until the dependencies are resolved.

How to Install Java on Linux via Ubuntu Method Using a GUI Package Manager

1.Open a package manager. You can use Synaptic or Adept Manager.

2.Install Open JDK. Java JDK and JRE are not available for installation through GUI Package Manager. You’ll need to install Open JDK instead.

Perform a search for openjdk-7-jdk.

Select openjdk-7-jdk for installation. Depending on the package manager, you may be asked if you wish to install the required dependencies or it will automatically select them without confirmation. For example, the openjdk-7-jre was already selected by Synaptic Package Manager. If you want to use Java as a plug-in in your browser, then also select to install icedtea-7-plugin.

3.Apply the changes. Click the button to apply the changes. Depending on the package manager, a pop-up window may appear asking for you to confirm the changes.

4.Wait for Java to install.

How to Install Java on Linux via Ubuntu Method Using a Console

1.Enter one of the following commands into your console program:

sudo apt-get install openjdk-7-jdk openjdk-7-jre (if you don’t want the browser plug-in)

sudo apt-get install openjdk-7-jdk openjdk-7-jre icedtea-7-plugin (if you do need the plug-in)

apt-get automatically takes care of the dependencies and lists the changes for confirmation.

2.Enter y to confirm the installation.

How to Install Java on Linux via Ubuntu OpenJDK Method Using a Console

1.Ubuntu no longer supports the Sun Java package in favor of OpenJDK.

2.Enter one of the following into your console program:

If you do not want the browser plugin, sudo apt-get install openjdk-6-jre.

If you do want the browser plugin, sudo apt-get install openjdk-6-jre icedtea6-plugin

If you’re working on a server without graphics, and want an environment just for running server applications (e.e. Tomcat or Glassfish), sudo apt-get install –no-install-recommends openjdk-6-jre-headless

If you need the full JDK (for writing Java programs): sudo apt-get install openjdk-6-jdk

apt-get automatically takes care of the dependencies and lists the changes for confirmation.

3Enter y to confirm the installation.