1

I need to install Java from command line. This is what I am trying:

hdiutil attach javaforosx.dmg
cd /Volumes/Java\ for\ OS\ X\ 2015-001/
sudo installer -pkg JavaForOSX.pkg -target "/"
sudo hdiutil detach hdiutil detach /Volumes/Java\ for\ OS\ X\ 2015-001/

It fails at the last step, with the error message:

hdiutil: couldn't unmount "disk2" - Resource busy

What more, if I now go to my desktop and manually try to eject the disk image that is showing up in regards to Java (right click -> Eject) it says I cannot eject it, the terminal is using it. I have to close the terminal and only then I am able to eject the disk.

How do I do it correctly from command line?

4

1 回答 1

2

You need to exit the image directory too. Probably if you change the cd to a pushd and then before doing a hdiutil detach just do a popd. This will get back to your working directory. So just change your script to something like:

hdiutil attach javaforosx.dmg
pushd /Volumes/Java\ for\ OS\ X\ 2015-001/
sudo installer -pkg JavaForOSX.pkg -target "/"
popd
sudo hdiutil detach /Volumes/Java\ for\ OS\ X\ 2015-001/

Also, note that if you have homebrew installed, you can use cask to install java from command line too. Like:

brew cask install java7

This will also take care of the download details and

于 2015-12-20T08:09:28.047 回答