FreeBSD 中文社区 2025 第二季度问卷调查
FreeBSD 中文社区(CFC)
VitePress 镜像站QQ 群 787969044视频教程Ⅰ视频教程Ⅱ
  • FreeBSD 操作系统研究导论
  • 中文期刊
  • 状态报告
  • 发行说明
  • 手册
  • 网络文章集锦
  • 笔记本支持报告
  • Port 开发者手册
  • 架构手册
  • 开发者手册
  • 中文 man 手册
  • 文章与书籍
  • UNIX 四分之一世纪
  • Unix 痛恨者手册
  • FreeBSD 操作系统研究导论(第三版:草稿)
  • 编辑日志
  • 贡献指南与开放任务
  • 目录
  • 前言
    • 致读者
    • 致谢
    • 初版序言:好望角与塔吊
    • 再版序言:回到复制粘贴,面向教程本身
    • 三版序言:且有大觉而后知此其大梦也(草稿)
    • 本书的组织结构
    • 本书中使用的一些约定
  • 第 1 章 FreeBSD 初见
    • 1.1 操作系统的历程:UNIX、BSD 和 Linux
    • 1.2 欢迎来到 FreeBSD
    • 1.3 关于 FreeBSD 项目
    • 1.4 George Berkeley(乔治·贝克莱)与 BSD 命名的文化背景
    • 1.5 加州大学伯克利分校和“Fiat Lux”(要有光)
  • 第 2 章 安装 FreeBSD
    • 2.1 安装前的准备工作
    • 2.2 使用 bsdinstall 开始安装
    • 2.3 键盘布局和主机名
    • 2.4 选择安装组件
    • 2.5 分配磁盘空间
    • 2.6 设置 root 密码
    • 2.7 网络设置
    • 2.8 时区、服务、安全、固件和账户
    • 2.9 完成安装
    • 2.10 故障排除
  • 第 3 章 FreeBSD 基础
    • 3.1 Windows 用户迁移指南
    • 3.2 Linux 用户迁移指南
    • 3.3 虚拟控制台和终端
    • 3.4 认识 shell
    • 3.5 命令行基础
    • 3.6 文本编辑器
    • 3.7 用户和基本账户管理
    • 3.8 权限
    • 3.9 sudo 和 doas
    • 3.10 文件系统的挂载和卸载
    • 3.11 磁盘结构
    • 3.12 目录结构
  • 第 4 章 软件管理和系统升级
    • 4.1 FreeBSD 镜像站现状
    • 4.2 更换 FreeBSD 软件源
    • 4.3 gitup 的用法
    • 4.4 使用 pkg 管理二进制包
    • 4.5 使用 Ports 以源代码方式安装软件
    • 4.6 使用 DVD 安装软件
    • 4.7 使用 freebsd-update 更新 FreeBSD
    • 4.8 使用源代码更新 FreeBSD
    • 4.9 使用 pkgbase 更新 FreeBSD
  • 第 5 章 桌面环境
    • 5.1 Intel 和 AMD 显卡驱动
    • 5.2 NVIDIA 显卡驱动
    • 5.3 KDE6
    • 5.4 GNOME
    • 5.5 Mate
    • 5.6 Xfce
    • 5.7 Cinnamon
    • 5.8 Lumina
    • 5.9 LXQt
    • 5.10 Budgie
    • 5.11 CDE
    • 5.12 LXDE
    • 5.13 主题美化
    • 5.14 远程桌面
    • 5.15 启用 root 桌面登录
  • 第 6 章 本地化——i18n/L10n
    • 6.1 本地化环境变量
    • 6.2 Fcitx 输入法框架
    • 6.3 IBus 输入法框架
    • 6.4 五笔输入法
    • 6.5 网络浏览器
    • 6.6 QQ(Linux 版)
    • 6.7 更换字体
    • 6.8 金山 WPS(Linux 版)
    • 6.9 压缩和解压
    • 6.10 微信(Linux 版)
  • 第 7 章 多媒体和外部设备
    • 7.1 音频设备配置
    • 7.2 蓝牙
    • 7.3 打印机
    • 7.4 触摸板
    • 7.5 音频播放器
    • 7.6 视频播放器
    • 7.7 多媒体处理工具
  • 第 8 章 代理服务器
    • 8.1 HTTP 代理
    • 8.2 V2ray
    • 8.3 Mihomo(原 Clash)
    • 8.4 OpenVPN
  • 第 9 章 Jail
    • 9.1 配置 Jail
    • 9.2 更新 jail
    • 9.3 使用 Qjail 管理 Jail
    • 9.4 Linux Jail
  • 第 10 章 虚拟化和容器
    • 10.1 通过 BVCP 以网页管理 BHyve
    • 10.2 使用 bhyve 安装 Windows 11(vm-bhyve)
    • 10.3 Podman
    • 10.4 在 FreeBSD 上安装 VirtualBox
  • 第 11 章 FreeBSD 安装实践
    • 11.1 使用 Hyper-V 安装 FreeBSD
    • 11.2 使用 VMware Workstation Pro 安装 FreeBSD
    • 11.3 使用 Virtual Box 安装 FreeBSD
    • 11.4 手动安装双系统(先安装 FreeBSD)
    • 11.5 手动安装双系统(后安装 FreeBSD)
    • 11.6 基于 Apple M1 & Parallels Desktop 20 安装 FreeBSD
    • 11.7 基于 Apple M1 & VMware Fusion Pro 安装 FreeBSD
    • 11.8 使用 Qemu 安装 RISC-V FreeBSD(基于 x86 Windows)
    • 11.9 云服务器安装 FreeBSD(基于腾讯云轻量云)
    • 11.10 配置 rEFInd(双系统用)
  • 第 12 章 窗口管理器
    • 12.1 bspwm
    • 12.2 IceWM
    • 12.3 i3wm
    • 12.4 Hyprland
    • 12.5 Window Maker
    • 12.6 Fluxbox
  • 第 13 章 FreeBSD 系统管理
    • 13.1 引导界面和虚拟控制台
    • 13.2 管理 FreeBSD 中的服务
    • 13.3 bsdconfig 系统配置工具
    • 13.4 SSH 配置和相关工具
    • 13.5 单用户模式和密码重置
    • 13.6 Grub、UEFI 和 efibootmgr
  • 第 14 章 网络管理
    • 14.1 设置网络
    • 14.2 无线网络
    • 14.3 USB 网络共享(USB tethering)
    • 14.4 TCP 堆栈
  • 第 15 章 FreeBSD 防火墙
    • 15.1 Fail2Ban(基于 IPFW、PF、IPF)
    • 15.2 Packet Filter(PF)
    • 15.3 IPFilter(IPF)
    • 15.4 ipfirewall(IPFW)
  • 第 16 章 服务器
    • 16.1 FTP 服务器
    • 16.2 MinIO 对象存储服务
    • 16.3 Gitlab-EE
    • 16.4 时间服务
    • 16.5 WildFly
    • 16.6 Rsync 同步服务
    • 16.7 Samba 服务器
    • 16.8 NFS 服务器
    • 16.9 Webmin
  • 第 17 章 Web 服务器和监控平台
    • 17.1 Apache
    • 17.2 Nginx
    • 17.3 PHP 8.X
    • 17.4 Zabbix 监控(基于 PostgreSQL)
    • 17.5 NextCloud——基于 PostgreSQL
    • 17.6 Telegraf+InfluxDB+Grafana 监控平台
    • 17.7 AList
    • 17.8 Prometheus 监控部署
    • 17.9 Tomcat
    • 17.10 Caddy
    • 17.11 OnlyOffice(基于 PostgreSQL)
  • 第 18 章 嵌入式平台
    • 18.1 树莓派简介
    • 18.2 树莓派安装 FreeBSD
    • 18.3 树莓派 FreeBSD 配置
    • 18.4 树莓派和 Linux 兼容层
    • 18.5 Radxa X4(x86)
  • 第 19 章 数据库管理
    • 19.1 PostgreSQL
    • 19.2 pgAdmin4
    • 19.3 MySQL 5.X
    • 19.4 MySQL 8.X
    • 19.5 MongoDB 8.0
  • 第 20 章 游戏、科学计算和专业工具
    • 20.1 游戏
    • 20.2 我的世界(Minecraft)
    • 20.3 科研和专业工具
  • 第 21 章 Linux 二进制兼容层
    • 21.1 Linux 兼容层实现
    • 21.2 RockyLinux 兼容层(FreeBSD Port)
    • 21.3 Ubuntu/Debian 兼容层
    • 21.4 ArchLinux 兼容层(基于 ArchLinux bootstrap)
    • 21.5 ArchLinux 兼容层(基于 archlinux-pacman)
    • 21.6 OpenSUSE 兼容层
    • 21.7 Gentoo Linux 兼容层
    • 21.8 Rocky Linux 兼容层
    • 21.9 Slackware Linux 兼容层
    • 21.10 Deepin 兼容层
    • 21.11 故障排除与未竟事宜
  • 第 22 章 开发生态与贡献社区
    • 22.1 如何报告 Bug
    • 22.2 如何开发一个 Port
    • 22.3 如何参与 FreeBSD 开发
    • 22.4 C/C++ 环境的配置
    • 22.5 Java 环境的配置
    • 22.6 QT 环境的配置
    • 22.7 Python 和 VS Code
    • 22.8 Rust/Go 环境的配置
    • 22.9 配置 Shell
    • 22.10 通过 IDA 7 调试 FreeBSD
    • 22.11 如何订阅 FreeBSD 的邮件列表
    • 22.12 code-server 和 clangd
    • 22.13 Node.js
    • 22.14 利用脚本自动生成 BSDlibc 库文本
  • 第 23 章 存储管理和文件系统
    • 23.1 自动挂载文件系统
    • 23.2 ZFS 文件系统
    • 23.3 磁盘扩容和分区调整
    • 23.4 Windows 文件系统
    • 23.5 Swap 交换分区的设置
    • 23.6 Linux 文件系统
  • 第 24 章 DragonFly BSD 入门
    • 24.1 DragonFly BSD 概述
    • 24.2 安装 DragonFly BSD
    • 24.3 配置 DragonFly BSD
  • 第 25 章 TwinCAT/BSD 入门
    • 25.1 TwinCAT/BSD 系统安装和基本配置
    • 25.2 TwinCAT/BSD 开发环境配置
  • 第 26 章 OpenBSD 入门
    • 26.1 OpenBSD 概述
    • 26.2 安装 OpenBSD
    • 26.3 配置 OpenBSD
    • 26.4 OpenBSD 包管理器
    • 26.5 桌面和其他软件
    • 26.6 在 RISC-V 开发板上安装 OpenBSD
    • 26.7 树莓派和 OpenBSD
  • 第 27 章 NetBSD 入门
    • 27.1 NetBSD 概述
    • 27.2 NetBSD 安装图解
    • 27.3 NetBSD 换源和包管理器
    • 27.4 桌面和中文环境常用软件
  • 附录 Ⅰ 计算机概论
    • 存储卡简介
    • 总线接口与协议
    • 网络基础
    • 操作系统
    • MySQL 数据库
  • 附录 Ⅱ 工具与资源
    • 适用于 FreeBSD 的以太网卡、USB 以太网卡和 USB 无线网卡
    • FreeBSD 桌面发行版评述
    • BSD 许可证概览
  • 附录 Ⅲ 文学故事
    • 我与 FreeBSD 的故事
    • 两次告别
    • 小说:大教堂与集市
    • 小说:吾乡何处
    • 小说:你与暗
    • 诗歌选
    • 杂记
  • 附录 Ⅳ 参考文献和术语
    • 参考书目
    • 术语表
