温馨提示×

ubuntu swagger怎么安装

小樊
37
2026-10-06 21:33:48
栏目: 智能运维

在 Ubuntu 上“安装 Swagger”通常分几种场景,先确认你说的 Swagger 是哪一种:


一、Swagger UI(网页查看 API 文档)

方式 1:直接用 Docker(最推荐)

sudo apt update
sudo apt install docker.io -y
sudo systemctl enable --now docker

docker run -p 8080:8080 swaggerapi/swagger-ui

浏览器访问:

http://localhost:8080

方式 2:用 Node.js 安装 Swagger UI

sudo apt update
sudo apt install nodejs npm -y

npm install -g swagger-ui-cli
swagger-ui-cli serve ./swagger.yaml

二、Swagger Editor(在线编辑 API)

docker run -p 8081:8080 swaggerapi/swagger-editor

访问:

http://localhost:8081

三、在 Ubuntu 后端项目中使用 Swagger

1️⃣ Java(Spring Boot)

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
  <version>2.3.0</version>
</dependency>

访问:

http://localhost:8080/swagger-ui.html

2️⃣ Python(FastAPI)

pip install fastapi uvicorn

FastAPI 自带 Swagger:

http://localhost:8000/docs

3️⃣ Node.js(Express)

npm install swagger-ui-express yamljs

四、如果你是“Ubuntu 服务器上看不到 Swagger”

常见原因:

  • 端口未开放
  • 防火墙
sudo ufw allow 8080

五、我可以进一步帮你

你可以告诉我:

  1. 用的是 Java / Python / Node / Go?
  2. 想要 Swagger UI / Editor / 代码集成?
  3. Ubuntu 版本(lsb_release -a)

我可以给你精确到命令级别的安装方案。

0 踩