Install Java silently using powershell in Azure Windows VM

Written by Akhil M Anil.

To install Java silently using PowerShell in Windows VM, follow the following steps:

Downloading Java can be done in two ways:

  1.  Download your required Java version (Java Downloads | Oracle) to a folder in your Windows VM. 
  2.  Use PowerShell to Download Java to a folder. 

Follow the below steps for downloading Java through PowerShell:

  1. Initially copy the Download link for your required Java version, Java file name, and Location where you want to download Java in your VM to a notepad
  2. Open PowerShell 
  3. Run the following command in PowerShell
    • $url = "<your-copied url>"
    • $filename = "<file_name>"
    • $dest = "<outputfile-location\$filename>"
    • Invoke-WebRequest -Uri $url -OutFile $dest
    • For Example: 
      • $url = "https://download.oracle.com/java/18/latest/jdk-18_windows-x64_bin.exe"
      • $filename = "jdk-18_windows-x64_bin.exe"
      •  $dest = "C:\Users\akhilanil\Desktop\Java\$filename"
      • Invoke-WebRequest -Uri $url -OutFile $dest
  4. Run the following command will download Java in the specified location.


  
Once java is downloaded,  execute the following steps to install the java version through PowerShell.

  1. Execute the following commands to install Java Silently.
    • Start-Process -Wait -FilePath $dest -ArgumentList "/s" -PassThru
  2. If you manually download Java in a folder, Open the same directory which contains the executable in PowerShell.
  3. Run the following command in PowerShell to install Java Silently.
    • Start-Process -Wait -FilePath '.\<exe filename.exe>' -ArgumentList "/s" -PassThru
    • For Example: Start-Process -Wait -FilePath '.\jdk-18_windows-x64_bin.exe' -ArgumentList "/s" -PassThru

      4.  The Java should be installed by now. You can validate it by opening a new PowerShell window and checking the version of Java by java -version  









Comments

Post a Comment

Popular posts from this blog

Usage of Variable Template in Azure DevOps Pipelines

List of Repositories - Authorize Rest API calls using Job Access Token