Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 711
Davide Buoso Avatar asked Oct 30 '17 10:10

Davide Buoso


2 Answers

  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

like image 78
crakama Avatar answered Oct 05 '22 23:10

crakama


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
like image 30
thecloudguy Avatar answered Oct 05 '22 22:10

thecloudguy