在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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值