How to Install Oracle Java and set the JAVA_HOME, PATH for all users in Ubuntu LTS

Description: In this post we are trying to solve the JAVA_HOME and PATH for all user, just follow the steps below and then create user and you have the permission without accessing the root.

 

Step 1:

Login in your Ubuntu with root, install the Java package with apt get command in terminal.

First you need to update.

sudo apt-get update

Then check if it is not install by typing the following command.

java -version

If it return “The program java can be found in the following packages” this line then you need to install the Java.

Before installing the Java you need to add some repositories in order to perform JDK installation.

Step 2:

Run the following commands.

sudo apt-get install python-software-properties

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

Now install the JDK by running the following command.

sudo apt-get install oracle-java7-installer

Step 3:

After this you need to set the $JAVA_HOME and $PATH for all users so that when the new user created he has the permission to JDK Path and Home.

To set the $PATH open the file with your editor vi /vim

vim /etc/environment

here you see the line

¬†PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

:/usr/games:/usr/local/games”

Now you need to add the “:/usr/bin/java/bin” at the very last of this line.

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

:/usr/games:/usr/local/games:/usr/bin/java/bin”

Step 4:

Now you need to add the JAVA_HOME.

Open same file /etc/environment

Add the following line next to the PATH.

JAVA_HOME=”/usr/bin/java”

Now reload the file by giving the following command in the terminal.

source /etc/environment

Now echo $JAVA_HOME or $PATH from any user and you see the path and home.

Enjoy developing.

Leave a Reply

Your email address will not be published. Required fields are marked *