export JAVA_HOME with spaces in Cygwin

user1508893 picture user1508893 · Jan 28, 2013 · Viewed 20.1k times · Source

I'm trying to set my JAVA_HOME in Cygwin with this command:

export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.7.0_10"

But when I do cd $JAVA_HOME, I'd get this error:

$ cd $JAVA_HOME
-bash: cd: /cygdrive/c/Program: No such file or directory

I tried quoting, and escaping the space (ie., \), but none worked. Any idea what else would?

Thanks,

Answer

vikas kapdoskar picture vikas kapdoskar · Aug 25, 2013

I faced this problem too and I saw many posts but nothing really worked. There is a small trick that I did and things started working.

My JAVA_HOME was set to C:/Program Files/Java/jdk1.7.0_23. The problem was with Program Files directory and I was getting the same error.

In Windows there is a short name created for every directory with a space which is without a space. You can see it by running dir /X command on the command prompt. The Short name for Program Files was PROGRA~1.

In the Windows env variable through My Computer I changed the JAVA_HOME to C:/PROGR~1/Java/jdk1.7.0_23 and in hadoop-env.sh I changed JAVA_HOME to /cygdrv/c/PROGRA~1/Java/jdk1.7.0_23.

It worked fine.