在FreeBSD15.1系统安装bun,最后使用官方安装成功!

在FreeBSD安装bun

首先必须是FreeBSD15.x系统,低于15不行

其次,不能二进制安装,必须编译安装!所以要先安装适配好ports系统!

在FreeBSD安装ports

更新ports

复制代码
skywalk@fb250:/usr/ports $ sudo git pull
接收对象中: 100% (15176/15176), 4.59 MiB | 2.26 MiB/s, 完成.
处理 delta 中: 100% (5258/5258), 完成.
来自 https://mirrors.ustc.edu.cn/freebsd-ports/ports
   c1a0c59450..1050071235  main       -> origin/main
   4257c085c8..38244ac0be  2026Q2     -> origin/2026Q2
 * [新分支]                2026Q3     -> origin/2026Q3
 * [新标签]                release/14.5.0 -> release/14.5.0
更新 c1a0c59450..1050071235

安装相关pkg

更新pkg

复制代码
sudo pkg update 

安装依赖库

复制代码
sudo pkg install www/npm-node24 lang/rust devel/llvm21 devel/cmake-core devel/ninja www/node24

如果速度慢就用这个镜像

复制代码
ustc-ports: { 
    url: "https://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/quarterly",
    mirror_type: "none",
    signature_type: "fingerprints",
    fingerprints: "/usr/share/keys/pkg",
    enabled: yes
}

ustc-ports-kmods: {
    url: "https://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/kmods_quarterly_${VERSION_MINOR}",
    mirror_type: "none",
    signature_type: "fingerprints",
    fingerprints: "/usr/share/keys/pkg",
    enabled: yes
}

FreeBSD-ports: { 
    enabled: no 
}

FreeBSD-ports-kmods: { 
    enabled: no 
}

# 仅当启用 pkgbase 时才添加以下内容
#ustc-base: {
#   url: "https://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/base_release_${VERSION_MINOR}",
#   mirror_type: "none",
#   signature_type: "fingerprints",
#   fingerprints: "/usr/share/keys/pkgbase-${VERSION_MAJOR}",
#   enabled: yes
#}

#FreeBSD-base: {
#   enabled: no
#}

开始ports编译安装

make的时候,如果下载源码 慢,就加上中科大镜像,写入/etc/make.conf文件.

复制代码
MASTER_SITE_OVERRIDE?=https://mirrors.ustc.edu.cn/freebsd-ports/distfiles/${DIST_SUBDIR}/

进入目录,开始编译安装!

复制代码
cd /usr/ports/lang/bun 
sudo make install clean

很不巧,碰到报错

使用社区提供的版本安装

下载源代码

复制代码
git clone https://github.com/8ff/bun-freebsd.git

进入目录安装

复制代码
cd bun-freebsd
sh build.sh

如果cpu没有跑满,可以加上-j参数. 看了一下,Zig 构建系统不能用-j ....

如果内存较少,可以加上这句

复制代码
-DZIG_EXTRA_BUILD_ARGS="--maxrss;17179869184"

当然前提条件是配置更大的swap空间

复制代码
dd if=/dev/zero of=/usr/swap0 bs=1m count=8192
chmod 0600 /usr/swap0
mdconfig -a -t vnode -f /usr/swap0 -u 0
swapon /dev/md0

直接使用官方安装

执行命令

复制代码
curl -fsSL https://bun.sh/install | bash

当然前提条件是要装上bash

复制代码
[skywalk@fb250 ~]$ curl -fsSL https://bun.sh/install | bash
cat: /proc/cpuinfo: No such file or directory
######################################################################## 100.0%
bun was installed successfully to ~/.bun/bin/bun 

Manually add the directory to ~/.bashrc (or similar):
  export BUN_INSTALL="$HOME/.bun" 
  export PATH="$BUN_INSTALL/bin:$PATH" 

To get started, run: 

  bun --help 

官方安装碰到了报错,说缺库,是到ubuntu的仿真环境里面拿到,然后cp出来,搞定!

具体见调试部分

设置环境变量并激活

复制代码
skywalk@fb250:~ $ echo 'export BUN_INSTALL="$HOME/.bun"' >> ~/.zshrc
skywalk@fb250:~ $ echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> ~/.zshrc
skywalk@fb250:~ $ source ~/.zshrc

总结

最后只有用官方安装方法是成功的!

调试

安装报错错误:RPC 失败。curl 28 Operation too slow. Less than 1000 bytes/sec transferred the last 20 seconds

Message from node22-22.23.2:

--

Note: If you need npm (Node Package Manager), please install www/npm-node22.

==> Cloning lwhsu/bun @ 5a9ab808bd71fe32b08244314896a7e3df54bcb3

正克隆到 'bun'...

remote: Enumerating objects: 99276, done.

remote: Total 99276 (delta 0), reused 0 (delta 0), pack-reused 99276 (from 1)

接收对象中: 100% (99276/99276), 21.02 MiB | 8.00 MiB/s, 完成.

处理 delta 中: 100% (73052/73052), 完成.

