使用云服务器 + 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私仓

相关推荐
你的人类朋友24 分钟前
什么是API签名?
前端·后端·安全
会豪2 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子2 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶2 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子3 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_3 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_23333 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
RoyLin3 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js
遂心_4 小时前
深入理解 React Hook:useEffect 完全指南
前端·javascript·react.js
Moonbit4 小时前
MoonBit 正式加入 WebAssembly Component Model 官方文档 !
前端·后端·编程语言