How to Set Java_Home Path on Ubuntu

How to set Java environment path in Ubuntu

set environment variables as follows

Edit the system Path file /etc/profile

sudo gedit /etc/profile

Add following lines in end

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Then Log out and Log in ubuntu for setting up the paths...

How to set JAVA_HOME in Linux for all users


  1. find /usr/lib/jvm/java-1.x.x-openjdk
  2. vim /etc/profile

    Prepend sudo if logged in as not-privileged user, ie. sudo vim

  3. Press 'i' to get in insert mode
  4. add:

    export JAVA_HOME="path that you found"

    export PATH=$JAVA_HOME/bin:$PATH
  5. logout and login again, reboot, or use source /etc/profile to apply changes immediately in your current shell

Set JAVA_HOME ubuntu: path not found

/etc/environment is as well a bash script, so change the line with

"JAVA_HOME":"/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin"

which is not bash variable syntax to:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Also note the above uses the base directory not the bin directory for the JAVA_HOME environment variable.

How to set JAVA_HOME path on Ubuntu?

I normally set paths in

~/.bashrc

However for Java, I followed instructions at
https://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7

and it was sufficient for me.

you can also define multiple java_home's and have only one of them active (rest commented).

suppose in your bashrc file, you have

export JAVA_HOME=......jdk1.7

#export JAVA_HOME=......jdk1.8

notice 1.8 is commented. Once you do

source ~/.bashrc

jdk1.7 will be in path.

you can switch them fairly easily this way. There are other more permanent solutions too. The link I posted has that info.

I want to get the path to jdk to set JAVA_HOME in ubuntu


# The next var an example path obvs.
export JAVA_HOME=/usr/lib/jvm/bellsoft-java16-amd64
export PATH=$JAVA_HOME/bin:$PATH

Windows Subsystem for Linux not recognizing JAVA_HOME Environmental Variable

As Biswapriyo suggested, you should use WSLENV.

  1. Open PowerShell. Then set JAVA_HOME to the path to your java installation.

  2. In your case, run setx JAVA_HOME "D:\Program Files\Java\jdk-11.0.1"

You should see a message that says "SUCCESS: Specified value was saved".


  1. Then run setx WSLENV "JAVA_HOME/p".

You should see the success message again.


  1. Type 'env' into your WSL bash prompt.

You should see JAVA_HOME correctly set at this point.

Note: If step 2 doesn't work, you might want to changing the path to JAVA_HOME to include the \bin folder.

I'm trying to set JAVA_HOME and path for JDK on Linux using .bashrc. But it says [ Error writing .bashrc: Permission denied ]. Why?

You're trying to create a new file in the root directory /, where a normal user doesn't have permission to write. The file you must edit is located in your home directory, so open the editor this way: nano ~/.bashrc



Related Topics



Leave a reply



Submit