Java offline installer – How to install Java in Linux
In this tutorial we will show you how to install the latest Java version in a Linux machine, using the Java offline installer. The Java offline installer is an executable file that contains all necessary files required for a complete installation.
An internet connection is required, in order for the offline installer to be downloaded. Once the installer is downloaded, the computer does not need to remain connected to the Internet. Also, the downloaded installer can be copied to another computer, which it doesn’t have access to the Internet.
This tutorial applies to Ubuntu, Red Hat Linux, SUSE Linux, Oracle Linux and Fedora platforms and also, to Java 6.0 and 7.0 versions.
1. Install Java in Ubuntu
There are several Java implementations that can be installed in Ubuntu. In this tutorial, we will discuss about the following:
- OpenJDK: OpenJDK aims for providing an open-source implementation of the Java SE Platform, both 6.0 and 7.0. This is the default version of Java that Ubuntu uses.
- Oracle Java 7: Oracle Java 7 is Oracle’s own version of Java 7.0.
OpenJDK-6
In order to install the Java Runtime Environment (JRE), we must issue the following command:
sudo apt-get install openjdk-6-jre
Also, we need to install the IcedTea Web plugin, in order for Java applets to be executed, using the command:
sudo apt-get install icedtea6-plugin
Finally, in order to write and develop Java programs, we need the Java Development Kit (JDK). We can install it by executing the command:
sudo apt-get install openjdk-6-jdk
Notice that the installation of JDK includes the installation of JRE.
OpenJDK-7
In order to install the Java Runtime Environment (JRE), we must issue the following command:
sudo apt-get install openjdk-7-jre
Also, we need to install the IcedTea Web plugin, in order for Java applets to be executed, using the command:
sudo apt-get install icedtea7-plugin
Finally, in order to write and develop Java programs, we need the Java Development Kit (JDK). We can install it by executing the command:
sudo apt-get install openjdk-7-jdk
Notice that the installation of JDK includes the installation of JRE.
Oracle Java 7
Currently, there are no .deb packages available for Oracle Java 7. You can download the raw binaries from the Oracle’s official download page here. Then, to install Oracle Java in your system, follow the steps described in the following sections.
Multiple Java versions
In case you have installed multiple Java versions, you can choose the default Java version of your system, using the command:
sudo update-alternatives --config java
2. Install Java in other Linux platforms
Download Java
- First of all, you must visit the manual download page here.
- As you can observe, there are two types of installation packages:
Java for Linux Platforms:
Both Linux and Linux_x64 are tar.gz binary files that can be installed in any location of your system, provided that you have the appropriate write permissions. For example, you must be a root user to install Java in a system’s directory.
Java for RPM-based Linux Platforms:
The RPM-based Linux platforms, such as Red hat, use .rpm binary files, in order to package their software. Notice, that in order to install such a binary package, you need root privileges.
Choose the appropriate file based on your Linux platform and click on the version that corresponds to your machine’s architecture, either 32-bit or 64-bit.
- In the appearing dialog box, choose
Save File
and clickOK
, in order to download the file to your local system. - Close all running applications, including the web browser.
Install Java
Once the download procedure is complete, we are ready to install Java in our local machine. The following instructions refer to the latest version of Java, 7u45
, in a 32-bit system. In case you are installing a different version, all you have to do is change the version number appropriately.
Install Java in Linux Platforms
First of all, we must navigate to the folder where Java is about to be installed. Open a terminal and issue the following command:
cd <directory_path>
A sample installation directory for Java is /usr/java
.
Important: To install Java in a system’s directory, you must login as a user with root privileges. In case your user account does not have the required write permissions, install Java in your home directory or in a directory where you have write permissions.
Move the downloaded archive binary from the Downloads folder to the current folder, using the following command:
mv ~/Downloads/<Java archive> ./
Once the downloaded archive is moved to the installation folder, all we have to do is unpack it using the command:
tar zxvf jre-7u45-linux-i586.tar.gz
All extracted files are installed in a newly created directory called jre1.7.0_45
.
Finally, in order to save some disk space, delete the archive file by issuing the following command:
rm jre-7u45-linux-i586.tar.gz
Install Java in RPM-based Linux Platforms
First of all, we must become a root user, in order to proceed with the installation. Open a terminal, issue the command su
and enter the root password.
Remove any earlier installations of Java packages using the following command:
rpm -e <package_name>
Navigate to the folder where Java is about to be installed:
cd <directory_path>
A sample installation directory for Java is /usr/java
.
Once, you are inside the installation folder, install the package using the command:
rpm -ivh jre-7u45-linux-i586.rpm
or upgrade the package issuing the command:
rpm -Uvh jre-7u45-linux-i586.rpm
In order to save some disk space, delete the .rpm file by issuing the following command:
rm jre-7u45-linux-i586.rpm
Finally, exit the root shell to end the installation procedure.
This was a tutorial on how to install Java in Linux.