什么是MacPorts?

MacPorts是使用于Mac OS中第三方包管理工具。

MacPorts让你可以轻松编译、安装和管理开源软件。MacPorts可以分为两个核心部分:MacPort base和MacPorts ports。

每个MacPorts port都是一个Portfile,在这个文件中定义了这是什么应用、它的特性,安装它所需要的文件和指令。通过Portfile,你可以只执行一条命令就完成下载、编译和安装应用和库文件。通过MacPorts管理开源软件还有些其他的好处。例如:

  1. 为指定的port自动安装所有依赖包。

  2. 为安装的port提供卸载和升级功能。

  3. 将所有port限制在一个沙盒内,这样它就不会影响操作系统且不易崩溃。

  4. 让你可以为port预编译二进制的安装包,这样你就可以在其他地方快速安装该包而无需重新编译它的源代码。

MacPorts是在Mac OS X上开发的,但是它便于携带且可用于其他类Unix系统,尤其是BSD及其分支版本。

 

如何安装MacPorts?

1. 首先安装XCode。

    XCode是由苹果公司提供的开发包,它包含了编译器、代码库和其他用于开发Mac OS X应用的工具。

  你可以通过Mac App StoreApple developer website下载XCode,你也可以在网上搜索相关资源。(点击这里下载 XCode 5.1.dmg

  注意:请确保你的Mac OS X版本安装了和它匹配的最新的XCode,使用过期版本会造成port安装失败。另外需要注意的是在OS 10.6之前,XCode不是通过Mac OS X的Software Update Utility进行升级,在Mac OS X 10.7之后,它通过Mac App Store升级。

 

2. 安装MacPorts。

  如果你使用的是Mac OS X,你最好使用Mac OS X Package Installer来安装MacPorts,除非你不想将MacPorts安装到它的默认目录(/opt/local/)。 

  2.1. Mac OS X Package Installer

    Mac OS X Package Installer能自动安装MacPorts,设置shell environment,并且运行selfupdate命令来更新ports tree和MacPorts base。

    你可以从MacPorts download directory下载最新的MacPorts Installer。以下直接给出几个OS X版本用到的下载链接:

      a. OS X 10.7 Lion: MacPorts-2.2.1-10.7-Lion.pkg

      b. OS X 10.8 Mountain Lion: MacPorts-2.2.0-10.8-MountainLion.pkg

      c. OS X 10.9 Mavericks: MacPorts-2.2.1-10.9-Mavericks.pkg

    下载完成后,直接双击Package Installer执行默认安装即可,安装完毕后,打开一个新的终端,执行:

$ port version
Version: 2.2.1

    如果安装成功,则可以看见版本号,如果出现 command not found,可以尝试在这里(MacPorts and the Shell)查找原因。

 

3. 使用MacPorts。

  MacPorts port 命令是与MacPorts交互的主要手段。它用于更新Portfiles、MacPorts基础部件,安装和管理ports。

  3.1. help - 帮助命令。如果给出操作名称,则显示该操作的简要说明,如果没有给出操作名称,则显示port命令使用方法的基本说明。

$ port help
port
        [-bcdfknopqRstuvy] [-D portdir] [-F cmdfile] action [privopts] [actionflags]
        [[portname|pseudo-portname|port-url] [@version] [+-variant]... [option=value]...]...
    
Supported actions
------------------
activate, archive, archivefetch, build, cat, cd, checksum, clean, configure,
contents, deactivate, dependents, deps, destroot, dir, distcheck, distfiles,
dmg, dpkg, echo, edit, exit, extract, fetch, file, gohome, help, info,
install, installed, lint, list, livecheck, load, location, log, logfile,
mdmg, mirror, mpkg, notes, outdated, patch, pkg, platform, portpkg,
provides, quit, rdependents, rdeps, rev-upgrade, rpm, search, select,
selfupdate, setrequested, space, srpm, sync, test, unarchive, uninstall,
unload, unsetrequested, upgrade, url, usage, variants, version, work

Pseudo-portnames
----------------
Pseudo-portnames are words that may be used in place of a portname, and
which expand to some set of ports. The common pseudo-portnames are:
all, current, active, inactive, actinact, installed, uninstalled, outdated,
obsolete, requested, unrequested and leaves.
These pseudo-portnames expand to the set of ports named.

Pseudo-portnames starting with variants:, variant:, description:, depends:,
depends_lib:, depends_run:, depends_build:, depends_fetch:, depends_extract:,
portdir:, homepage:, epoch:, platforms:, platform:, name:, long_description:,
maintainers:, maintainer:, categories:, category:, version:, revision:, and
license: each select a set of ports based on a regex search of metadata
about the ports. In all such cases, a standard regex pattern following
the colon will be used to select the set of ports to which the
pseudo-portname expands.

Pseudo-portnames starting with depof:, rdepof:, dependentof:, and rdependentof:
select ports that are direct or recursive dependencies or dependents of the
following portname, respectively.

Portnames that contain standard glob characters will be expanded to the
set of ports matching the glob pattern.
    
Port expressions
----------------
Portnames, port glob patterns, and pseudo-portnames may be logically
combined using expressions consisting of and, or, not, !, (, and ).
    
For more information
--------------------
See man pages: port(1), macports.conf(5), portfile(7), portgroup(7),
porthier(7), portstyle(7). Also, see http://www.macports.org.
    
xaviermavericks:~ Xavier$ port help selfupdate
Usage: selfupdate --nosync

Upgrade MacPorts itself and run the sync target
View Code

相关文章: