Linux之所以如此流行,其原因之一就是其方便的软件管理,如yum、apt-get等。而Mac下面常用的安装方式为通过dmg、pkg包进行安装,作为unix的分支的Mac OS下面有没有apt-get、yum一样方便的软件管理工具呢?答案是肯定的,这就是本便要介绍的macports,其同BSD中的ports用法几乎一样。

其官方网站为:http://www.macports.org/install.php,这里提供有dmg安装、pkg安装和源码安装三种方式,dmg和pkg就不多说了,下载完成后,下一步下一步安装即可。目前的最新版本为2.1.2 。源码下载地址为: https://distfiles.macports.org/MacPorts/

源码安装具体步骤如下:

1wget http://distfiles.macports.org/MacPorts/MacPorts-2.1.2.tar.gz
2tar zxvf MacPorts-2.1.2.tar.gz
3cd MacPorts-2.1.2
4./configure && make && sudo make install
5cd ../
6rm -rf MacPorts-2.1.2*

其安装完成后,默认路径为/opt/local 。因些如果想直接使用该命令,需要通过设置$PATH生效。如下:

1vim /etc/profile
2export PATH=/opt/local/bin:$PATH
3export PATH=/opt/local/sbin:$PATH

MacPorts使用
更新ports tree和MacPorts版本,强烈推荐第一次运行的时候使用-v参数,显示详细的更新过程。

1sudo port -v selfupdate

搜索索引中的软件

1port search name

安装新软件

1sudo port install name

卸载软件

1sudo port uninstall name

查看有更新的软件以及版本

1port outdated

升级可以更新的软件

1sudo port upgrade outdated

以wget的安装为例,如下:

 1macmatoMacBook-Pro:bin yang$ sudo port -v selfupdate
 2Password:
 3--->  Updating MacPorts base sources using rsync
 4receiving file list ... done
 5sent 36 bytes  received 69 bytes  30.00 bytes/sec
 6total size is 3543040  speedup is 33743.24
 7receiving file list ... done
 8sent 36 bytes  received 76 bytes  24.89 bytes/sec
 9total size is 512  speedup is 4.57
10MacPorts base version 2.1.2 installed,
11MacPorts base version 2.1.2 downloaded.
12--->  Updating the ports tree
13Synchronizing local ports tree from rsync://rsync.macports.org/release/tarballs/ports.tar
14receiving file list ... done
15sent 36 bytes  received 70 bytes  23.56 bytes/sec
16total size is 54691840  speedup is 515960.75
17receiving file list ... done
18sent 36 bytes  received 77 bytes  25.11 bytes/sec
19total size is 512  speedup is 4.53
20Creating port index in /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports
21Total number of ports parsed:   0
22Ports successfully parsed:  0
23Ports failed:           0
24Up-to-date ports skipped:   15923
25--->  MacPorts base is already the latest version
26The ports tree has been updated. To upgrade your installed ports, you should run
27  port upgrade outdated
28macmatoMacBook-Pro:bin yang$ port search wget
29gwget @1.0.4 (gnome, net)
30    Gwget is a Download Manager for Gnome 2. It uses wget as a backend.
31wget @1.14 (net, www)
32    internet file retriever
33wgetpro @0.1.3 (net, www)
34    advanced internet file retriever
35wput @0.6.2 (net)
36    wput is like wget but is for uploading files to ftp-servers
37Found 4 ports.
38macmatoMacBook-Pro:bin yang$ sudo port install wget
39--->  Computing dependencies for wget
40--->  Dependencies to be installed: gettext expat libiconv ncurses gnutls libgcrypt libgpg-error libtasn1 lzo2 readline libidn
41--->  Fetching archive for expat
42--->  Attempting to fetch expat-2.1.0_0.darwin_10.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/expat
43--->  Attempting to fetch expat-2.1.0_0.darwin_10.x86_64.tbz2.rmd160 from http://mse.uk.packages.macports.org/sites/packages.macports.org/expat
44--->  Installing expat @2.1.0_0
45--->  Activating expat @2.1.0_0
46--->  Cleaning expat
47--->  Fetching archive for libiconv
48--->  Attempting to fetch libiconv-1.14_0.darwin_10.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/libiconv
49………………

Eclipse的插件需要subclipse需要JavaHL,下面通过MacPorts来安装

1sudo port install subversion-javahlbindings

注:MacPorts的安装需要xcode的支持,xcode for mac os x 10.6.5的下载地址