由 GitBook 提供支持
LogoLogo

FreeBSD 中文社区(CFC) 2025

在本页
  • 使用 ports 压缩包
  • 下载 ports 压缩包
  • 解压 ports 压缩包
  • 使用 Git 获取 Ports
  • 安装 Git
  • 拉取 Ports 存储库(USTC)浅克隆
  • 拉取 Ports 存储库(FreeBSD 官方)浅克隆
  • 完全拉取 Ports 存储库(FreeBSD 官方)并指定分支
  • 同步更新 Ports Git
  • 故障排除与未竟事宜
  • 使用 whereis 查询软件路径
  • 查看依赖
  • 看看 python 的 ports 在哪
  • 安装 python3
  • 如何设置全部所需的依赖
  • 如何使用 pkg 安装依赖
  • 如何删除当前 port 及其依赖的配置文件
  • 如何一次性下载所有需要的软件包
  • ports 编译的软件也可以转换为 pkg 包
  • 更新 FreeBSD 软件包/Port
  • ① portmaster(推荐)
  • ② portupgrade
  • FreeBSD USE
  • FreeBSD ports 多线程编译
  • 参考资料
  • 设置内存为 tmp
  • 参考资料
  • ccache
  • ccache3
  • ccache4
  • 参考文献
  • 多线程下载
  • axel
  • wget2
  • 参考文献
