How to Setup Java Environment for Netbeans in Ubuntu Linux Operating System

Posted on

As stated in the title of the article, the purpose for writing this article is to give an explanation on how to setup Java environment in Ubuntu Linux operating system. Basically, the Java environment is a requirement for any Java Application Server to run. The main connection with Netbeans which is one of the popular Java IDE available is the internal execution of the Java Application itself from Netbeans. Since in the initial process to create a new project in Netbeans is also specifically ask for the Application Server required, the main setup for Java environment is also required. The steps are enlisted below :

1. Check the available Java installed by running the following command :

update-alternatives --list java

The following are the output of the above command execution :

user@hostname:~$ update-alternatives --list java
/opt/jdk1.8.0_171/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
user@hostname:~$

The output of the command executed above is actually the Java program currently installed. If there is any other Java program which is needed for further installation since there is a specific version which is going to work out with the Netbeans installed, just add another Java program.

  1. Running as ‘root’, just execute the command in the command line as follows :
update-alternatives --config java

The following are the output of the above command execution :

root@hostname:/opt# update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.
root@hostname:/opt# 

The above output is the output where the Java program installed is only one. It is the default Java program installed in Ubuntu using the ‘apt-get’ tools. The main purpose of setting and configuring Java environment to support Netbeans is to add the second entry which is located in /opt/jdk1.8.0_171.

3. Before adding the second entry, download Java SDK in zip compressed format.

4. Extract the Java SDK zip file and store it in ‘/opt’.

5. After successfully placed the extracted Java SDK zip file in /opt, execute the following command to add the second entry of Java program :

root@hostname:/opt# update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_171/bin/java 1
root@hostname:/opt# update-alternatives --list java
/opt/jdk1.8.0_171/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
root@hostname:/opt#

6. After installing new Java program, recheck to see if it is already properly installed as shown below:

root@hostname:/opt# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /opt/jdk1.8.0_171/bin/java                       1         manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press  to keep the current choice[*], or type selection number: 1
update-alternatives: using /opt/jdk1.8.0_171/bin/java to provide /usr/bin/java (java) in manual mode
root@hostname:/opt#

Just enter, number 1 to set the default Java program executed to change from the ‘0’ selection to ‘1’.

7. Last but not least, check the version of the currently installed and configured java as shown below :

root@hostname:/opt# java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
root@hostname:/opt# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
root@hostname:/opt#  

As shown in the above output, the version of the currently running Java is ‘1.8.0_171’ which is suitable with the one selected through the execution of ‘update-alternatives –config java’

3 thoughts on “How to Setup Java Environment for Netbeans in Ubuntu Linux Operating System

Leave a Reply