Postman在CentOS中的配置方法
Postman在CentOS中的配置主要分为应用程序安装(桌面端)和命令行工具配置(Newman)两部分,以下是详细步骤:
.tar.gz格式)下载;或使用wget命令直接下载最新版:wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz/usr/local/postman(需管理员权限):sudo mkdir -p /usr/local/postmansudo tar -zxf postman.tar.gz --strip-components=1 -C /usr/local/postman//usr/bin:sudo ln -s /usr/local/postman/Postman/Postman /usr/bin/postmansudo touch /usr/share/applications/postman.desktop[Desktop Entry] Encoding=UTF-8 Name=Postman GenericName=API Tools Comment=Postman API测试工具 Exec=/usr/bin/postman Terminal=false MimeType=text/plain Icon=/usr/local/postman/app/resources/app/assets/icon.png StartupNotify=true Categories=Development; 赋予执行权限:sudo chmod +x /usr/share/applications/postman.desktoppostman,或在应用菜单中找到Postman图标启动。若系统已安装Snap(未安装则执行sudo yum install snapd && sudo systemctl enable --now snapd.socket),可直接通过Snap安装Postman:
sudo snap install postman --classic
安装完成后,通过postman命令启动应用程序。
Postman官方提供了YUM仓库支持,步骤如下:
sudo rpm -Uvh https://dl.pstmn.io/download/latest/linux/x64/yum/yum.reposudo yum install postmanpostmanNewman是Postman的命令行版本,用于自动化运行API测试集合,适合CI/CD流程。
Newman依赖Node.js环境,通过YUM安装:
sudo yum install -y nodejs npm
验证安装:node -v(显示版本号)、npm -v(显示版本号)。
使用npm安装Newman(需管理员权限):
sudo npm install -g newman
验证安装:newman --version(显示版本号)。
collection.json)。newman run /path/to/collection.jsonenvironment.json),并通过-e参数指定:newman run /path/to/collection.json -e /path/to/environment.jsonrun_postman.sh),内容如下:#!/bin/bash COLLECTION_FILE="/path/to/collection.json" ENVIRONMENT_FILE="/path/to/environment.json" newman run "$COLLECTION_FILE" -e "$ENVIRONMENT_FILE" 赋予执行权限:chmod +x run_postman.sh,运行脚本:./run_postman.sh。/etc/systemd/system/postman.service),内容如下:[Unit] Description=Newman Postman Collection Runner After=network.target [Service] ExecStart=/usr/local/bin/newman run /path/to/collection.json -e /path/to/environment.json Restart=always User=your_username [Install] WantedBy=multi-user.target 启用并启动服务:sudo systemctl daemon-reloadsudo systemctl enable postman.servicesudo systemctl start postman.servicesudo systemctl status postman.service。baseUrl=https://api.example.com、apiKey=123456),点击“Save”。{{variable_name}}引用(如{{baseUrl}}/users)。pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Response contains user data", function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property("id"); }); 以上步骤覆盖了Postman在CentOS中的主要配置场景,可根据需求选择桌面端或命令行工具使用。