链接
Linux 直接安装
需求
Node.js v18 或更高版本
- 任选其一:
npm、pnpm、yarn
Linux 安装 verdaccio
# npm
npm install -g verdaccio
# yarn
yarn global add verdaccio
# yarn
pnpm install -g verdaccio
# 查看 verdaccio 版本
verdaccio
Linux 启动 verdaccio
verdaccio 启动时,会创建一个文件夹 verdaccio,用于储存默认配置文件与Node.js包,不同环境的文件夹位置不同,如:
- 运行
verdaccio 命令时的当前文件夹下创建 verdaccio 文件夹,即:$(pwd)/verdaccio
- 在
当前用户文件夹 下的 .config 文件夹中创建 verdaccio 文件夹 ~/.config/verdaccio
- 默认配置仅允许使用
http://localhost:4873 访问,如需远程访问请修改配置文件中的 listen
# $(pwd)/verdaccio
[root@anolis-8-2 ~]# verdaccio
(node:120118) Warning: Verdaccio doesn't need superuser privileges. don't run it under root
(Use `node --trace-warnings ...` to show where the warning was created)
(node:120118) Warning: Verdaccio doesn't need superuser privileges. Don't run it under root.
warn --- This is a deprecated method, please use runServer instead
info --- config file - /root/verdaccio/config.yaml
info --- plugin @verdaccio/local-storage successfully loaded (storage)
info --- using htpasswd file: /root/verdaccio/htpasswd
info --- plugin verdaccio-htpasswd successfully loaded (authentication)
info --- plugin verdaccio-audit successfully loaded (middleware)
info --- plugin @verdaccio/ui-theme successfully loaded (theme)
warn --- http address - http://localhost:4873/ - verdaccio/6.2.3
# ~/.config/verdaccio
root@pve:~# verdaccio
(node:124035) Warning: Verdaccio doesn't need superuser privileges. don't run it under root
(Use `node --trace-warnings ...` to show where the warning was created)
(node:124035) Warning: Verdaccio doesn't need superuser privileges. Don't run it under root.
warn --- This is a deprecated method, please use runServer instead
info --- config file - /root/.config/verdaccio/config.yaml
info --- plugin @verdaccio/local-storage successfully loaded (storage)
info --- using htpasswd file: /root/.config/verdaccio/htpasswd
info --- plugin verdaccio-htpasswd successfully loaded (authentication)
info --- plugin verdaccio-audit successfully loaded (middleware)
info --- plugin @verdaccio/ui-theme successfully loaded (theme)
warn --- http address - http://localhost:4873/ - verdaccio/6.2.3
配置
| 路径 |
说明 |
| verdaccio/config.yaml |
配置文件 |
| verdaccio/htpasswd |
用户信息储存位置 |
config.yaml
# 默认 端口监听地址
listen:
- localhost:4873
# 允许所有人访问 端口监听地址
listen:
- 0.0.0.0:4873
# 默认 npm 仓库代理地址
uplinks:
npmjs:
url: https://registry.npmjs.org
# 淘宝 npm 仓库代理地址
uplinks:
npmjs:
url: https://registry.npmmirror.com
# 默认 npm 仓库储存地址
storage: ./storage
# 自定义 npm 仓库储存地址
storage: /mnt/pve/ST8000/verdaccio-storage
Linux 服务
- Linux 命令强烈建议使用绝对位置
- 某些系统如果开启了 SELinux,必须关闭才能使用 Linux Service,见:SELinux
# /usr/lib/systemd/system/verdaccio.service
[Unit]
After=syslog.target
[Service]
# 使用绝对位置
ExecStart=/srv/node-v18.20.8-linux-x64/bin/node /srv/node-v18.20.8-linux-x64/bin/verdaccio
Restart=always
RestartSec=10
StartLimitInterval=60s
StartLimitBurst=3
User=root
[Install]
WantedBy=multi-user.target
| 命令 |
说明 |
| systemctl enable verdaccio.service |
设置开机自启 |
| systemctl is-enabled verdaccio.service |
查看开机自启状态 |
| systemctl disable verdaccio.service |
关闭开机自启 |
| systemctl start verdaccio.service |
启动 |
| systemctl stop verdaccio.service |
停止 |
| systemctl restart verdaccio.service |
重启 |