在GitHub上编辑
导出为 PDF
  1. 第 4 章 软件管理和系统升级

4.5 使用 Ports 以源代码方式安装软件

一款软件的相关文件或文件夹的(补丁文件、校验码、Makefile 等)集合(表现为一个文件夹)为一个 Port,所有 Port(移植软件)的集合即 Ports Collection,即 Ports。

NetBSD 和 OpenBSD 也使用 Ports(不通用)。

注意

ports 和 pkg 可以同时使用,而且大部分人也是这么用的。但是要注意 pkg 的源必须是 latest,否则会存在一些依赖上的问题(比如 ssl)。latest 的源也比主线上的 ports 要出来的晚(是从中编译出来的),因此即使是 latset 源也可能会出现上述问题,总之有问题出现时就卸载那个 pkg 安装的包,重新使用 ports 编译即可。

技巧

ports 下载路径是 /usr/ports/distfiles/。

使用 ports 压缩包

使用压缩包成功地规避了先有鸡还是先有蛋的哲学问题(要安装 Git 但是没有 Ports 也不想用 pkg 的话)。

下载 ports 压缩包

  • NJU:

# fetch https://mirrors.nju.edu.cn/freebsd-ports/ports.tar.gz
  • 或 USTC

# fetch https://mirrors.ustc.edu.cn/freebsd-ports/ports.tar.gz
  • 又或 FreeBSD 官方

