11

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 -target /

But I receive this error:

installer: Error the package path specified was invalid: 'jdk-7u51-macos-x64.dmg' 
user3472065
  • 1,259
  • 4
  • 16
  • 32

4 Answers4

15

Try this:

MOUNTDIR=$(echo `hdiutil mount jdk-7u51-macos-x64.dmg | tail -1 \
| awk '{$1=$2=""; print $0}'` | xargs -0 echo) \
&& sudo installer -pkg "${MOUNTDIR}/"*.pkg -target / 
Mateusz Szlosek
  • 1,175
  • 10
  • 19
  • @SebMa I have `10.13.5 Beta (17F45c)` installed and this `awk` still works for me, even with spaces in mounted dir. – Mateusz Szlosek Apr 26 '18 at 14:29
  • Does your `awk` command also return your mounted dir when there is no space in it ? – SebMa Apr 26 '18 at 15:38
  • Because `$2` is equal to `Apple_HFS` in my case. Full output: `/dev/disk2s2 Apple_HFS /Volumes/Lemur Installer` – Mateusz Szlosek Apr 26 '18 at 16:39
  • That's a [useless `echo` in backticks](http://www.iki.fi/era/unix/award.html#echo) with some additional pesky overcomplications. You want simply `MOUNTDIR=$(hdiutil mount jdk-7u51-macos-x64.dmg | awk 'END {$1=$2=""; print $0}')` (though you should properly also avoid using all uppercase for your private variables). – tripleee Apr 26 '19 at 14:53
2

Let dmgFilePath be the variable containing the path of your dmg file.

Then you can try this :

$ MOUNTDEV=$(hdiutil mount $dmgFilePath | awk '/dev.disk/{print$1}')
$ MOUNTDIR="$(mount | grep $MOUNTDEV | awk '{$1=$2="";sub(" [(].*","");sub("^  ","");print}')"
$ sudo installer -pkg "${MOUNTDIR}/"*.pkg -target /
$ hdiutil unmount "$MOUNTDIR"

Tested on macOS High Sierra even if "$MOUNTDIR" contains one space.

SebMa
  • 4,037
  • 29
  • 39
  • It won't work if the mounted directory have spaces, for example: `/Volumes/Lamur Installer`. I get `Installer` instead. – Mateusz Szlosek Apr 26 '18 at 14:27
  • 1
    @MateuszSzlosek I had forgotten to mention the day I edited it according to your comment, I had fixed the space issue. It should work with space in the mounted directory – SebMa May 22 '19 at 17:21
0

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
Yosri
  • 31
  • 3
-2

Thank Mateusz Szlosek,

For me :

$ MOUNTDIR=$(echo `hdiutil mount /Users/valorisa/Downloads/VirtualBox\ 5.0.14\ Build\ 105127
/VirtualBox-5.0.14-105127-OSX.dmg | tail -1 | awk '{$1=$2=""; print $0}'` | xargs -0 echo) 
&& sudo installer -pkg "${MOUNTDIR}/"*.pkg -target /

Password:
installer: Package name is Oracle VM VirtualBox
installer: Upgrading at base path /
installer: The upgrade was successful.

Valorisa

valorisa
  • 11
  • 2