# How to properly save gedit java_home file

Every tutorial I've read about setting java_home environment variable via gedit just says "save and exit" save to where?

Can I save this particular gedit file as such /home/nexogen/developer/gedit_java

Or must I save this gedit file to /usr/lib/jvm/java-8-oracle

as in save the gedit file which contains the java_home environment variable command in the same directory as jave_home itself

I think I have understand your problem. You're opening /etc/environment file as normal user and then cannot save the file at that place.

You won't open it as normal user. Instead you'll open as root user. To do so, First open a terminal by pressing Ctrl-Alt-T keyboard shortcut.

Then write this command there to open as root

sudo -i gedit /etc/environment


This will open the file as root.

JAVA_HOME is an environment variable. It is set to a directory containing JDK installation like this line

JAVA_HOME=/usr/lib/jvm/java-8-oracle


I assumed jdk is in /usr/lib/jvm/java-8-oracle folder.

You'll add this line at the end of that file and save by pressing Ctrl-S. This will overwrite the file at place. You don't need to save this file anywhere else as you opened this as root

Now exit gedit.

Logout and login again to see the effect of setting JAVA_HOME.

• Yes I know what gedit is and I also know the proper directory. I opened gedit and opened /etc/environment and then ran command "export JAVA_HOME=/usr/lib/jvm/java-8-oracle" now I'm frustrated because It's not just save and exit... When I run the command and go to save, I must choose a directory to save to. The home directory initially pops up. I simply need to know where I should save to (the location I should save the gedit untitled document to) using the GUI I went into the directory /usr/lib/jvm and Java-8-oracle is there. But java-8-oracle is also still located in /etc/environment – nexogen.io Sep 12 '16 at 18:21
• you will save it in. bashrc file. /etc/environment is for system usage. Use the file in your home not /etc/environment. – Anwar Sep 12 '16 at 18:37
• When you say write a line at the end of .bashrc what do you mean? I am ready to save and I selected .bashrc I was going to save as "JAVA_HOME.bashrc in the home directory... Is this not proper? – nexogen.io Sep 12 '16 at 18:43
• No. It's not. You'll open. bashrc first. add lines on that file and save that file – Anwar Sep 12 '16 at 18:47
• @nexogen.io I think I understood your problem and updated the answer. Check it.your problem was you weren't opening the file as root – Anwar Sep 13 '16 at 0:33

Well I recommend you to add the following in the file /etc/profile so that the java path could be usable system-wide. JAVA_HOME and PATH variable can be set as follows : Open up a terminal

sudo nano /etc/profile

At the following statements at the bottom of the file , I am assuming your java extracted folder is at /usr/lib/jvm/java-8-oracle

JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin JRE_HOME=/usr/lib/jvm/java-8-oracle/jre PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH


Save the file by pressing Ctrl + x y enter

Better give read and execute permission for the Java installation folder as follows :

sudo chmod -R a+rx /usr/lib/jvm/java-8-oracle


I also recommend to update alternative for all the application to use java when required as follows :

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-8-oracle/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-8-oracle/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-8-oracle/bin/javaws" 1
sudo update-alternatives --set java /usr/lib/jvm/java-8-oracle/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-8-oracle/bin/javac
sudo update-alternatives --set javaws /usr/lib/jvm/java-8-oracle/bin/javaws


Now reload the profile file we have updated as follows in the terminal.
Note: There is a space between . and /etc/profile in the below command.

. /etc/profile


That's it