Follow these steps for installing Java (Oracle JDK) on Linux Ubuntu server using terminal.
notes : remove sudo if you are already root user.
First, open the terminal and use SSH if you’re installing on the Remote Machine.
Most of Ubuntu installation come with OpenJDK, if no, skip these 2 step.
1. For show currently installed java on system, type this on terminal :
java -version
2. This command will completely remove OpenJDK/JRE from your system, type this on terminal :
sudo apt-get purge openjdk-\*
3. create “/usr/local/java” directory, type this on terminal :
type : sudo mkdir -p /usr/local/java
4. download Java from Oracle website (url : http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html).
Usually tar.gz format (for example : “jdk-7u79-linux-x64.tar.gz”)
5. copy the downloaded file to folder /usr/local/java
6. Go to folder /usr/local/java/, type this on terminal :
cd /usr/local/java/
7. set the file owner, type this on terminal (replace “filename” with downloaded file) :
sudo chmod a+x “filename”
8. extract file, type this on terminal :
sudo tar xvzf “filename”
9. At this point, you should have an uncompressed binary directory in /usr/local/java for the Java JDK/JRE.
notes : replace “directory name” with your uncompressed binary directory name.
10. Edit the system PATH file /etc/profile and add the following system variables to your system path, type this on terminal :
sudo nano /etc/profile
11. After you open the file with nano, type this at the end of file :
JAVA_HOME=/usr/local/java/”directory name”
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
12. To finish editing the file, press “ctrl + x” on keyboard
13. for confirm saving the file, press : y
14. for Inform OS for java new installation, type this on terminal :
sudo update-alternatives –install “/usr/bin/java” “java” “/usr/local/java/”directory name”/bin/java” 1
15. Set newly installed java as default java, type this on terminal :
sudo update-alternatives –set java /usr/local/java/”directory name”/bin/java
16. Reload environment variable, type this on terminal :
/etc/profile
17. Check the newly installed java on system, type this on terminal :
java -version