I would like to install the dmg java package in my MAC OS through the terminal
I tried using this command:
sudo installer -package jdk-7u51-macos-x64.dmg
I ran into the exact same problem and found the root cause. if you trying to install a package where the installer has no permission to access the directory you will get that weird error.
i.e
osascript -e {'do shell script "installer -allowUntrusted -pkg ~/Download/OpenJDK8U-jdk_x64_mac_hotspot_8u275b01.pkg -target /tmp/ " with administrator privileges'}
1:150: execution error: installer: Error - the package path specified was invalid: '/Users/user-x/Download/OpenJDK8U-jdk_x64_mac_hotspot_8u275b01.pkg'. (1)
either by moving the package into /tmp/ or change the directory permission so applescript or installer command can access the file.
osascript -e {'do shell script "installer -allowUntrusted -pkg /tmp/OpenJDK8U-jdk_x64_mac_hotspot_8u275b01.pkg -target /tmp/ " with administrator privileges'}
installer: The upgrade was successful.K