How to install Java on Ubuntu
DIFFICULTY strong> | Basic - 1 | Medium - 2 | Advanced - 3 td> |
TIME REQUIRED strong> | 15-30+ min |
RELATED PRODUCTS strong> | Linux-based VPS or dedicated servers |
The Oracle implementation of Java is the reference implementation.
Before installing, you need to know if you're running a 32-bit or 64-bit installation of Ubuntu. Run the file command against the init boot startup file to determine its file type and it will report which of the two is installed.
This reports results like the following:
Next, visit http://www.java.com/en/download/manual.jsp and download the Linux release for your installation, either Linux for the 32-bit release or Linux x64 for the 64-bit version. Follow the instructions on the Oracle site. You'll download a file named something like jre-8u25-linux-i586.tar.gz (32-bit) or jre-8u25-linux-x64.gz (64-bit). The name may differ slightly.
Now, run the rest of the commands as root.
After downloading, create a place to store the unpacked version of what you've just downloaded. You may pick a different place if you wish to install it in a different location.
Next, unpack what you've downloaded into that directory:
After unpacking, you'll need to add "Java" to your path so it can be found when you need to run java. Add the following to /etc/profile, make sure to use the directory that was created when you unpacked what you downloaded. There will be a sub-directory specific to the version installed. Use that as your JAVA_HOME. Use your favorite text editor to edit the /etc/profile file.
Add the following to the bottom of file:
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME
export PATH
The next time you login, you can check to see if you've configured your environment correctly. If you have, the following command will tell you what version is running. It should be the same as what you just installed.
Output should look like the following