ubuntu java environment path, bash: /etc/environment: permission denied?

Davide Buoso picture Davide Buoso · Oct 30, 2017 · Viewed 9.6k times · Source

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

Answer

crakama picture crakama · Feb 22, 2018
  1. 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*
    
  2. 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

  3. 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.

  1. 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