Home > Enterprise >  Setting up JAVA_HOME in Ubuntu to point to Window's JAVA_HOME
Setting up JAVA_HOME in Ubuntu to point to Window's JAVA_HOME

Time:12-15

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

CodePudding user response:

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.

CodePudding user response:

When the user logs in, the environment will be loaded from the /etc/profile and $HOME/.bashrc files. There are many ways to solve this problem. You can execute ex manually

export JAVA_HOME=/opt/jdk1.8.0_66
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

or fix the configuration in /etc/profile or $HOME/.bashrc

export JAVA_HOME=/opt/jdk1.8.0_66
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

CodePudding user response:

You can edit /etc/profile, append

export JAVA_HOME=C:\Program Files\Java\jdk1.8.0_231

export PATH=$JAVA_HOME/bin:$PATH
  • Related