# fetch https://download.freebsd.org/ftp/ports/ports/ports.tar.gz

解压 ports 压缩包

# tar -zxvf ports.tar.gz -C /usr/ # 解压至路径
# rm ports.tar.gz # 删除存档

使用 Git 获取 Ports

安装 Git

  • 使用 pkg 安装:

# pkg install git

拉取 Ports 存储库(USTC)浅克隆

# git clone --filter=tree:0 https://mirrors.ustc.edu.cn/freebsd-ports/ports.git /usr/ports

拉取 Ports 存储库(FreeBSD 官方)浅克隆

# git clone --filter=tree:0 https://git.FreeBSD.org/ports.git /usr/ports

完全拉取 Ports 存储库(FreeBSD 官方)并指定分支

# git clone https://git.FreeBSD.org/ports.git /usr/ports

查看所有分支:

# cd /usr/ports/ # 切换到 git 项目
# git branch -a
* main # * 代表当前分支
  remotes/origin/2014Q1

	……省略…………

  remotes/origin/2025Q1
  remotes/origin/HEAD -> origin/main
  remotes/origin/main

切换到 2025Q1 分支:

root@ykla:/usr/ports # git switch 2025Q1
正在更新文件: 100% (14323/14323), 完成.
分支 '2025Q1' 设置为跟踪 'origin/2025Q1'。
切换到一个新分支 '2025Q1'

