Download the latest JDK(jdk-8u321-linux-x64.tar.gz) from this official site.
Step 2:
Open the terminal (Ctrl + Alt + T)
and enter the following command
All Comand
type
Step 3.
sudo mkdir /usr/lib/jvm
If the /usr/lib/jvm folder does not exist, this command will
create the directory. If you already have this folder, you can ignore this step
and move to next step.
3
4step 4.
Enter the following command
to change the directory.
cd
/usr/lib/jvm
step 5.
Extract the jdk-8u321-linux-x64.tar.gz file in that directory using this command.
sudo tar -xvzf
~/Downloads/jdk-8u321-linux-x64.tar.gz
According
to this command, the JDK filename is jdk-8u321-linux-x64.tar.gz and which is located in the ~/Downloads folder. If your downloaded file
is in any other location, change the command according to your path.
Step 6:
Enter the following command to open the environment
variables file.
sudo gedit /etc/environment
Step 7:
In the opened file, add the following bin folders
to the existing PATH variable.
/usr/lib/jvm/jdk1.8.0_321/bin
/usr/lib/jvm/jdk1.8.0_321/db/bin
/usr/lib/jvm/jdk1.8.0_321/jre/bin
The PATH variables
have to be separated by a colon.
Notice that the installed JDK version is 1.8 update
321. Depending on your JDK version, the paths can be different.
Add the following environment variables at the end
of the file.
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_321"
J2REDIR="/usr/lib/jvm/jdk1.8.0_321/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_321"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_321/db"
The environment file before the modification:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
The environment file after the modification:
PATH=
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_321/bin:/usr/lib/jvm/jdk1.8.0_321/db/bin:/usr/lib/jvm/jdk1.8.0_321/jre/bin"
J
2SDKDIR=
"/usr/lib/jvm/jdk1.8.0_321"
J
2REDIR=
"/usr/lib/jvm/jdk1.8.0_321/jre"
JAVA_HOME=
"/usr/lib/jvm/jdk1.8.0_321"
DERBY_HOME=
"/usr/lib/jvm/jdk1.8.0_321/db"
Step
8:
Enter the following commands to inform the system
about the Java's location. Depending on your JDK version,
the paths can be different.
sudoupdate-alternatives --install
"/usr/bin/java""java"
"/usr/lib/jvm/jdk1.8.0_321/bin/java"
0
sudoupdate-alternatives --install
"/usr/bin/javac""javac"
"/usr/lib/jvm/jdk1.8.0_321/bin/javac"
0
sudoupdate-alternatives --set java /usr/lib/jvm/jdk1.8.0_321/bin/java
sudoupdate-alternatives --set javac /usr/lib/jvm/jdk1.8.0_321/bin/javac
Step 9:
To verify the setup enter the following commands
and make sure that they print the location of java and javac as you have
provided in the previous step.
update-alternatives --list java
update-alternatives --list javac
Step 10:
Restart the computer (or just log-out and login)
and open the terminal again.
Step 11:
Enter the following command.
java -version
0 Comments