# How to change the Java installation directory

**URL:** https://discourse.chef.io/t/how-to-change-the-java-installation-directory/19758
**Category:** Chef Infra (archive)
**Created:** [April 11, 2021, 5:19pm UTC](https://discourse.chef.io/t/how-to-change-the-java-installation-directory/19758 "2021-04-11T17:19:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deepaksingla](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/deepaksingla/32/2321_2.png) [@deepaksingla](https://discourse.chef.io/u/deepaksingla)
#### Post date: [April 11, 2021, 5:19pm UTC](https://discourse.chef.io/t/how-to-change-the-java-installation-directory/19758/1 "2021-04-11T17:19:03Z")

</div>

Hi

I am trying to install Java 8 on windows. By default, it is installing in directory "C:\Program files\Java". But I want to install the java at another location.

Kindly help me out. Find the below chef code to install Java8

```
# Download Java_8 from remote directory on chef-client node
remote_file "#{Chef::Config['file_cache_path']}/jdk.exe" do
  source "#{node['shared_resources']['java_8']['download_url']}"
  remote_domain "#{node['shared_resources']['domain']}"
  remote_user "#{node['shared_resources']['user_name']}"
  remote_password "#{node['shared_resources']['password']}"
end

execute "Java" do
	cwd "#{Chef::Config['file_cache_path']}"
	command "jdk.exe"
end

windows_env 'JAVA_HOME' do
	value "#{ENV['ProgramW6432']}\\Java\\#{node['java']['directory_name']}"
end

# Set the path of JAVA_HOME in in PATH environment variable
windows_env 'Path' do
	value "#{ENV['ProgramW6432']}\\Java\\#{node['java']['directory_name']}\\bin\\;#{ENV['Path']}"
	action :modify
end

# delete jdk-8u181-windows-x64.exe
file "#{Chef::Config['file_cache_path']}/jdk.exe" do
	action :delete
end

```

Regards,  
Deepak

---

<div class="post-metadata">

### Author: ![greg.schofield](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@greg.schofield](https://discourse.chef.io/u/greg.schofield)
#### Post date: [April 14, 2021, 2:59pm UTC](https://discourse.chef.io/t/how-to-change-the-java-installation-directory/19758/2 "2021-04-14T14:59:01Z")

</div>

Hi Deepak,

Looks like you can provide an argument to the jdk command to set the installation directory.

Try altering you `command` property of your execute resource to this:

```auto
jdk.exe /s INSTALLDIR=C:\my-custom-dir

```
