8

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

Mohamed Elrashid
  • 8,125
  • 6
  • 31
  • 46
  • Have you installed Java on the Bash shell directly? It won't recognize the path `C:\...`. To Bash on Ubuntu on Windows, the path would be `/mnt/c/...` What happens when you run `echo $JAVA_HOME` in the bash shell? – Shahein Moussavi Jul 15 '17 at 03:27
  • how to install Java on the Bash shell directly ? echo $JAVA_HOME gives a blank line – Mohamed Elrashid Jul 15 '17 at 03:43
  • 1
    If you want to install the JDK for Ubuntu - https://stackoverflow.com/questions/36478741/installing-oracle-jdk-on-windows-subsystem-for-linux – Shahein Moussavi Jul 15 '17 at 04:07
  • 1
    Looks like a way to share variables, which includes path conversions was introduced in Insider Build 17063: https://blogs.msdn.microsoft.com/commandline/2017/12/22/share-environment-vars-between-wsl-and-windows/ – JeffryHouser Jun 10 '18 at 23:21

5 Answers5

10

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.

Shahein Moussavi
  • 349
  • 2
  • 13
  • worked! but now it asking for git path? my main question: is there a way to set Path variable for bash From window Path automatically on bash startup – Mohamed Elrashid Jul 15 '17 at 03:47
  • 2
    You may need to install git on the bash shell if you haven't already. (`apt-get update` then `apt-get git`) Add the variables to your `~/.bashrc` file (syntax is the same) - . Then, either restart the shell, or type `source ~/.bashrc` to reload the environment variables. – Shahein Moussavi Jul 15 '17 at 04:03
  • apt-get will install a new instanse , I have "/mnt/c//Program Files/Git/cmd/git.exe" and"C:\Users\mohamad\.bashrc" like this https://gist.github.com/Elrashid/a16f74449c108d2336aec21abe80fa59 how to add it ? – Mohamed Elrashid Jul 15 '17 at 04:16
  • 1
    .exe files don't run on Linux. I'm recommending that you install git separately on Bash on Ubuntu on Windows. See my edit above. – Shahein Moussavi Jul 15 '17 at 04:17
  • Since June 2017, the [windows executables can be invoked from the Bash on Ubuntu](https://msdn.microsoft.com/en-us/commandline/wsl/interop) and you can invoke bash from command line.. However, the windows executables will use the windows environment variables and configuration. – Jaime Sep 16 '17 at 18:07
  • 2
    wslpath is your (new) friend in Wsl2, so no reason to do the path importing to Wsl from Win manual. – Timo Jan 03 '21 at 12:22
1

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.

S Raghav
  • 1,386
  • 1
  • 16
  • 26
1

My path environment variable seems to already have my windows paths there. But you can run windows programs from Ubuntu on Windows. So you can get environment variables or whatever you like.

export PATH=$PATH:`/mnt/c/Windows/System32/cmd.exe -/C "echo %PATH%"`

It isn't recommended to use Cygwin (licensing, registry corruption, etc). But below should work. run is documented to run windows programs from the bash shell it gives you.

export PATH=$PATH:`run /mnt/c/Windows/System32/cmd.exe -/C "echo %PATH%"`
TamusJRoyce
  • 817
  • 1
  • 12
  • 25
  • 1
    I think this is the simplest answer since it doesn't require PowerShell. I would add that in Windows command line, `%PATH%` is the correct variable reference, not `$PATH` (which is the Linux variable reference). – yuyu5 Jul 11 '20 at 16:11
  • you might need to append `| sed -e 's/;/:/g'` or other string processing to replace semicolons with colons. If there is a better suggestion then sed (zsh compatible maybe?), leave a comment. – TamusJRoyce Jul 14 '20 at 19:47
  • @yuyu5 this does not work in a windows cmd, do not know why you think this is for a cmd. – Timo Jan 03 '21 at 12:27
  • Think about wslpath to convert the paths. Otherwise, your solution is not helpful. – Timo Jan 03 '21 at 12:28
1

This one is working for me, by setting WSLENV in the System variables environment.

System variables

Justin
  • 11
  • 3
0

export [variable-name]='any-path' for current shell session

e.g.

export VSCode='C:/Program Files/....'
echo $VSCODE