How to Properly Set Java_Home in /Etc/Environment

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

Maven Java home configuration

As you can see in the documentation the JAVA_HOME variable must point to the java installation path, not to the bin folder.

Change it to C:\Program Files\Java\jdk1.8.0_131

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.

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 do I fix maven error The JAVA_HOME environment variable is not defined correctly?

The SETX command does not modify the current environment.

If you run the following batch file:

setx AAA aaa
echo AAA=%AAA%

It will print

AAA=

So your batch file is wrong. You have to use set:

set AAA=aaa

See What is the difference between SETX and SET in environment variables in Windows.

How to set JAVA_HOME environment variable on Mac OS X 10.9?

If you're using bash, all you have to do is:

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile

If you're using zsh (which probably means you're running macOS Catalina or newer), then it should instead be:

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc

In either case, restart your shell.

If you have multiple JDK versions installed and you want it to be a specific one, you can use the -v flag to java_home like so:

echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile


Related Topics



Leave a reply



Submit