remote: Enumerating objects: 12086, done.

remote: Counting objects: 100% (3916/3916), done.

remote: Compressing objects: 100% (3350/3350), done.

remote: Total 12086 (delta 853), reused 566 (delta 566), pack-reused 8170 (from 1)

接收对象中: 100% (12086/12086), 51.99 MiB | 9.35 MiB/s, 完成.

处理 delta 中: 100% (2107/2107), 完成.

正在更新文件: 100% (12554/12554), 完成.

注意:正在切换到 '5a9ab808bd71fe32b08244314896a7e3df54bcb3'。

您正处于分离头指针状态。您可以查看、做试验性的修改及提交,并且您可以在切换

回一个分支时,丢弃在此状态下所做的提交而不对分支造成影响。

如果您想要通过创建分支来保留在此状态下所做的提交,您可以通过在 switch 命令

中添加参数 -c 来实现(现在或稍后)。例如:

git switch -c <新分支名>

或者撤销此操作:

git switch -

通过将配置变量 advice.detachedHead 设置为 false 来关闭此建议

HEAD 目前位于 5a9ab808b docs: update FreeBSD test results with copyFile fix and expanded coverage

==> Cloning oven-sh/WebKit @ 4a6a32c32c11ffb9f5a94c310b10f50130bfe6de

remote: Enumerating objects: 21697, done.

remote: Counting objects: 100% (21697/21697), done.

remote: Compressing objects: 100% (18177/18177), done.

remote: Total 21697 (delta 1173), reused 17501 (delta 934), pack-reused 0 (from 0)

接收对象中: 100% (21697/21697), 12.85 MiB | 9.36 MiB/s, 完成.

处理 delta 中: 100% (1173/1173), 完成.

来自 https://github.com/oven-sh/WebKit

* branch 4a6a32c32c11ffb9f5a94c310b10f50130bfe6de -> FETCH_HEAD

remote: Enumerating objects: 398729, done.

remote: Counting objects: 100% (398729/398729), done.

错误:RPC 失败。curl 28 Operation too slow. Less than 1000 bytes/sec transferred the last 20 seconds

致命错误:协议错误:无效的包头

致命错误:无法从承诺者远程获取 253e74a1cfb48b00aab075e27ffee9fee4923a06

安装这个试试:

复制代码
sudo pkg install webkit2-gtk_60-2.46.6_8

另外也可能是github抽风,多试几次!

有新的报错compile exe zig ReleaseFast native: this step declares an upper bound of 10000000000 bytes of memory, exceeding the available 8409804800 bytes of memory

note: use --maxrss to override the defaultthread 101169 panic: reached unreachable code

复制代码
[skywalk@fb250 ~/github/bun-freebsd]$ sh build.sh 
==> Installing build dependencies
Updating FreeBSD-base repository catalogue...
FreeBSD-base repository is up to date.
Updating ustc-ports repository catalogue...
ustc-ports repository is up to date.
Updating ustc-ports-kmods repository catalogue...
ustc-ports-kmods repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The most recent versions of packages are already installed
HEAD 目前位于 5a9ab808b docs: update FreeBSD test results with copyFile fix and expanded coverage
==> Building Bun's Zig fork (~10 min)
-- Configuring zig version 0.15.2
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/skywalk/src/bun-zig/build
[1/2] Building stage3
FAILED: [code=1] stage3/bin/zig /home/skywalk/src/bun-zig/build/stage3/bin/zig 
cd /home/skywalk/src/bun-zig && /home/skywalk/src/bun-zig/build/zig2 build --prefix /home/skywalk/src/bun-zig/build/stage3 --zig-lib-dir /home/skywalk/src/bun-zig/lib -Dversion-string=0.15.2 -Dtarget=native -Dcpu=native -Denable-llvm -Dconfig_h=/home/skywalk/src/bun-zig/build/config.h -Dno-langref -Doptimize=ReleaseFast -Dstrip
compile exe zig ReleaseFast native: this step declares an upper bound of 10000000000 bytes of memory, exceeding the available 8409804800 bytes of memory
note: use --maxrss to override the defaultthread 101169 panic: reached unreachable code
Unwind information for `libsys.so.7:0x8054f4e2e` was not available, trace may be incomplete

/home/skywalk/src/bun-zig/lib/std/debug.zig:559:14: 0x113bced in assert (build)
    if (!ok) unreachable; // assertion failure
             ^
/home/skywalk/src/bun-zig/lib/compiler/build_runner.zig:679:11: 0x11d9be6 in runStepNames (build)
    assert(run.memory_blocked_steps.items.len == 0);
          ^
