Friday, January 10, 2020

Install Java on Ubuntu

Java is a programming language used to build Android apps and real life web applications like Gmail and Google Docs. This ubiquitous language can be installed onto an Ubuntu server and its what we’ll be teaching in this tutorial today.

Pre-flight

  • Open the terminal and log in as root. If you are logged in as another user, you will need to add sudo before each command.
  • Working on a Linux Ubuntu 18.04 server
  • No installations of previous Java versions

Install Java

Step 1: Updating your system

apt-get update && apt-get upgrade

Step 2: Install the Repo

First, install the repository, its provided by a third party and you’ll need to press enter to continue downloading. The Oracle Java (JDK) Installer automatically downloads and installs Oracle JDK8.
add-apt-repository ppa:webupd8team/java
Update your system once more
apt-get update

Step 3: Install Java 8

Using the command below will kickstart the Java Installer which will assist in our task. Press Y when prompted to continue.
sudo apt install openjdk-8-jdk

Step 4: Verify the Installation of Java 8

java -version
Example Output:
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Set Java’s Home Environment

You may be looking to set Java’s home environment once we’ve installed it onto our server. To do that, lets first, let’s find Java’s path.
update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
Take the highlighted path and add the variable into your /etc/environment file. Add the JAVA_HOME path after any line that is already present.
vim /etc/environment
Once you are in the file type `i` to insert the needed line:
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin/java"
Save and exit the file by typing `ESC` followed by `:wq` and press `Enter`. Afterward, use the source command to have the system recognize the changes in your file.
source /etc/environment
You’ll know the variable has been set correctly by calling the variable.
echo $JAVA_HOME
Example Output:
root@1804:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle/jre/bin/java

Reference:




Previous Post
Next Post

2 comments:

  1. ngga sengaja ketemu blog ini. mantap sharingnya om faris

    ReplyDelete