在 Linux 上运行 Postman 脚本(通常是 Postman Collection)一般不是用 Postman 图形界面,而是用 Newman(Postman 的命令行运行器)。下面一步步说明。
Newman 依赖 Node.js,先确认是否已安装:
node -v
npm -v
如果没有安装(以 Ubuntu 为例):
sudo apt update
sudo apt install -y nodejs npm
推荐 Node.js 14 及以上版本
npm install -g newman
安装完成后检查:
newman --version
你有两种常见方式:
... → Exportapi_test.json 的文件传到 Linux:
scp api_test.json user@linux-server:/path/
newman run api_test.json
如果你导出了 Environment 文件(如 env.json):
newman run api_test.json -e env.json
newman run api_test.json -g globals.json
newman run api_test.json -n 5
先安装 reporter:
npm install -g newman-reporter-htmlextra
运行:
newman run api_test.json \
-e env.json \
--reporters htmlextra \
--reporter-htmlextra-export report.html
crontab -e
添加:
0 2 * * * /usr/bin/newman run /path/api_test.json -e /path/env.json >> /var/log/postman.log 2>&1
newman: command not found可能是 npm 全局路径不在 PATH:
export PATH=$PATH:$(npm bin -g)
newman run api_test.json --proxy http://proxy:8080
newman run api_test.json --insecure
✅ Linux 跑 Postman 脚本 = Newman + Collection JSON
✅ 不需要图形界面
✅ 非常适合自动化测试、CI、定时任务
如果你愿意,可以把你的 Collection 示例 或 **使用场景(CI / 压测 / 定时)**发给我,我可以帮你写具体命令。