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.
- 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 VPS server
- No installations of previous Java versions
Step 1: Updating your system
apt-get update && apt-get upgrade
Step 2: Download Java
Follow these steps to download and install Java for Linux. This procedure installs the Java Runtime Environment (JRE) for 64-bit Linux, using an archive binary file (.tar.gz).
Go to http://java.com and click on the Download button.
Download and check the downloaded file size to ensure that you have downloaded the full, uncorrupted software bundle. Before you download the file, take notice of the files size provided on the download page on the website. Once the download has completed, compare that file size to the size of the downloaded file to make sure they are equal.
The instructions below are for installing version Java 8 Update 73 (8u73). If you are installing another version, make sure you change the version number appropriately when you type the commands at the terminal. Example: For Java 8u79 replace 8u73 with 8u79. Note that, as in the preceding example, the version number is sometimes preceded with the letter u, and sometimes it is preceded with an underbar, for example, jre1.8.0_73.
A note about root access: To install Java in a system-wide location such as /usr/local, you must login as the root user to gain the necessary permissions. If you do not have root access, install Java in your home directory or a subdirectory for which you have write permissions.
Change to the directory in which you want to install. Type:
For example, to install the software in the /usr/java/ directory, Type:
Next, move the .tar.gz archive binary to the current directory.
Unpack the tarball and install Java
tar zxvf jre-8u73-linux-x64.tar.gz
The Java files are installed in a directory called jre1.8.0_73 in the current directory. In this example, it is installed in the /usr/java/jre1.8.0_73 directory. When the installation has completed, you will see the word Done.
Lastly, delete the .tar.gz file if you want to save disk space.
Next, verify the Installation of Java 8.
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.
Once you are in the file type i to insert the needed line:
Save and exit the file by typing ESC followed by :wq and press enter.
After this, we can use the source command to ensure the system recognizes the changes in our file.
You’ll know the variable has been set correctly by calling the variable.
root@host:~# echo $JAVA_HOME /usr/lib/jvm/java-8-oracle/jre/bin/java
The Most Helpful Humans In Hosting™
Liquid Web prides ourselves as being The Most Helpful Humans In Hosting™! Our support staff is always available to assist with any Dedicated, Cloud, or VPS server issues 24 hours a day, 7 days a week 365 days a year.
We are available, via our ticketing systems at firstname.lastname@example.org, by phone (at 800-580-4986) or via a LiveChat for whatever method you prefer. We work hard for you so you don’t have to!!!