Java_HOME setting for paths with spaces

Introduction

JAVA is widely used, and setting JAVA_HOME is a common task as a developer. There are many articles on the setting procedure on Windows. This time, I will explain the setting of the path with spaces.

JAVA_HOME setting procedure

Open control panel

image.png

Select system and security

image.png

Select system

image.png

Select advanced system settings

image.png

Select an environment variable

image.png

Press new

image.png

Variable setting

Variable name: JAVA_HOME Path: C: \ Program Files \ Java \ jdk1.8.0_201

If you do not change the path when installing JAVA, it will be installed in "C: \ Program Files \ Java". Since there is a space in the "Program Files" folder, it may be strange due to the path when executing with the command. Error example: image.png

The best way is to select a folder with no space and no Japanese when installing.

In the case of "Program Files", there are the following plans.

Enclose the path in double quotes

"" C: \ Program Files \ Java \ jdk1.8.0_201 "" Set the path like this

This often solves the problem, but in some cases it cannot be used.

Use a short folder name

If you execute it with the dir / x command, you can see the short folder name. image.png

In the above path, if you set the following path, you can avoid the influence of the path with the base. C:\Program Files\Java\jdk1.8.0_201」 ⇒ C:\Progra~1\Java\jdk1.8.0_201

Add the JAVA bin folder to the path variable

You can use javac and java commands by adding "% JAVA_HOME% \ bin" to the path variable.

that's all

Recommended Posts

Java_HOME setting for paths with spaces
Setting JAVA_HOME on Ubuntu
Change the setting value for each environment with Digdag (RubyOnRails)
Preparation for developing with Rails