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

12,366

Solution 1

  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

Solution 2

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

Solution 3

Try with sudo

$ sudo cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre 
EOL
Share:
12,366
Davide Buoso
Author by

Davide Buoso

Updated on June 08, 2022

Comments

  • Davide Buoso
    Davide Buoso almost 2 years

    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
    
  • Jean-Claude Arbaut
    Jean-Claude Arbaut over 2 years