查看本地分支:

root@ykla:/usr/ports # git branch
* 2025Q1
  main

已经切换成功。

同步更新 Ports Git

root@ykla:/ # cd /usr/ports/ # 切换目标目录
root@ykla:/usr/ports # git pull # 同步更新上游 Ports

如果提示本地已经修改,放弃本地修改,再更新:

root@ykla:/usr/ports # git checkout . # 放弃本地修改
root@ykla:/usr/ports # git pull

故障排除与未竟事宜

fatal: unable to access 'https://mirrors.ustc.edu.cn/freebsd-ports/ports.git/': SSL certificate problem: certificate is not yet valid

先检查时间:

# date
Fri May 31 12:09:26 UTC 2024

时间错误。校对时间:

# ntpdate -u pool.ntp.org
 5 Oct 08:39:16 ntpdate[3276]: step time server 202.112.29.82 offset +10960053.088901 sec

检查时间:

# date
Sat Oct  5 08:39:21 UTC 2024

使用 whereis 查询软件路径

如

# whereis python

将输出

python: /usr/ports/lang/python

查看依赖

已经安装:

root@ykla:~ # pkg info -d screen
screen-4.9.0_6:
	indexinfo-0.3.1

未安装:

root@ykla:/usr/ports/sysutils/htop # make all-depends-list
/usr/ports/ports-mgmt/pkg
/usr/ports/devel/pkgconf
/usr/ports/devel/kyua
……省略一部分……

看看 python 的 ports 在哪

# whereis python
# python: /usr/ports/lang/python

安装 python3

# cd /usr/ports/lang/python
# make BATCH=yes clean

其中 BATCH=yes 意味着使用默认参数进行编译。

如何设置全部所需的依赖

# make config-recursive

如何使用 pkg 安装依赖

不使用 Ports 来编译依赖,仅使用 Ports 来编译软件包本体:

# make install-missing-packages

以 chinese/fcitx 为示例:

root@ykla:~ # cd /usr/ports/chinese/fcitx
root@ykla:/usr/ports/chinese/fcitx # make install-missing-packages
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
Updating FreeBSD-base repository catalogue...
FreeBSD-base repository is up to date.
All repositories are up to date.
Updating database digests format: 100%
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	e2fsprogs-libuuid: 1.47.1 [FreeBSD]
	enchant2: 2.2.15_5 [FreeBSD]

Number of packages to be installed: 2

94 KiB to be downloaded.

Proceed with this action? [y/N]: 

如何删除当前 port 及其依赖的配置文件

# make rmconfig-recursive

如何一次性下载所有需要的软件包

# make BATCH=yes fetch-recursive

ports 编译的软件也可以转换为 pkg 包

# pkg create nginx

更新 FreeBSD 软件包/Port

先同步更新 Ports Git。

然后列出过时 Port 软件:

root@ykla:/usr/ports # pkg version -l '<'
chromium-127.0.6533.99             <
curl-8.9.1_1                       <
ffmpeg-6.1.2,1                     <
vlc-3.0.21_4,4                     <
w3m-0.5.3.20230718_1               <

下边分别列出 2 种 FreeBSD 手册中提及的升级工具:

① portmaster(推荐)

  • 更新:

# cd /usr/ports/ports-mgmt/portmaster && make install clean
# portmaster -a #自动升级所有软件
# portmaster screen #升级单个软件

如果不想回答问题解决依赖,可使用类似 BATCH=yes 的选项 -a -G --no-confirm:

# portmaster -a -G --no-confirm

查看依赖关系

root@ykla:/usr/ports/ports-mgmt/portmaster # portmaster sysutils/htop  --show-work

