Installing Java on Ubuntu

This article explains the steps to install the Java software bundle on Ubuntu 12.04.

Blue Light Tech

Java

Java is a software platform to develop and deploy programs and applications in a computing environment.

Java Development Kit (JDK) is a set of Java resources to develop Java application developments. JDK is provided by Oracle. OpenJDK is the open-source version of the kit.

Java Runtime Environment (JRE) is a part of the JDK and can be downloaded separately. JRE is required if you need to run the Java-based applications.

Ubuntu

Ubuntu is a Linux-based operating system and uses the Unity desktop. Ubuntu has a Package Manager, apt . The package manager maintains most of the software required for Ubuntu. You can download the latest Java packages using apt .

Prerequisites

The prerequisite to successfully install Java on Ubuntu 12.04 is a non-root user account to perform the installation.

Setting up Non-Root User Account

Root user has higher privileges and permissions which this installation does not require. To reduce the chances of risk which may come with unwanted permissions, a non-root user with some root privileges is used for the installation.

To create a non-root user for the installation, perform the following:

  1. Open the terminal and log in as root user on Ubuntu server.
  2. Type the command
    adduser <username>

    Replace <username> with a name for the user. For example – tester .
  3. Type a password for the user.
  4. Retype the password.

The following figure shows the password being updated for the new user.

  1. Type answers for the questions that appear on the terminal.
    These questions are optional and default responses can be accepted by pressing the Enter
    The system asks for confirmation on the information provided.
  2. Press y to confirm the information.
  3. To add the user to the sudo group, run the command
    gpasswd –a <username> sudo

    Replace <username> with a name for the user. User is successfully added to the sudo group.

Installing Java

Java installation comprises the following tasks:

  1. Installing default JRE
  2. Installing default JDK
  3. Installing Oracle JDK (Optional)
  4. Managing Java Installation (Optional)
  5. Setting up JAVA_HOME Environment Variable

Installing default JRE

To install OpenJDK 6 on Ubuntu 12.04, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. To get an update of the packages, run the command -
    sudo apt-get update
    System gets the updates and displays the message as shown the following figure.
  3. To check if Java is installed, run the command
    java –version

    If the system returns the statement “The program ‘java’ can be found in the following packages:” it means that Java has not been installed yet.
  4. To install Java, run the command
    sudo apt-get install default-jre
    Provide the user password if prompted.
    The system starts the installation. The system may ask for confirmation on the installation.
  5. Press y to confirm the installation.
    When the installation is completed, to verify if Java is installed properly, run the command
    java – version
    The terminal displays the version of Java installed as shown in the following figure.

Installing default JDK

JDK is usually required to compile Java applications. So if required you must install JDK separately.

To install JDK, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. Run the command
    sudo apt-get install default-jdk
    Provide the user password if prompted.
    The system starts the installation.
    The system may ask for confirmation on the installation.
  3. Press y to confirm the installation.

The terminal returns the prompt when JDK is installed.

Installing Oracle JDK (Optional)

Installing Oracle JDK is an optional procedure.

To install Oracle JDK, perform the following:

  1. Log in to the terminal as user performing the installation.
  2. Run the command
    sudo apt-get install python-software-properties

    Provide the user password when prompted.
    The system asks for confirmation on the installation.
  3. Press y to confirm the installation.
    Python-software-properties are set and terminal returns the prompt.
  4. Run the command
    sudo add-apt-repository ppa:webupd8team/java
  5. Press Enter when prompted.
  6. Run
    sudo apt-get update
    to get updates of the packages.
    Terminal returns the prompt after getting the updates.
  7. Run the respective command for the required JDK version as follows:
    • JDK 6 -
      sudo apt-get install oracle-java6-installer
    • JDK 7 -
      sudo apt-get install oracle-java7-installer
    • JDK 8 -
      sudo apt-get install oracle-java8-installer
      The system asks for confirmation on the installation.
  8. Press y to confirm the installation.
    Package Configuration license appears.
  9. Press Enter to agree to the license terms.

Oracle JDK is installed.

Managing Java Installation (Optional)

When multiple Java versions are installed, you can configure the version that must be used as the default one.

Perform the following:

  1. Log in to the terminal as the user performing the configuration.
  2. Run the command
    sudo update-alternatives --config java

    When there are multiple Java versions installed, the terminal returns a message as shown in the following figure.
  3. Type the number corresponding to the version that must be used as the default version.
  4. Run the command
    sudo update-alternatives --config javac
    to set the value for the Java compiler.
  5. Type the number corresponding to the version that must be used as the default one.
  6. Use the same command –
    sudo update-alternatives --config <command>
    for all other commands which have different versions installed.
    Replace <command> with the required value. Possible values are keytool , javadoc , and jarsigner .

Setting JAVA_HOME Environment Variable

JAVA_HOME environment variable is a mandatory attribute for some programs.

To set the variable, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. Type the command
    sudo update-alternatives --config java

    The terminal returns a message as shown in the following figure.
  3. Choose your required installation.
  4. Type the command
    sudo nano /etc/environment
    to edit the file available at the location.
    The file opens as shown in the following figure.
  5. Add the value JAVA_HOME=”PATH” to the file.
    Replace “PATH” with the path of the chosen installation. Following figure shows an example.
  6. Save the changes and exit the file.
  7. Run the command
    source /etc/environment
    to reload the configuration.
  8. To verify the configuration, run the command
    echo $JAVA_HOME

    The terminal returns the added path.

This verifies that the configuration is updated.

Now you can start using Java for your required application development.


13 Comments


Michael - 26/05/2018 13:42:48

The National Gallery https://www.drugonsale.com purchase medication online Police arrested at least 380 people as they struggled to quell the violence, which injured several police and others and shone a spotlight on persistent tension between ethnic Russians and people from the Caucasus and Central Asia.


Judi - 12/05/2018 12:27:01

pBTlVe https://www.genericpharmacydrug.com


mike11 - 17/04/2018 23:33:23

Tvfn8q https://www.genericpharmacydrug.com


mike11 - 16/04/2018 16:22:02

NiKIQf https://www.genericpharmacydrug.com


HolaBromz - 19/03/2018 03:55:03

http://google0123.com/


GoldenTabs - 06/01/2018 01:50:58

AiLL5v https://goldentabs.com/


Barnypok - 08/07/2017 23:42:18

jPXk9P http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


matt - 20/02/2017 12:29:22

QwbQor http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


matt - 20/02/2017 10:33:04

xaNcB6 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


gordon - 20/02/2017 08:36:15

z66qYO http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


chaba - 20/02/2017 06:39:17

FJ91Pv http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


gordon - 20/02/2017 04:43:38

qcP218 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


Craig - 28/11/2015 20:09:48

This really helped me out, thanks a lot!