安裝 Ports 套件時下載原始碼常因網路速度成為瓶頸。以下提供三種實用加速方案,透過修改 /etc/make.conf 即可生效:
FETCH_ENV= "HTTP_PROXY=IP[:PORT]" # 若需驗證,追加: FETCH_ENV+= " HTTP_PROXY_AUTH=basic:*:user:password"
make fetch-recursive # 完成後將 /usr/ports/distfiles 整個目錄複製至目標機器
FETCH_CMD= wget FETCH_BEFORE_ARGS= -c -t 1 FETCH_AFTER_ARGS= DISABLE_SIZE=yes # 或合寫為: FETCH_CMD= wget -c -t 1 # 穿透 Proxy: FETCH_ENV= http_proxy=https://proxy.example.com:3128 FETCH_ENV= ftp_proxy=https://proxy.example.com:3128 # 或搭配 proxychains / runsocks (socks5) FETCH_CMD= proxychains wget # FETCH_CMD= runsocks wget
FETCH_CMD= axel FETCH_BEFORE_ARGS= -a FETCH_AFTER_ARGS= DISABLE_SIZE=yes # 或合寫: FETCH_CMD= axel -a # Proxy 設定同 wget
注意:若系統未安裝 wget/axel,請先 cd /usr/ports/ftp/wget (或 axel) && make install clean。
在 /etc/make.conf 加入以下內容(教育網範例,公網使用者請自行替換為就近鏡像):
MASTER_SITE_OVERRIDE= \ ftp://ftp2.tsinghua.edu.cn/mirror/FreeBSD/ports/distfiles/ \ ftp://freebsd.csie.nctu.edu.tw/pub/FreeBSD/ports/distfiles/ \ ftp://ftp.hk.freebsd.org/pub/FreeBSD/ports/distfiles/ \ ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/distfiles/
善用上述技巧,可大幅縮短 Ports 編譯安裝的等待時間。