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

相关推荐
神奇的程序员9 小时前
我的软件冲进苹果商店下载榜前 50 了
前端
阳光是sunny9 小时前
别再被 worktree 绕晕了!AI 编程时代你必须掌握的 Git 隔离神器
前端·人工智能·后端
万少11 小时前
万少的博客 - 技术分享与解决方案
前端·javascript·后端
尘世中一位迷途小书童13 小时前
用 Cesium 撸了一个森林火情监控大屏,弧线、粒子、发光效果都齐了
前端·javascript
IT_陈寒14 小时前
垃圾回收器选错了,我的Java服务内存炸了
前端·人工智能·后端
月光下的丝瓜14 小时前
Flutter 国内安装指南
前端·flutter
玄星啊15 小时前
AI 编程的第 30 天,我怀念古法 Coding 了
前端·ai编程
Jolyne_15 小时前
Angular基础速通
前端·angular.js
锋行天下16 小时前
半秒开!还有谁!!!
前端·vue.js·架构
代码搬运媛17 小时前
git 下中文文件名乱码问题解决
前端