使用云服务器 + Verdaccio 创建 npm 私有仓库

Verdaccio是一个开源的、轻量级的私有 npm 仓库管理器,允许开发团队在本地环境中搭建一个专属的 npm 仓库,用于存储和管理项目的依赖包,有利于在公司内部管理多个自定义包,确保稳定性和安全性。
环境:阿里云服务器ECS

1. 下载Node

登录到阿里云服务器中,使用wget下载node包,并解压

bash 复制代码
# cd 到根目录 
cd / 
# 下载 node 18 
wget https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-x64.tar.xz 
# 解压 
tar -xvf node-v18.16.0-linux-x64.tar.xz 
# 修改node文件夹的名称 
mv node-v18.16.0-linux-x64 nodejs

配置node环境变量

bash 复制代码
# 使用 vim 进行编辑 
vi /etc/profile 
#按 i 键进入编辑模式:在文件末尾添加: 
#node 
#这里用你的解压目录(我刚刚是解压到根目录下的nodejs中) 
NODE_HOME=/nodejs 
PATH=$PATH:$NODE_HOME/bin 
NODE_PATH=$NODE_HOME/lib/node_modules export 
PATH NODE_HOME NODE_PATH 
##按esc 输入:wq 进行编辑保存 
#执行一下刚刚编辑过的文件 
source /etc/profile

创建软连接

bash 复制代码
ln -s /nodejs/bin/node /usr/local/bin/node 
ln -s /nodejs/bin/npm /usr/local/bin/npm

此时在控制台中检测node版本发现可以正常打印说明node已经配置成功

bash 复制代码
[root@iZbp12s6n1dclq79esxf2oZ usr]# node -v 
v18.16.0 
[root@iZbp12s6n1dclq79esxf2oZ usr]# npm -v 
9.5.1

2. 下载Verdaccio

css 复制代码
npm i Verdaccio -g

3. 测试一下Verdaccio

bash 复制代码
# 在终端中直接执行 verdaccio 
[root@iZbp12s6n1dclq79esxf2oZ /] verdaccio 
(node:46828) 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:46828) Warning: Verdaccio doesn't need superuser privileges. don't run it under root 
info --- config file - /usr/verdaccio/config.yaml
info --- the "crypt" algorithm is deprecated consider switch to "bcrypt" in the configuration file. Read the documentation for additional details 
info --- using htpasswd file: /usr/verdaccio/htpasswd 
info --- plugin successfully loaded: verdaccio-htpasswd 
info --- plugin successfully loaded: verdaccio-audit 
warn --- http address - http://localhost:4873/ - verdaccio/5.26.2

此时会打印出verdaccio的配置文件所在地址:/usr/verdaccio/config.yaml

4. 配置Verdaccio

因为默认verdaccio会跑在localhost中,我们配置一下使用ip访问,以便后续可以使用公网ip进行外部访问

bash 复制代码
[root@iZbp12s6n1dclq79esxf2oZ /]# vi /usr/verdaccio/config.yaml 
# 在文件末尾加上 
listen: 0.0.0.0:4873 
# esc + :wq保存

5. 安装PM2

使用pm2做进程守护,否则当你退出服务器的时候verdaccio也会随之关闭掉

css 复制代码
npm i pm2 -g

6. 使用pm2运行verdaccio

sql 复制代码
pm2 start verdaccio

打印出如下表格则说明verdaccio成功启动了

7. 配置阿里云安全组,开放出4873端口,否则公网ip无法访问到verdaccio页面

进入阿里云的安全组配置页面,点击手动添加,新增一条开放所有端口的策略,你也可以只开放4873端口

8. 访问 http://公网IP:4873 即可访问verdaccio npm私仓

相关推荐
[seven]6 分钟前
React Router TypeScript 路由详解:嵌套路由与导航钩子进阶指南
前端·react.js·typescript
无我Code24 分钟前
前端-2025年末个人总结
前端·年终总结
文刀竹肃41 分钟前
DVWA -SQL Injection-通关教程-完结
前端·数据库·sql·安全·网络安全·oracle
LYFlied1 小时前
【每日算法】LeetCode 84. 柱状图中最大的矩形
前端·算法·leetcode·面试·职场和发展
Bigger1 小时前
Tauri(21)——窗口缩放后的”失焦惊魂”,游戏控制权丢失了
前端·macos·app
Bigger1 小时前
Tauri (20)——为什么 NSPanel 窗口不能用官方 API 全屏?
前端·macos·app
bug总结1 小时前
前端开发中为什么要使用 URL().origin 提取接口根地址
开发语言·前端·javascript·vue.js·html
一招定胜负2 小时前
网络爬虫(第三部)
前端·javascript·爬虫
Shaneyxs2 小时前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(13)
前端
半山烟雨半山青2 小时前
微信内容emoji表情包编辑器 + vue3 + ts + WrchatEmogi Editor
前端·javascript·vue.js