Macports拓展于BSD系统的port命令,机制和架构较为传统更加类似于Linux下的yum和apt-get,不如HomeBrew复杂,因此简介如下:
MacPorts Install
安装MacPorts可以选择下载pkg安装包进行安装也可以下载源码包自行编译安装,可参考guide https://guide.macports.org/#installing.macports
注意Macports需要xcode的相关支持,因此需保证以下组件在系统中安装:
如果选择pkg安装包进行安装较为简单,这里选择编译源码包的方式安装,命令如下:
$ tar xf MacPorts-2.4.1.tar.bz2
$ cd MacPorts-2.4.1/
$ ./configure
$ make
$ sudo make install
该流程是常规的make脚本实现的源码编译安装,因此不多做解释,脚本默认建立/opt/local
作为MacPorts程序的根目录,通过MacPorts安装的软件也部署在该路径下,因此MacPorts的架构独立于系统存在,该特性的优势在于程序文件集中,不会扰乱系统,甚至卸载可以通过直接remove掉该目录实现;而缺陷在于安装软件包时并不使用系统本身具有的library,导致需要安装的依赖包较多,占用较大的磁盘空间。
安装完毕后,为了便于以后直接在terminal中调用程序和使用man page,需要将bin,sbin和man的路径添加到PATH变量中,可以在home目录下新建~/.profile
文件,编辑添加以下命令
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
MacPorts Uninstall
因为MacPorts文件系统较为独立,因此卸载MacPorts较为简单,可参考guide https://guide.macports.org/#installing.macports.uninstalling,首先uninstall所有已经安装的ports,命令如下
sudo port -fp uninstall installed
然后在删除所有可能跟MacPorts有关系的文件和文件夹,命令如下
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
这样MacPorts就彻底的从系统中移除掉了。
MacPorts Mechanism
本质上讲,MacPorts在架构上分为两个部分:MacPorts-base和Macports-ports,base是MacPorts的执行程序,GitHub地址是https://github.com/macports/macports-base,该repo下维护的是执行程序的源码,而ports是描述软件包的portfile文件集合,GitHub地址是https://github.com/macports/macports-ports,该repo下维护的是MacPorts所能安装所有软件包的描述文件。
在MacPorts的概念里update也相应的对应两个action,针对执行程序(base)的update和针对portfiles(ports)的update,每次ports更新后MacPorts都建立新的port index便于软件包的查找与安装。
MacPorts architecuture:
/opt/local/ -> default macports location
/opt/local/etc/macports/macports.conf -> base setting
/opt/local/etc/macports/sources.conf -> ports setting
/opt/local/var/macports/sources/ -> database directory which holds the sources update for the ports tree (the Portfiles) and also MacPorts base.
/opt/local/var/macports/software/ -> directory stored tar-type package
MacPorts的文件架构如上所示,macports.conf通过rsync_server
和rsync_dir
字段定义base fetch源;
# The rsync server for fetching MacPorts base during selfupdate. This
# setting is NOT used when downloading ports trees; ports trees are
# configured using the file referenced by sources_conf. See
# https://trac.macports.org/wiki/Mirrors#MacPortsSource for a list of
# available servers.
#rsync_server rsync.macports.org
#
# Location of MacPorts base sources on rsync_server. If this references
# a .tar file, a signed .rmd160 file must exist in the same directory
# and will be used to verify its integrity. See
# https://trac.macports.org/wiki/Mirrors#MacPortsSource to find the
# correct rsync_dir for a particular rsync_server.
#rsync_dir macports/release/tarballs/base.tar
source.conf通过file://
定义local ports源,通过rsync://
定义remote ports源;
# To add a local source, add a "file://" entry.
#
# Example: file:///Users/landonf/misc/MacPorts/ports
#
# A list of rsync mirrors is available at
# https://trac.macports.org/wiki/Mirrors#Portfiles.
#
# If an "rsync://" URL points to a .tar file, a signed .rmd160 file must
# exist in the same directory on the server and will be used to verify
# its integrity.
#
# For proper functionality of various resources (port groups, mirror
# sites, etc.), the primary MacPorts source must always be tagged
# "[default]", even if switched from the default "rsync://" URL.
rsync://rsync.macports.org/macports/release/tarballs/ports.tar [default]
在MacPorts中存在四类源(source),分别是MacPorts base source,Portfiles source,distfiles source(source code),archives source(package),可参考官方镜像页面 https://trac.macports.org/wiki/Mirrors
其中前两类分别在对应的conf文件中定义,后两类则由MacPorts程序从镜像列表中自动选择,摘录镜像页面对各源的描述。
MacPorts Source
MacPorts is updated during port selfupdate by checking the version on the rsync server. You can point your installation at a closer mirror listed below by changing the two options, rsync_server and rsync_dir, in ${prefix}/etc/macports/macports.conf.
Portfiles
Portfiles are normally retrieved with port sync or port selfupdate. The URL used to get Portfiles is set in ${prefix}/etc/macports/sources.conf.
Distfiles
Distfiles (“distribution files”) contain the source code for ports. They are usually retrieved from the project’s site or one of their mirrors. The MacPorts project further mirrors the distfiles in one location. The following mirrors are queried automatically by MacPorts.
Archives
Archives contain pre-built installations of ports. The following mirrors are queried automatically by MacPorts.
Port Command
port command
port help; port help
sudo port -v sync(ports tree); sudo port -v selfupdate(ports tree & MacPorts base)
port list(all of ports tree); port search - ; port info
sudo port install ; sudo port clean (usually used for compile failed); sudo port uninstall ; sudo port upgrade outdated
port contents ; port installed
Change Source
更换中科大MacPorts源可参考该链接 https://www.leg.uct.ac.za/mirrors/packages/macports
更换MacPorts Base源可编辑/opt/local/etc/macports/macports.conf文件更改以下内容:
rsync_server ftp.leg.uct.ac.za
rsync_dir pub/packages/macports/release/base/
更换Profiles源可编辑/opt/local/etc/macports/sources.conf文件更改以下内容:
rsync://ftp.leg.uct.ac.za/pub/packages/macports/release/ports/ [default]
执行以下命令使用更改配置更新base和protfiles
$ sudo port -v sync
$ sudo port -v selfupdate