Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up JAVA_HOME in Ubuntu to point to Window's JAVA_HOME

Tags:

java

ubuntu

I tried to run Kafka on CMD in Windows and it's very unstable , constantly giving errors. Then I came across this post, which suggests installing Ubuntu and run Kafka from there.

I have installed Ubuntu successfully. Given that I have already defined JAVA_HOME=C:\Program Files\Java\jdk1.8.0_231 as one of the environmental variables and CMD recognizes this variable but Ubuntu does not, I am wondering how to make Ubuntu recognize this because at the moment, when i typed java -version, Ubuntu returns command not found.

Update: Please note that I have to have Ubuntu's JAVA_HOME pointing to the evironmental variable JAVA_HOME defined in my Window system. Because my Java program in eclipse would need to talk to Kafka using the same JVM.

I have added the two lines below in my /etc/profile file. echo $JAVA_HOME returns the correct path. However, java -version returns a different version of Java installed on Ubuntu, not the one defined in the /etc/profile

export JAVA_HOME=mnt/c/Program\ Files/Java/jdk1.8.0_231
export PATH=$JAVA_HOME/bin:$PATH
like image 890
user1769197 Avatar asked Dec 15 '21 08:12

user1769197


People also ask

Where is JAVA_HOME set in Ubuntu?

You can set your JAVA_HOME in /etc/profile as Petronilla Escarabajo suggests. But the preferred location for JAVA_HOME or any system variable is /etc/environment .

How do you JAVA_HOME is set to the location of your JDK?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.


1 Answers

You have 2 issues. Firstly you omitted the "/" from the beginning of the environment variable so your JAVA_HOME would not work unless you cd / as "mnt" won't exist.

export JAVA_HOME=/mnt/c/Program\ Files/Java/jdk1.8.0_231
export PATH=$JAVA_HOME/bin:$PATH

Secondly, if you use a Windows JDK the executable is java.exe

java.exe -version

Also consider when using WSL that WSL1 is faster when accessing Windows OS disk - helpful if using java.exe, and that WSL2 is faster for Linux mount drives - and you may be better off using Linux binaries in favour of Windows binaries as suggested in your Kafka post.

like image 198
DuncG Avatar answered Oct 01 '22 15:10

DuncG