===>>> Port directory: /usr/ports/sysutils/htop

===>>> Starting check for all dependencies
===>>> Gathering dependency list for sysutils/htop from ports

===>>> Installed devel/autoconf
===>>> Installed devel/automake
===>>> NOT INSTALLED		devel/libtool
===>>> NOT INSTALLED		devel/pkgconf
===>>> NOT INSTALLED		lang/python311
===>>> Installed ports-mgmt/pkg

② portupgrade

# cd /usr/ports/ports-mgmt/portupgrade && make install clean
# portupgrade -ai #自动升级所有软件,i 会挨个确认
# portupgrade -R screen #升级单个软件
# portupgrade -a --batch		#不要问,只做,等同于  BATCH=yes

参考资料

  • portmaster -- manage your ports without external databases or languages

  • portupgrade, portinstall -- tools to upgrade installed packages or in- stall new ones via ports or packages

FreeBSD USE

  • 如何全局屏蔽 mysql

# echo "OPTION_UNSET+= MYSQL" >> /etc/make.conf

完整的列表见 https://cgit.freebsd.org/ports/tree/Mk/bsd.default-versions.mk

FreeBSD ports 多线程编译

将以下内容写入 /etc/make.conf,没有就 touch 新建一个。

FORCE_MAKE_JOBS=yes
MAKE_JOBS_NUMBER=4

Linux 如 Gentoo 上一般是直接 -jx 或者 jx+1, x 为核心数。

4 是处理器核心数(还是线程数?)。

可以通过命令查询:

root@ykla:/home/ykla # sysctl kern.smp.cpus
kern.smp.cpus: 16

或者:

root@ykla:/home/ykla # sysctl hw.ncpu 
hw.ncpu: 16

输出值即为 MAKE_JOBS_NUMBER 值。

英特尔的处理器搜索 CPU 型号+ARK 转跳英特尔官网可查询线程数。

  • 个别情况下可以设置别名加速编译:(非永久设置,FreeBSD 14 无须设置默认即生效)

# alias ninja='ninja -j4'

参考资料

  • Easy way to get cpu features,获取 CPU 线程数量的命令来自此处。

设置内存为 tmp

# ee /etc/fstab

写入:

tmpfs /tmp tmpfs rw 0 0

reboot 重启即可。

参考资料

  • tmpfs --in-memory file system

ccache

警告

使用 ccache 可能会导致编译失败!只在重复编译时起效果,首次编译不仅不会加速还会慢上一些。是一种以空间换时间的行为。

ccache3

使用 pkg 安装:

root@ykla:~ # pkg install ccache
  • 使用 Ports 安装:

# cd /usr/ports/devel/ccache/ 
# make install clean
  • 查看软链接情况:

root@ykla: # ls -al  /usr/local/libexec/ccache
total 56
drwxr-xr-x   3 root wheel 15 Sep 20 02:02 .
drwxr-xr-x  18 root wheel 49 Sep 20 01:39 ..
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 CC -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 c++ -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 cc -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 clang -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 clang++ -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 clang++15 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 02:02 clang++18 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 clang15 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 02:02 clang18 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 cpp13 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 g++13 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21 Sep 20 00:29 gcc13 -> /usr/local/bin/ccache
drwxr-xr-x   2 root wheel 15 Sep 20 02:02 world

  • 修改 /etc/make.conf,加入下面一行:

WITH_CCACHE_BUILD=yes
  • 设置编译缓存最大为 10GB:

root@ykla:/usr/ports/devel/ccache4 # ccache -M 10G  
Set cache size limit to 10.0 GB
root@ykla:/usr/ports/www/chromium # ccache -s
cache directory                     /root/.ccache
primary config                      /root/.ccache/ccache.conf
secondary config      (readonly)    /usr/local/etc/ccache.conf
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
cache hit rate                      0.00 %
cleanups performed                     0
files in cache                         0
cache size                           0.0 kB
max cache size                      10.0 GB
  • 在 Ports 编译一段时间后:

