Install dmg package on MAC OS from Terminal

耗尽温柔 提交于 2019-12-04 11:23:12

问题


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' 

回答1:


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 / 



回答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.




回答3:


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



来源:https://stackoverflow.com/questions/22934083/install-dmg-package-on-mac-os-from-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!