Installing Java in linux. Repository installation In

Installing
java in ubuntu Linux

In
this tutorial I am going to explain how to install Oracle java in
linux environment.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

The
primary goal of this article is to learn java installation in linux,
java installation in most of the linux flavours are similar, few
steps can be modified according to the OS flavour in which you are
installing java.

There
are basically 2 ways to install Java in linux.

Repository
installation

In
this type of installation you have to configure respective repository
and then you have to fire below commands,

$
sudo add-apt-repository ppa:webupd8team/java

$
sudo apt-get update

$
sudo apt-get install oracle-java8-installer

Managing
Java

It
is also possible that multiple java installations are present in the
machine, So in that case we have to configure the default java
version which should be used while running java programs from command
line.

We
have to use below command to configure alternatives,

$
sudo update-alternatives –config java

The
output of the above command will look like,

Selection
Path Priority Status
————————————————————
*0
/usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto
mode
1
/usr/lib/jvm/java-6-oracle/jre/bin/java 1
manual mode
2
/usr/lib/jvm/java-7-oracle/jre/bin/java 2
manual mode

Press
to keep the current choice*, or type selection
number:

Now we
have to select the appropriate java version which we want to set as
default, Simillarly we can also update the javac
command alternatives using below command,

$
sudo update-alternatives –config javac

In
this way we can also update other java commands like, javadoc,
jarsigner
etc.

The
generic command for updating alternatives will look like,

$
sudo update-alternatives –config

Set
JAVA_HOME environment variable

Now
we have to set JAVA_HOME
so that other programs which are using java, can find the java. In
order to set JAVA_HOME,
we have to find out the location at which java is installed.

Now
copy the JAVA installation path and open /etc/environment
file using any editor,
I
have used gedit for the opening the file.

$
sudo gedit /etc/environment

Now,
append the following line, please remember to use your java
installation path.

JAVA_HOME=”/usr/lib/jvm/java-8-oracle”

After
updating the file my /etc/environment
looks like,

Now,
we have to varify the JAVA_HOME
path and installation using below commands,

To
varify JAVA_HOME,
I have used below command from terminal,

$
echo $JAVA_HOME

To
varify the javac & java, I have used below commands,

$
javac -version

$
java -version

If the
above commands work properly then we have configured the Java
installation in linux properly.

Extrating
the Java Jdk files and manual installation

This
is the second method of installing java in linux, In this method we
have to manage all the things manually.

This
method is appropriate for easy update and change java versions.

In
order to install java manually, we have to download the Java jdk-8
files, I have downloaded jdk-8u45-linux-x64.tar.gz
file from oracle’s official website.

You
can download the appropriate java jdk from below link,
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Similarly,
you can download the respective files as per your OS(32/64 bits).

I
have downloaded the jdk8 tar file(jdk-8u45-linux-x64.tar.gz)
and placed it at my Desktop location.

Once
the file is downloaded, we have to perform following steps.

Create
a folder in the linux system, where we are going to save the Java
files.

In
order to save the java files, appropriate location is /usr/lib/jvm.

But
the jvm directory doesn’t exist by default in linux system, so we
have to create the jvm directory under location /usr/lib

To
create the directory, we have to open the terminal and we have to
fire below commands as super user, so we will fire the commands by
prepending sudo.

I
have used below commands to create directory.

$
sudo mkdir /usr/lib/jvm

Once
the directory is created, we have to extract the tar file that we
have downloaded, and move the content of the folder to /usr/lib/jvm/

Extract
the tar file using below command,

$
tar -xvf jdk-8u45-linux-x64.tar.gz

To
move the extracted folder I have used below command,

$
sudo mv jdk1.8.0_45 /usr/lib/jvm/

Now
we have to set the permission for the jvm folder,

I
have used below command to set the permission on the /usr/lib/jvm
folder.

$
sudo chmod -R 777 /usr/lib/jvm/jdk1.8.0_45

Once
the permission is set, we have to set the JAVA_HOME
& PATH
variable in the /home/.bashrc
file.

I
have used gedit editor for updating the .bashrc
file, you can use your favourite editor to update the file I have
used below command to open the .bashrc
file.

Append
the below content at the end of file.

export
JAVA_HOME=/usr/lib/jvm/jdk1.8.0_45
export
PATH=$PATH:$JAVA_HOME/bin

Once
the modifications are completed in .bashrc
file, the file looks like,

Once
the .bashrc file is updated, we have to run the below command.

$
. ~/.bashrc

Now,
we have to varify the JAVA_HOME
path and installation using below commands,

To
varify JAVA_HOME,
I have used below command from terminal,

$
echo $JAVA_HOME

To
varify the javac & java, I have used below commands,

$
javac -version

$
java -version

If
the output of the commands are appropriate/without any error, then
you have configured the Java correctly.

I
have explained both the methods of installing java in linux, both are
appropriate methods.

I
would recommand to use second method of installing java in linux
based on my experience.

Now
you are ready for running various softwares which uses java like,
Hadoop,
Hbase, Hive and other tools like, Eclipse, Netbeans, Tomcat etc.

x

Hi!
I'm Dana!

Would you like to get a custom essay? How about receiving a customized one?

Check it out