1. 安装必要的软件
安装MacPorts需要先安装X11和Xcode,Lion系统已经默认安装好了X11,在Appstore里安装Xcode即可。
下载完Xcode之后,一般路径在/Application下,可以先将其拷出来,以备后续使用:
$ cp -a /Application/Xcode.app ~/soft
2. 安装MacPort,并安装
下载地址:https://distfiles.macports.org/MacPorts/,可以直接下载Lion下的最新版:https://distfiles.macports.org/MacPorts/MacPorts-2.1.1-10.7-Lion.pkg
如果MacPort出现新版本,可以直接通过如下命令进行更新:
$ sudo port -v selfupdate
添加MacPort到环境变量,vi ~/.bash_profile
export PATH=${PATH}:/opt/local/bin:/opt/local/sbin:/opt/local/share/man
3. 比如安装bash的自动补全软件:
$ sudo port install bash-completion
Error: No valid Xcode installation is properly selected.
Error: Please use xcode-select to select an Xcode installation:
Error: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer # version 4.3.2
Error: sudo xcode-select -switch /Users/zhaobinjie/soft/Xcode.app/Contents/Developer # version 4.3.2
错误解决方法,1)设置xcode-select的路径,2)安装命令行工具:
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
You can get Xcode from the Mac App Store as a free download. From within that (in the preferences | downloads) you can download and install the command line tools.
4. MacPort常用操作
查询安装的ports
$ port -qv install
当安装新的系统时,卸载安装的ports
$ sudo port -fp uninstall --follow-dependents installed
清除所有局部的构建
$ sudo port clean all
安装必须的ports
$ sudo port install portname +variant1 +variant2 …
5. 删除MacPorts:
#原版使用MacPorts安装过的软件在/opt/local目录下,删除之前最好查看下,心里有个数.
$ sudo port -f uninstall installed
$ sudo rm -rf \
/opt/local \
/Applications/DarwinPorts \
/Applications/MacPorts \
/Library/LaunchDaemons/org.macports.* \
/Library/Receipts/DarwinPorts*.pkg \
/Library/Receipts/MacPorts*.pkg \
/Library/StartupItems/DarwinPortsStartup \
/Library/Tcl/darwinports1.0 \
/Library/Tcl/macports1.0 \
~/.macports
Reference:
http://www.macports.org/install.php
http://hi.hiing.net/2011/06/use-homebrew-package-management.html