/home/skywalk/src/bun-zig/lib/compiler/build_runner.zig:474:21: 0x11e5502 in main (build)
        runStepNames(
                    ^
/home/skywalk/src/bun-zig/lib/std/start.zig:627:37: 0x11efd59 in main (build)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x80457423e in ??? (libc.so.7)
/usr/src/lib/csu/amd64/crt1_s.S:80:0: 0x1133903 in ??? (/usr/src/lib/csu/amd64/crt1_s.S)
 callq __libc_start1

???:?:?: 0x3b128be03007 in ??? (???)
error: the following build command crashed:
.zig-cache/o/eb047aad55d534aed5f38cb02257522d/build /home/skywalk/src/bun-zig/build/zig2 lib /home/skywalk/src/bun-zig .zig-cache /home/skywalk/.cache/zig --seed 0xd8b4a4a1 -Zd6d5969c3e44f1af --prefix /home/skywalk/src/bun-zig/build/stage3 -Dversion-string=0.15.2 -Dtarget=native -Dcpu=native -Denable-llvm -Dconfig_h=/home/skywalk/src/bun-zig/build/config.h -Dno-langref -Doptimize=ReleaseFast -Dstrip
ninja: build stopped: subcommand failed.

用这个

复制代码
# 创建一个 4GB 的 swap 文件
sudo dd if=/dev/zero of=/swap bs=1G count=4
sudo chmod 600 /swap
sudo swapon /swap

# 确认 swap 已生效
swapinfo

不行,那我就用的这个方法

复制代码
dd if=/dev/zero of=/usr/swap0 bs=1m count=8192
chmod 0600 /usr/swap0
mdconfig -a -t vnode -f /usr/swap0 -u 0
swapon /dev/md0

生效了看看效果

复制代码
swapinfo -h

root@fb250:~ # swapinfo -h

Device Size Used Avail Capacity

/dev/ada0p3 2.0G 303M 1.7G 15%

/dev/md0 8.0G 0B 8.0G 0%

Total 10G 303M 9.7G 3%

还需要在build.sh文件中,找到cmake那句话,加上

复制代码
-DZIG_EXTRA_BUILD_ARGS="--maxrss;17179869184"

这样就行了

bun启动报错

skywalk@fb250 \~$ bun

ELF interpreter /lib64/ld-linux-x86-64.so.2 not found, error 2

终止陷阱 bun

原来是缺linux文件

复制代码
[skywalk@fb250 ~]$ ls -l /compat/ubuntu/lib64/ld-linux-x86-64.so.2
lrwxr-xr-x  1 root wheel 42  1月 30  2026 /compat/ubuntu/lib64/ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
[skywalk@fb250 ~]$ bun
ELF interpreter /lib64/ld-linux-x86-64.so.2 not found, error 2
终止陷阱               bun
[skywalk@fb250 ~]$ /compat/ubuntu/lib64/ld-linux-x86-64.so.2 ~/.bun/bin/bun --version
bash: /compat/ubuntu/lib64/ld-linux-x86-64.so.2: 文件或目录不存在

进入linux仿真安装libc6库

复制代码
apt install -y libc6 libstdc++6 ca-certificates

# apt install glibc-doc libnss-nis libnss-nisplus

linux仿真环境报错

复制代码
E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt 2>/dev/null || true: 成功
E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt 2>/dev/null || true: 成功

原来是snap...去掉

复制代码
rm -f /etc/apt/apt.conf.d/20snapd.conf

不行啊,还是没有

原来我ubuntu里面指向了/lib/x86_64-linux-gnu//ld-linux-x86-64.so.2 但是压根没有/lib/x86_64-linux-gnu/ 这个目录,创建这个目录,然后把ld-linux-x86-64.so.2 文件先从Ubuntu里放到/tmp目录,再从tmp目录cp过来:

复制代码
[skywalk@fb250 ~]$ sudo mkdir /lib/x86_64-linux-gnu/
[skywalk@fb250 ~]$ sudo cp /compat/ubuntu/tmp/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/
[skywalk@fb250 ~]$ bun

bun终于好了

复制代码
[skywalk@fb250 ~]$  bun -v
1.4.2
相关推荐
带鱼吃猫1 小时前
LangGraph入门:支持搜索的智能代理系统
人工智能·langchain
吴佳浩1 小时前
Agent Memory 架构设计:短时记忆、长期记忆与 Memory 生命周期
人工智能·agent·ai编程
GlobalInfo1 小时前
上新 | 全球及中国Agent测试用例生成软件行业研究报告(2026版):市场现状、行业前景与占有率分析
人工智能·ai·agent
shujudang1 小时前
零售客户分析平台的四种路径:身份关联、分析模型与系统对接
大数据·人工智能·数据分析
袁俪1 小时前
大模型幻觉
人工智能
找方案1 小时前
AI+汽车座舱:智能座舱如何重新定义驾驶体验
人工智能·汽车
武子康1 小时前
Expert Parallel 深入解析:专家分得均匀,负载为什么仍不均
人工智能·llm·agent
她的男孩2 小时前
做了"异步导出",用户点了还是卡 3 分钟:扒完 4223 行源码,@Async 压根没生效
人工智能·后端·程序员
szxinmai主板定制专家2 小时前
【嵌入式实战】RK3588+GMSL多路相机采集方案|SerDes长距离低延时视频流落地教程
人工智能·单片机·机器人·边缘计算·zynq