root@ykla:~ # ccache -s
cache directory                     /root/.ccache
primary config                      /root/.ccache/ccache.conf
secondary config      (readonly)    /usr/local/etc/ccache.conf
stats updated                       Fri Sep 20 02:05:35 2024
cache hit (direct)                    20
cache hit (preprocessed)              17
cache miss                           918
cache hit rate                      3.87 %
called for link                      121
called for preprocessing              26
compile failed                       115
preprocessor error                    66
bad compiler arguments                15
autoconf compile/link                523
no input file                         71
cleanups performed                     0
files in cache                      2305
cache size                           0.0 kB
max cache size                      10.0 GB

ccache4

目前最新版本是 ccache4:

使用 pkg 安装:

# pkg install ccache4

或使用 Ports 安装:

# cd /usr/ports/devel/ccache4/
# make install clean
  • 查看软链接情况:

root@ykla:~ # ls -al  /usr/local/libexec/ccache    total 55
drwxr-xr-x   3 root wheel 13  9月 20 02:29 .
drwxr-xr-x  20 root wheel 54  9月 20 02:29 ..
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 c++ -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 cc -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 CC -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 clang -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 clang++ -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 clang++15 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 clang15 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 cpp13 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 g++13 -> /usr/local/bin/ccache
lrwxr-xr-x   1 root wheel 21  9月 20 02:29 gcc13 -> /usr/local/bin/ccache
drwxr-xr-x   2 root wheel 13  9月 20 02:29 world

  • 修改 /etc/make.conf,加入下面一行:

WITH_CCACHE_BUILD=yes
  • 设置编译缓存最大为 20GB:

root@ykla: # ccache -M 20G  
Set cache size limit to 20.0 GB
  • 在 Ports 编译一段时间后,查看编译缓存:

root@ykla:/ # ccache -s
Cacheable calls:   558 /  579 (96.37%)
  Hits:            110 /  558 (19.71%)
    Direct:        110 /  110 (100.0%)
    Preprocessed:    0 /  110 ( 0.00%)
  Misses:          448 /  558 (80.29%)
Uncacheable calls:  21 /  579 ( 3.63%)
Local storage:
  Cache size (GB): 0.0 / 20.0 ( 0.11%)
  Hits:            110 /  558 (19.71%)
  Misses:          448 /  558 (80.29%)

查看当前配置文件:

root@ykla:~ # ccache -p 
(default) absolute_paths_in_stderr = false
(default) base_dir =
(default) cache_dir = /root/.cache/ccache
……省略一部分……

参考文献

  • ccache-howto-freebsd.txt.in

  • ccache -a fast C/C++ compiler cache

多线程下载

axel

安装:

# pkg install axel

或者

# cd /usr/ports/ftp/axel/
# make install clean

新建或者编辑 /etc/make.conf 文件,写入以下几行:

FETCH_CMD=axel
FETCH_BEFORE_ARGS= -n 10 -a
FETCH_AFTER_ARGS=
DISABLE_SIZE=yes

wget2

# cd /usr/ports/www/wget2/ && make install clean

新建或者编辑 /etc/make.conf 文件,写入以下几行:

FETCH_CMD=wget2
FETCH_BEFORE_ARGS= -c -t 3 -o 10
FETCH_AFTER_ARGS=
DISABLE_SIZE=yes
  • -c 断点续传;

  • -t 3 重试次数 3;

  • -o 10 启用 10 个线程进行下载。

技巧

10 这个参数可能过于保守。但是要注意很多服务器不支持较多线程同时下载。同时会给服务器带来较大压力。

参考文献

  • ports --contributed applications,FETCH_CMD 的出处,同时也是参数 BATCH 的出处。

上一页4.4 使用 pkg 管理二进制包下一页4.6 使用 DVD 安装软件

最后更新于6小时前