Applies to macOS and Windows Only. Linux users must manually install Java to play Minecraft, so this guide does not apply.

You can install OptiFine without also manually installing Java on macOS or Windows. It involves the command line but the process is very easy. On Windows and macOS, Minecraft Java Edition bundles and manages its own Java installation. We can use this Java to run the .jar OptiFine installer.

Part 1: Locate Minecraft's Java

On macOS, the bundled Java runtime is located inside the minecraft/runtime/jre-x64 folder. On Windows, it is located inside the Launcher's Program Files folder at Minecraft Launcher\runtime\jre-x64 for 64-bit computers, and Minecraft Launcher\runtime\jre-x86 for 32-bit computers.

If you installed Minecraft in the default locations, the full path to the Java executable is:

Part 2: Invoke Minecraft's Java

You can run .jar files from the command line using the following command format: java -jar path/to/program.jar. However, if you tried this on your computer without Java manually installed, the command will fail. This is because your computer does not know where to find the java command, so we will need to use the full path to Minecraft's Java.

Using the aforementioned command format, we can run the OptiFine installer using the following steps.
  1. Open your operating system's command line interface.
    On macOS, this is Terminal, and you can find it by going to /Applications/Utilities in the Finder and launching Terminal, or by searching for "Terminal" (without quotes) in Spotlight.
    On Windows, this is CMD, and you can find it by searching for "CMD" (without quotes) in the start-menu or taskbar search field.
  2. Enter the path to Java, which you found in Part 1.
    You will need to ensure special characters like spaces are properly escaped. On macOS, simply place a backslash (\) before every space in your path, or surround the entire path in quotes. On Windows, surround the entire path in quotes.
  3. Add -jar to the path in your command window. There should be a space between your path and the -, and after the r.
  4. Find your OptiFine installer .jar file, and drag it on top of the command window. It should autofill the path.
  5. Press Enter to run the command. You should see the OptiFine installer window appear. Run it and play Minecraft!
If you get an error message, ensure your command looks like this: The path to the OptiFine jar file will vary.
If you want, you can add Minecraft's Java to your PATH environment variable so that you only need to type java -jar path/to/OptiFine_1.XX.X_HD_X_XX.jar. Search the internet for (without quotes) "add environment variable macOS" or "add environment variable Windows" to get guides about how to do this.