Using UBUNTU, I installed java 8 with the following command
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default
and I'm trying to set the java environment path as follow
$ cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
EOL
but I get this error message:
bash: /etc/environment: permission denied
Assuming that you have already the following:
$sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default*
Open /etc/environment
file with the following command.
sudo nano /etc/environment
N/B: You can replace nano with any other editor you like e.g atom
At the end of file, add
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
The command above alone worked for me but you can also add the command below if you want.
JRE_HOME="/usr/lib/jvm/java-8-oracle/jre"
Remember the path used here was my java installation directory, if yours is the same then you don't need to change anything, otherwise use your path.
Check whether your changes persisted
$ source /etc/environment
$ echo $JAVA_HOME
https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
Try this script, save it in a file.sh
#!/bin/bash
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install openjdk-8-jre -y
sudo cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
EOL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With