SPTarkov Linux 自编译搭建指南

原始记录时间:2024年8月17日

注意: 需要 root 权限执行大部分操作。

1. 安装 nvm(Node Version Manager)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

注意检查最新版本号。

更新环境变量(根据 Shell 选择):

# bash
source ~/.bashrc
# zsh
source ~/.zshrc
# ksh
. ~/.profile

验证安装:

nvm -v

2. 安装对应版本的 Node.js

nvm ls                   # 查看已安装版本
nvm install <version>    # 安装指定版本
nvm use <version>        # 使用指定版本

3. 拉取 SPTarkov 仓库

# -b 指定版本(如 3.8.3),否则拉取 master(不稳定)
git clone https://github.com/sp-tarkov/server -b 3.8.3
# 解压资源(需要 7z)
7za x Server.7z -r -o./

4. 执行 git lfs pull

git lfs pull

5. 安装依赖

npm install

如果乱码报错,建议删除 Server/project/src/Program.ts 中 UTF-8 BOM 那一行。

6. 编译

npm run build:release

可能需要本地代理下载 pkg-fetch 对应版本。

7. 首次运行测试

先运行一次检查是否正常。

8. 修改 http.json 配置

vim SPT_Data/Server/configs/http.json

修改以下字段:

{
    "Ip": "0.0.0.0",
    "BackIP": "服务器IP"
}

保存退出:a → 编辑 → :wq!

9. 创建 systemd 服务

创建 /usr/lib/systemd/system/spt-server.service:

[Unit]
# 服务描述
Description=逃离塔科夫离线模式服务端
After=network.target auditd.service

[Service]
# 定义 systemctl start|stop|reload 的执行方法(需写绝对路径)
ExecStartPre=
ExecStart=/root/Server/project/online/SPT.Server.exe
ExecReload=
ExecStop=
Restart=always

# 应用程序工作目录
WorkingDirectory=/root/Server/project/online

# 创建私有的内存临时空间
PrivateTmp=True

[Install]
# 多用户
WantedBy=multi-user.target

10. 启动服务

sudo systemctl daemon-reload
sudo systemctl stop spt-server.service
sudo systemctl start spt-server.service
sudo systemctl status spt-server.service

主要确认状态为 active (running)。

11. 查看日志

sudo journalctl -u spt-server.service

12. 开机自启动

sudo systemctl enable spt-server.service
sudo systemctl status spt-server.service

13. Mod 安装

把 Mod 代码中的 C:/snapshot/ 路径改为 /snapshot/(Linux 路径格式)。