Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set [Bash on Ubuntu on Windows] [environment variables] from [windows path]?

Try to use samza.apache.org/startup/hello-samza/0.7.0/ with Bash On Windows

it will run

bin/grid bootstrap

where the flowing code

if [ -z "$JAVA_HOME" ]; then
  if [ -x /usr/libexec/java_home ]; then
    export JAVA_HOME="$(/usr/libexec/java_home)"
  else
    echo "JAVA_HOME not set. Exiting."
    exit 1
  fi
fi

give an error

JAVA_HOME not set. Exiting.

on CMD when i run

echo %JAVA_HOME%

i got

C:\Program Files (x86)\Java\jdk1.8.0_102\

I want to import the path data to bash

enter image description here

like image 408
Mohamed Elrashid Avatar asked Jul 15 '17 03:07

Mohamed Elrashid


2 Answers

I would try export JAVA_HOME="/mnt/c/Program Files (x86)/Java/jdk1.8.0_102" to set the JAVA_HOME variable in the bash shell.

Update (response to your edit):

I wouldn't recommend trying to automatically import your Windows paths to Bash on Ubuntu on Windows, because the paths have to be converted to be understood by the bash shell (\ to /, C:\ to mnt/c/ and so on), and because not all of the tools you're probably going to reference will work on both Windows and Linux. Instead, install what you need on the Bash shell using apt-get (you don't need to use sudo because BUW loads in a root shell). Java is probably fine to reference as above, but most things you'll want installed separately on Ubuntu.

like image 86
Shahein Moussavi Avatar answered Oct 19 '22 18:10

Shahein Moussavi


As a quick solution, I created a powershell script that would

  1. Take all windows environment variables
  2. Change the path separator to /
  3. Change C: to /mnt/c
  4. Output export commands one line per environment variable

    Get-ChildItem Env: | % {"export $($_.Name)=`"$($_.Value.Replace('\', '/').Replace('C:', '/mnt/c'))`""}
    

Now, all you need to do is run this script in Powershell, copy the output and paste it in WSL/Ubuntu on Windows to populate the environment variables. You could also put all these commands in a .sh file and execute it using bash.

It is a crude solution, but this worked for me. I'm open to suggestions on improving this.

like image 1
raghav710 Avatar answered Oct 19 '22 18:10

raghav710