Free yourself from fixing complex.
eleven

大部分mac软件包是以磁盘镜像的形式分发的,有些情境(如SSH)没办法用Gui界面,这个时候可以使用命令行来安装这些软件包。

  • 挂载dmg镜像:

     

    hdiutil mount /pathto/command.dmg

     

    命令行输出输出如下:

     

    [cc lang="bash"]
    expected CRC32 $D8B326FA
    /dev/disk1 Apple\_partition\_scheme
    /dev/disk1s1 Apple\_partition\_map
    /dev/disk1s2 Apple\_HFS /Volumes/Command Line Tools (Mountain Lion)
    [/cc]

  • 安装应用:

     

    由于mac系统的特性,你只需要简单地把以 .app 结尾的东西复制到/Applications目录就可以了。 
    sudo cp -R "Volumes/something/something.app" /Applications

     

    .app文件实际上是一个文件夹,所以这里用到了 -R 递归复制。

     

    有些软件只提供了mpkg格式的安装包,例如本例中的Command Line Tools,这个时候需要用到: 
    sudo installer -package /Volumes/Command\ Line\ Tools\ (Mountain\ Lion)/Command\ Line\ Tools\ (Mountain\ Lion).mpkg -target /Volumes/Root 
    -target 指明安装位置,一般就是你的Mac OSX的安装磁盘。

  • 卸载镜像: 
    hdiutil unmount "/Volumes/Command Line Tools (Mountain Lion)"
2013-05-17