温馨提示×

centos下postman怎么用

小樊
34
2026-09-21 00:24:31
栏目: 智能运维

CentOS 下使用 Postman,常见有两种方式:

  1. 桌面版(图形界面)Postman
  2. 命令行版(无界面)Postman(Newman)

下面分别说明。


一、CentOS 桌面版 Postman(推荐有 GUI 的情况)

1. 下载 Postman

cd /tmp
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz

2. 解压

sudo tar -xzf postman.tar.gz -C /opt

3. 创建启动方式

sudo ln -s /opt/Postman/Postman /usr/bin/postman

4. 启动 Postman

postman

或直接在桌面环境中搜索 Postman

⚠️ 注意

  • CentOS 必须 有桌面环境(GNOME / KDE)
  • 如果是服务器版(无 GUI),请使用 Newman

二、CentOS 命令行 Postman(Newman,无界面)

如果你是在 CentOS 服务器 上,只能使用命令行方式。

1. 安装 Node.js

curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs

验证:

node -v
npm -v

2. 安装 Newman

sudo npm install -g newman

验证:

newman --version

3. 使用 Postman 导出的 Collection 测试接口

Windows / Mac 的 Postman 中:

  • 导出 Collection(JSON 文件)
  • 上传到 CentOS

运行:

newman run example.postman_collection.json

带环境变量:

newman run test.json -e env.json

生成 HTML 报告:

npm install -g newman-reporter-htmlextra
newman run test.json -r htmlextra

三、常见用途示例

测试 API 接口

newman run api_test.json \
  --env-var "host=192.168.1.100" \
  --env-var "token=abc123"

CI/CD 中使用

newman run api_test.json || exit 1

四、你适合哪种方式?

使用场景 推荐方式
CentOS 有桌面 Postman 桌面版
CentOS 服务器(无 GUI) Newman
自动化测试 Newman
接口调试 Postman

如果你愿意,可以告诉我:

  • CentOS 7 还是 8 / Stream
  • 有没有 桌面环境
  • 接口测试 还是 日常调试

我可以给你更精确的命令。

0