Install Java On Ubuntu By CommandLine
Installing JRE/JDK
1 | sudo apt-get update # update the package index |
Setting the “JAVA_HOME” environment variable
find out the path of JAVA installation
1
sudo update-alternatives --config java
It perhaps returns:
1
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Then, the path is “/usr/lib/jvm/java-7-openjdk-amd64”, hold it.
use nano to edit the file /etc/environment
1
sudo nano /etc/environment
In this file, append the path, holden just now, into the quotes, seperate by colon, like this:
1
JAVA_HOME="your/other/paths:/usr/lib/jvm/java-7-openjdk-amd64"
reload the file /etc/environment
1
source /etc/environment
check if java installed
1
java -version
Finally, it maybe not have to set the environment variable. But I don’t test that.